2

I'm trying to start an instance on aws using terraform and using the amazon-linux-2 image. But I'm getting an Erro for Microsoft SQL Server Entreprise Edition.

provider "aws" {
    version = "~> 2.0"
    region = "us-east-1"
}

resource "aws_instance" "dev" {
  ami = "${data.aws_ami.amazon-linux-2.id}"
  instance_type = "t2.micro"
  key_name = "terraform"
  tags = {
    "Name" = "dev-terraform"
  }
}

data "aws_ami" "amazon-linux-2" {
  most_recent = true
  owners = ["amazon"]

  filter {
    name   = "owner-alias"
    values = ["amazon"]
  }
  filter {
    name   = "name"
    values = ["amzn2-ami-hvm*"]
   }
  filter {
    name   = "architecture"
    values = ["x86_64"]
  }
}

The error:

Error: Error launching source instance: UnsupportedOperation: Microsoft SQL Server Enterprise Edition is not supported for the instance type 't2.micro'.
        status code: 400, request id: 72df60b9-46ac-4616-ab3f-b964ab2f3156

  on main.tf line 6, in resource "aws_instance" "dev":
   6: resource "aws_instance" "dev" {

I'm not having any relation with Microsoft and I cannot understanding why this error is appearing.

Arthur Ávila
  • 69
  • 2
  • 9

1 Answers1

4

The error is correct. Your data source query returns:

amzn2-ami-hvm-2.0.20190313-x86_64-gp2-SQL_2017_Enterprise-2021.02.25

Please use the following data source instead:

data "aws_ami" "latest_amazon_2" {
  most_recent = true
  owners      = ["amazon"]
  name_regex = "^amzn2-ami-hvm-.*x86_64-gp2$"
}
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Just getting the same error. My code looks like this now: ` provider "aws" { version = "~> 2.0" region = "us-east-1" } resource "aws_instance" "dev" { ami = "${data.aws_ami.latest_amazon_2.id}" instance_type = "t2.micro" key_name = "terraform-dati" tags = { "Name" = "dev-terraform" } } data "aws_ami" "latest_amazon_2" { most_recent = true owners = ["amazon"] name_regex = "^amzn2-ami-hvm-.*x86_64-gp2" } ` – Arthur Ávila Feb 28 '21 at 00:43
  • @ArthurÁvila Wow. You are correct. The data source I gave is what I personally use, and I see now that it stopped working. Please give me a moment to check what's happening. – Marcin Feb 28 '21 at 00:48
  • @ArthurÁvila Sorry for the wait. I updated the `name_regex`. – Marcin Feb 28 '21 at 00:58
  • 1
    awesome mate! Just worked fine! Thanks for that!! – Arthur Ávila Feb 28 '21 at 02:04
  • @ArthurÁvila No problem. Glad it worked out :-) – Marcin Feb 28 '21 at 02:06