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

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

Open tofupup opened this issue 3 years ago β€’ 0 comments

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.

  • [x] βœ‹ I have searched the open/closed issues and my issue is not listed.

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

  • Module version [Required]: v4.1.4

  • Terraform version: Terraform v1.2.8 on linux_amd64

  • Provider version(s): provider registry.terraform.io/hashicorp/aws v4.29.0

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.

tofupup avatar Sep 04 '22 22:09 tofupup