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
754 stars 1.87k forks source link

Issue with plan if not capacity reservation provided #286

Closed savroman closed 2 years ago

savroman commented 2 years ago

Description

Running terraform plan cased the issue

If your request is for a new feature, please use the Feature request template.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Done! But not helps.

Versions

Reproduction Code [Required]

module "ec2_data" {
  # https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws/latest
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "~> 4.0"
  # insert the 10 required variables here
  create = true

  name                        = "${local.pre-fix}"
  ami                         = data.aws_ssm_parameter.ubuntu_latest_ami_arm64.value
  instance_type               = "t4g.micro"
  cpu_credits                 = "unlimited"
  subnet_id                   = module.vpc.public_subnets[0]
  vpc_security_group_ids      = [aws_security_group.ssh.id]
  associate_public_ip_address = true
  ebs_optimized               = true
  iam_instance_profile        = aws_iam_instance_profile.ec2.name
  key_name                    = aws_key_pair.ec2.key_name
  user_data                   = null
  disable_api_termination     = true
  monitoring                  = false
  root_block_device = [
    {
      volume_type = "gp2"
      volume_size = 50
    }
  ]

}

Steps to reproduce the behavior: terraform init terraform plan

Expected behavior

plan output

Actual behavior

 Error: Invalid combination of arguments
β”‚ 
β”‚   with module.ec2_data.aws_instance.this[0],
β”‚   on .terraform/modules/ec2_data/main.tf line 7, in resource "aws_instance" "this":
β”‚    7: resource "aws_instance" "this" {
β”‚ 
β”‚ "capacity_reservation_specification.0.capacity_reservation_target": one of
β”‚ `capacity_reservation_specification.0.capacity_reservation_preference,capacity_reservation_specification.0.capacity_reservation_target`
β”‚ must be specified

Terminal Output Screenshot(s)

Additional context

Downgrade to 4.1.2 fixes the issue

schniber commented 2 years ago

I was able to reproduce.

In fact the default value of the capacity_reservation_specification should remain null instead of {}

@bryantbiggs : I can revert this back to what it was originally

bryantbiggs commented 2 years ago

let me take a deeper look locally

vsem-cw commented 2 years ago

ran into the same error today and confirmed @savroman's note with downgrading to 4.1.2 worked for me as well.

qxmips commented 2 years ago

looks like the module testing should be improved.

bryantbiggs commented 2 years ago

looks like the module testing should be improved.

sponsorships are always welcomed so we can dedicate more time

antonbabenko commented 2 years ago

This issue has been resolved in version 4.1.4 :tada:

github-actions[bot] commented 1 year 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.