Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to define allowed_instance_types when defining a launch_template #265

Open
1 task done
DisgruntledCrayon opened this issue Apr 29, 2024 · 2 comments · May be fixed by #267
Open
1 task done

Unable to define allowed_instance_types when defining a launch_template #265

DisgruntledCrayon opened this issue Apr 29, 2024 · 2 comments · May be fixed by #267

Comments

@DisgruntledCrayon
Copy link

Description

Please provide a clear and concise description of the issue you are encountering, and a reproduction of your configuration (see the examples/* directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running terraform init && terraform apply without any further changes.

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

  • ✋ 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

Versions

  • Module version [Required]: 7.4.1

  • Terraform version: v1.8.0

  • Provider version(s):
    • hashicorp/aws: 5.45.0

Reproduction Code [Required]

module "asg" {
  source = "terraform-aws-modules/autoscaling/aws"
  version = "7.4.1"

  name                   = "example"
  autoscaling_group_tags = local.cluster_tags
  update_default_version = true

  create_launch_template = true
  image_id               = local.image_id
  launch_template_name   = local.cluster_name
  user_data              = base64encode(local.user_data)

  security_groups = local.security_groups
  vpc_zone_identifier = data.aws_subnets.private_subnets.ids

  default_cooldown      = 10
  max_size              = 1
  min_size              = 1

  health_check_type         = "EC2"
  health_check_grace_period = 600

  use_mixed_instances_policy = true
  instance_requirements = {
    allowed_instance_types = ["t3.micro", "t2.micro"]
    burstable_performance  = "included"

    memory_mib = {
      min = 256
      max = 8388608
    }

    vcpu_count = {
      min = 1
      max = 8096
    }
  }
}

Steps to reproduce the behavior:

terraform apply

Expected behavior

When running terraform apply my expectation is that the list provided for instance_requirements.allowed_instance_types gets populated within the EC2 launch template when it get created.

I expected it to be populated in the same way that it does when using mixed_instances_policy.override. However, when using this method, the allowed_instance_types get added to the autoscaling group instead of the launch template (this is expected).

Code like shown here:

  mixed_instances_policy = {
    override = [
      {
        instance_requirements = {
          allowed_instance_types = ["t3.micro", "t2.micro"]
        }
      }
    ]
  }

Actual behavior

The launch template is created but the list provided for instance_requirements.allowed_instance_types doesn't get populated into the created launch template.

Terminal Output Screenshot(s)

Additional context

I at the source and found that the problem is due to a missing line of code.

When looking at main.tf:769, I found that allowed_instance_types is utilized within the override block. However, I would expect to find the same logic on main.tf:182, but don't. I have not verified this theory, yet, but adding the following line at main.tf:182 should remedy the issue I'm experiencing:

allowed_instance_types = try(instance_requirements.value.allowed_instance_types, null)
@DisgruntledCrayon
Copy link
Author

Testing revealed that my solution will work, but also that main.tf:194 will need to be changed to:

      excluded_instance_types = try(instance_requirements.value.excluded_instance_types, null)

@baolsen
Copy link

baolsen commented May 15, 2024

I came to the same conclusion, tested the proposed fix and it works.
Will submit a PR shortly.

baolsen added a commit to baolsen/terraform-aws-autoscaling that referenced this issue May 15, 2024
@baolsen baolsen linked a pull request May 15, 2024 that will close this issue
3 tasks
baolsen added a commit to baolsen/terraform-aws-autoscaling that referenced this issue May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants