terraform-aws-ec2-instance icon indicating copy to clipboard operation
terraform-aws-ec2-instance copied to clipboard

The default value `ebs_optimized = true` makes some instance types unable to provision.

Open soya-miyoshi opened this issue 2 years ago • 3 comments

Describe the Bug

Because the default value of ebs_optimized changed to true in this PR #159, some instance types (such as t2.micro) are unable to provision because they are simply unsupported for EBS-optimized instances. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-optimized.html

So the following code causes an error:

module "my-ec2" {
  source  = "cloudposse/ec2-instance/aws"
  version = "1.1.0"

  vpc_id = module.shared_vpc.vpc_id

  ami              = "ami-06fdbb60c8e83aa5e"
  instance_type    = "t2.micro"
  ami_owner        = "137112412989"
  subnet           = module.shared_dynamic_subnets.private_subnet_ids[0]
}
 Error: creating EC2 Instance: Unsupported: The requested configuration is currently not supported. Please check the documentation for supported configurations.

Expected Behavior

EC2 instances of types that do not support EBS-optimized configurations can still be provisioned using default values.

Steps to Reproduce

Terraform v1.5.6

aws = { source = "hashicorp/aws" version = ">=5.12.0, <6.0.0" }

Then applying the code above will reproduce.

Screenshots

No response

Environment

No response

Additional Context

No response

soya-miyoshi avatar Sep 12 '23 12:09 soya-miyoshi

Hi, this isn't a bug actually.. 👍🏻

as far as i know, the ec2 module (terraform-aws-ec2-instance) from cloudposse provides a variable to control the ebs_optimized argument.

There are various ways for us to do that.

( using *.tfvars ) you can declare your own variable, for example,

add this code inside your "main.tf" or "variables.tf"

variable "ebs_optimized" {
  type        = bool
  description = "Launched EC2 instance will be EBS-optimized"
  default     = true
}

create a file "example.tfvars" and add this line inside of it ebs_optimized = "false"

then simply use the cloudposse module like this

module "my-ec2" {
  source  = "cloudposse/ec2-instance/aws"
  version = "1.1.0"

 . . . some code . . .

 ebs_optimized = var.ebs_optimized

 . . . some code . . .
}

run your resource terraform apply -var-file"example.tfvars"

OR...

(straightforward)

module "my-ec2" {
  source  = "cloudposse/ec2-instance/aws"
  version = "1.1.0"

 . . . some code . . .

 ebs_optimized = false

 . . . some code . . .
}

haidargit avatar Jan 21 '24 08:01 haidargit

ref: https://github.com/cloudposse/terraform-aws-ec2-instance/blob/d4045d949c84ea39a39a6ad676c4f17199063e82/variables.tf#L120

haidargit avatar Jan 21 '24 09:01 haidargit

@haidargit Thank you for getting back to me. You can indeed supply ebs_optimized = false to this module. However, I would like to point out that it would be more straightforward if ebs_optimized = false was the default value so that it is compatible with the previous version of this module.

soya-miyoshi avatar Feb 13 '24 08:02 soya-miyoshi