terraform-aws-modules / terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws
Apache License 2.0
758 stars 1.88k forks source link

Terraform apply fails when not providing AMI #260

Closed matheus-rdo closed 2 years ago

matheus-rdo commented 2 years ago

Description

terraform apply fails when the "ami" property is not set. According to the documentation, this property is optional. I was expecting to use the default linux AMI.

module "ec2_instance" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "~> 3.0"

  name = "my_ec2"
  ami  = ""  ## default value

  # omit others...
}

Error

module.ec2_instance.aws_instance.this[0]: Creating...
╷
│ Error: Error launching source instance: MissingParameter: The request must contain the parameter ImageId
│       status code: 400, request id: 8d52454d-80f1-4056-9d1b-f973b65b013f
│
│   with module.ec2_instance.aws_instance.this[0],
│   on .terraform\modules\ec2_instance\main.tf line 5, in resource "aws_instance" "this":
│    5: resource "aws_instance" "this" {
│

Versions

antonbabenko commented 2 years ago

ami is actually required. More info here - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#ami

matheus-rdo commented 2 years ago

ami is actually required. More info here - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#ami

I was reading through the terraform-aws-modules documentation. It says the field is optional https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws/latest

Thanks!

antonbabenko commented 2 years ago

It is optional if you disable the creation of the module's resources like this:

https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/blob/ab731d112e37971368066b5dbecf35b075a853aa/examples/complete/main.tf#L80-L84

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.