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

Setting cpu_credits for t4g instance does not set value though it's a burstable instance #293

Closed tofupup closed 1 year ago

tofupup commented 2 years ago

Description

Instance type t4g supports burstable CPU credits mode, but if cpu_credits is set when using the ec2-instance module it doesn't get set on the created resource. Any created t4g instance will use the "unlimited" setting.

⚠️ 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

Versions

Reproduction Code [Required]

data "aws_ssm_parameter" "ubuntu-jammy-arm64" {
    name = "/aws/service/canonical/ubuntu/server/22.04/stable/current/arm64/hvm/ebs-gp2/ami-id"
}

module "ec2_instance" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "4.1.4"

  name = "t4g-credit-standard"

  ami                    = data.aws_ssm_parameter.ubuntu-jammy-arm64.value
  instance_type          = "t4g.small"
  monitoring             = false
  cpu_credits            = "standard"

  tags = {
    Credit = "standard"
  }
}

output "id" {
  value = module.ec2_instance.id
}

Steps to reproduce the behavior:

  1. Create ec2_instance instance type t4g resource, set the cpu_credits to standard (instance defaults to unlimited if not specified)
  2. Check terraform plan output to see no credit_specification is being sent
  3. After terraform apply verify with AWS the instance is using unlimited credit specification using aws ec2 describe-instance-credit-specifications --instance-ids

Expected behavior

credit_specification to be set as specified, or be left unset if not specified

Actual behavior

credit_specification is left unset in aws_instance resource, causing it to default to unlimited regardless of specified value

Terminal Output Screenshot(s)

❯ terraform init >/dev/null && terraform plan 2>/dev/null | grep credit_specification
      + credit_specification {}
❯ terraform apply
data.aws_ssm_parameter.ubuntu-jammy-arm64: Reading...
....
....
....
Outputs:

id = "i-0105c90890dd415f4"
❯ aws ec2 describe-instance-credit-specifications --instance-ids i-0105c90890dd415f4
{
    "InstanceCreditSpecifications": [
        {
            "InstanceId": "i-0105c90890dd415f4",
            "CpuCredits": "unlimited"
        }
    ]
}

Additional context

The local.is_t_instance_type function only includes the t2, t3, and t3a instance types, so won't automatically update with new instance types.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 1 year ago

This issue was automatically closed because of stale in 10 days

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.