Terraform-provider-aws: aws_autoscaling_group mixed_instances_policy, can't set instance_type to ""

Created on 29 Apr 2019  路  3Comments  路  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.11.13
+ provider.archive v1.2.1
+ provider.aws v2.7.0
+ provider.local v1.2.1
+ provider.null v2.1.1
+ provider.random v2.1.1
+ provider.template v2.1.1

Affected Resource(s)

  • aws_autoscaling_group

Terraform Configuration Files

resource "aws_autoscaling_group" "test" {
  name             = "test"
  desired_capacity = 1
  max_size         = 1
  min_size         = 1

  mixed_instances_policy {

    launch_template {
      launch_template_specification {
        launch_template_id = "lt-02dde2f87b200ea75"
        version            = "$Latest"
      }

      override {
        instance_type = "t3.medium"
      }

      override {
        instance_type = "c4.large"
      }

      override {
        instance_type = ""
      }
    }
  }
  vpc_zone_identifier   = ["subnet-030dd08b792455d65"]
}

Expected Behavior

Every apply is clean on every run. Note the last override of instance_type = "".

Actual Behavior

Terraform applies this on every run:

  ~ aws_autoscaling_group.test
      mixed_instances_policy.0.launch_template.0.override.#: "2" => "3"

Steps to Reproduce

  1. terraform apply

Important Factoids

In the EC2 console, it looks good, there's only 2 instances specified for the ASG.

The reason for wanting to be able to set the instance_type to "" is because I want to define the aws_autoscaling_group resource inside a module and be able to pass optional extra instance types to the module that default to "". e.g.

module "my_asg_module" {
  name = "test"
  instance_type_1 = "t2.medium"
  instance_type_2 = "t3.large"
  instance_type_3 = "m4.large"
  instance_type_4 = "m5.large"
  instance_type_5 = "r4.xlarge"
}

The real example is here: https://github.com/terraform-aws-modules/terraform-aws-eks/blob/18baeea1fce469a95170889b52d6e3aebb15727e/workers_launch_template.tf#L28-L34

bug servicautoscaling

All 3 comments

whats the reason "instance_type" is not a list type in override map?

Why not just use a _dynamic_ block in terraform?
https://www.terraform.io/docs/configuration/expressions.html#dynamic-blocks

Your module could look like this:

dynamic override {
  for_each = var.instances
  content {
      instance_type     = override.key
      weighted_capacity = override.value
  }
}

And your code looks like that:

module "spot" {
  instances = {
    # instance_type = weighted_capacity
    "t3a.medium" = 1
    "t3.medium" = 1
  }
}

No need to do that weird empty string thing.

Any known workarounds for Terraform v0.11?

Was this page helpful?
0 / 5 - 0 ratings