hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

aws_autoscaling_group failed when 'for' provided in vpc_zone_identifier #10501

Open LuciferInLove opened 4 years ago

LuciferInLove commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.10

Affected Resource(s)

aws_autoscaling_group

Terraform Configuration Files

Main section part example:

provider "aws" {
  version = "2.32.0"
}

module "base_vpc" {
  source = "../modules/base_vpc"
  autoscaling_hosts = [
      {
        name = "host_1"
        instance_type = "t3.medium"
        availability_zones = ["eu-west-1a", "eu-west-1b"]
        desired_capacity = 0
        min_size = 0
        max_size = 1
      },
      {
        name = "host_2"
        instance_type = "t3.small"
        availability_zones = ["eu-west-1b"]
        desired_capacity = 0
        min_size = 0
        max_size = 1
      },
  ]
}

Module part example:

resource "aws_autoscaling_group" "autoscaling" {
  count              = length(var.autoscaling_hosts)
  depends_on         = [aws_route.private, aws_launch_template.autoscaling]

  name               = "${lookup(var.autoscaling_hosts[count.index], "name")}-${var.env}"
  availability_zones = lookup(var.autoscaling_hosts[count.index], "availability_zones")
  desired_capacity   = lookup(var.autoscaling_hosts[count.index], "desired_capacity")
  min_size           = lookup(var.autoscaling_hosts[count.index], "min_size")
  max_size           = lookup(var.autoscaling_hosts[count.index], "max_size")

  launch_template {
    id      = element(aws_launch_template.autoscaling.*.id, count.index)
    version = "$Latest"
  }

  vpc_zone_identifier = [for zone in lookup(var.autoscaling_hosts[count.index], "availability_zones") : element(aws_subnet.private.*.id, index(lookup(var.autoscaling_hosts[count.index], "availability_zones"), zone))]
}

Debug Output

2019/10/14 16:41:59 [WARN] Provider "aws" produced an invalid plan for module.base_vpc.aws_autoscaling_group.autoscaling[0], but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .force_delete: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .protect_from_scale_in: planned value cty.False does not match config value cty.NullVal(cty.Bool)
      - .availability_zones: planned value cty.UnknownVal(cty.Set(cty.String)) does not match config value cty.SetVal([]cty.Value{cty.StringVal("eu-west-1a"), cty.StringVal("eu-west-1b")})
      - .wait_for_capacity_timeout: planned value cty.StringVal("10m") does not match config value cty.NullVal(cty.String)
      - .health_check_grace_period: planned value cty.NumberIntVal(300) does not match config value cty.NullVal(cty.Number)
      - .metrics_granularity: planned value cty.StringVal("1Minute") does not match config value cty.NullVal(cty.String)

Panic Output

Panic gist

Expected Behavior

Resource must be created when terraform apply provided

Actual Behavior

When I run 'terraform apply' at first time, I see an error like in gist above. When I run 'terraform apply' at second time, aws_autoscaling_group resource is creating successfully.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

LuciferInLove commented 4 years ago

The problem happens when availability_zones and list in vpc_zone_identifier are used at the same time.

github-actions[bot] commented 2 years ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

justinretzolk commented 2 years ago

Hey @LuciferInLove 👋 Thank you for taking the time to file this issue! Given that there's been a number of Terraform and AWS provider releases since you initially filed it, can you confirm whether you're still experiencing this behavior?