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

aws_autoscaling_group -> mixed_instances_policy -> launch_template -> override don't support count #6738

Closed
jippi opened this issue Dec 6, 2018 · 3 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/autoscaling Issues and PRs that pertain to the autoscaling service. upstream-terraform Addresses functionality related to the Terraform core binary.

Comments

@jippi
Copy link

jippi commented Dec 6, 2018

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 -v
Terraform v0.11.10
+ provider.archive v1.1.0
+ provider.aws v1.50.0
+ provider.cloudflare v1.9.0
+ provider.consul v2.2.0
+ provider.datadog v1.6.0
+ provider.null v1.0.0
+ provider.random v2.0.0
+ provider.template v1.0.0
+ provider.vault v1.3.1

Affected Resource(s)

resource "aws_autoscaling_group" "this" {
  name                      = "${var.class}"
  min_size                  = "${var.asg_min_size}"
  max_size                  = "${var.asg_max_size}"
  health_check_grace_period = "${var.asg_health_check_grace_period}"
  health_check_type         = "${var.asg_health_check_type}"
  target_group_arns         = ["${compact(local.target_group_arns)}"]
  vpc_zone_identifier       = ["${var.subnets}"]
  wait_for_capacity_timeout = 0
  default_cooldown          = "${var.asg_default_cooldown}"

  enabled_metrics = [
    "GroupMinSize",
    "GroupMaxSize",
    "GroupDesiredCapacity",
    "GroupInServiceInstances",
    "GroupPendingInstances",
    "GroupStandbyInstances",
    "GroupTerminatingInstances",
    "GroupTotalInstances",
  ]

  mixed_instances_policy {
    launch_template {
      launch_template_specification {
        launch_template_id = "${aws_launch_template.this.id}"
        version            = "$$Latest"
      }

      override {
        count         = "${length(var.instance_types)}"
        instance_type = "${element(var.instance_types, count.index)}"
      }
    }

    instances_distribution {
      on_demand_base_capacity                  = 0
      on_demand_percentage_above_base_capacity = 0
      spot_allocation_strategy                 = "lowest-price"
      spot_instance_pools                      = "${var.spot_instance_pools}"
    }
  }
}

Expected Behavior

My mixed_instances_policy should have $x override created

I replaced

override {
  instance_type = "c5.large"
}
override {
  instance_type = "m5.large"
}
override {
  instance_type = "t3.medium"
}

with

override {
  count         = "${length(var.instance_types)}"
  instance_type = "${element(var.instance_types, count.index)}"
}

my variables.hcl

variable "instance_types" {
  description = "List of instance types to use"
  type        = "list"
  default     = ["t3.large", "m5.large", "c5.xlarge"]
}

expecting to be able to provide instance types as a variable

Actual Behavior

Error: module.web.aws_autoscaling_group.this: mixed_instances_policy.0.launch_template.0.override.0: invalid or unknown key: count

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. upstream-terraform Addresses functionality related to the Terraform core binary. service/autoscaling Issues and PRs that pertain to the autoscaling service. terraform-0.12 labels Dec 6, 2018
@bflad
Copy link
Contributor

bflad commented Dec 6, 2018

Hi @jippi 👋 Thanks for submitting this.

The count concept in Terraform 0.11's configuration language only applies to the top level resource configuration, to determine a number of resources to manage. Dynamic declaration of configuration blocks within any Terraform resource will be supported in Terraform 0.12 when it is released in the coming months.

A blog post detailing this concept can be found here: https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each

The issue with the specific feature request upstream in Terraform core can be found here: hashicorp/terraform#7034

Since this enhancement will be covered by the upcoming Terraform 0.12 release and requires no action within the provider itself, I'm going to close this issue. 👍

@bflad bflad closed this as completed Dec 6, 2018
@dushyants
Copy link

dushyants commented Sep 9, 2019

i got the same issue but i did it in the different way like below:

locals {
  asg_instance_type = {
    asg_instance_type_1 = "t2.small"
    asg_instance_type_2 = "t2.micro"
    asg_instance_type_3 = "t2.medium"
  }
}


  dynamic "override" {
      for_each = "${local.asg_instance_type}"
         content {
            instance_type = "${override.value}"
        }
      }

@ghost
Copy link

ghost commented Nov 1, 2019

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/autoscaling Issues and PRs that pertain to the autoscaling service. upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

No branches or pull requests

3 participants