Terraform-provider-aws: aws_autoscaling_group with ignore_changes is not being properly recreated when its launch_configuration is updated

Created on 19 Jul 2018  路  4Comments  路  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.7

Affected Resource(s)

  • aws_autoscaling_group
  • aws_autoscaling_schedule
  • aws_launch_configuration

Terraform Configuration Files

data "aws_ami" "testAmi" {
  ...
}

resource "aws_launch_configuration" "testLC" {
  image_id = "${data.aws_ami.testAmi.id}"
  instance_type = "m4.xlarge"
  name_prefix = "testLC-"
  user_data = "test1"
  lifecycle {
    create_before_destroy = true,
    prevent_destroy = false
  }
}

resource "aws_autoscaling_group" "testASG" {
  max_size = 1
  min_size = 1
  health_check_grace_period = 600
  health_check_type = "ELB"
  launch_configuration = "${aws_launch_configuration.testLC.name}"
  name = "${aws_launch_configuration.testLC.name}-asg"
  vpc_zone_identifier = [ "test-vpc-zone" ]
  lifecycle {
    ignore_changes = [ "health_check_grace_period" ]
  }
}

Expected Behavior

After applying the above, I would expect that when I make a change that forces a new resources for the aws_launch_configuration (e.g changing the user_data), the aws_autoscaling_group would have its launch_configuration updated and a new resource forced since its name depends on the aws_launch_configuration. Note that this works fine if the ASG's ignore_changes is empty.

Actual Behavior

Changing the user_data for the aws_launch_configuration forces a new resource for the launch configuration, but does NOT cause an update of the aws_autoscaling_group.

Steps to Reproduce

  1. terraform apply
  2. Change the user_data of testLC
  3. terraform plan, note that testLC is updated but testASG is not
  4. Change testASG's name manually to something that doesn't interpolate testLC
  5. terraform plan, note that now testASG is updated
  6. Change testASG's name back, and instead change ignore_changes to be an empty list
  7. terraform plan, again note that testASG is updated
bug servicec2

Most helpful comment

Based on testing (and communicating with @lowjoel), this behavior does not occur with Terraform 0.12.x. Just FYI for anyone watching this issue.

All 4 comments

Very similar in my case. A few notes: any changes in LC which will require LC recreation could be used, not only changes in user_data. In my case, desired_count was ignored in ASG and led to the same results. Even when desired_count attribute was absent from ASG configuration

I don't know if this is relevant, but when my team updated the AWS provider from 1.60 to the latest 2.x release, we saw this manifest (exactly the same case as @dvishniakov where we ignore the desired_capacity attribute)

If anyone has an idea where I should start looking so that we can fix this I'd be glad to work on the problem... but short of any advice I'd probably not make any meaningful progress.

I see this here when running TF_LOG=debug:

2019/09/03 18:21:01 [DEBUG] Removing 'id' diff and setting Destroy to false because after ignore_changes, this diff no longer requires replacement
2019/09/03 18:21:01 [DEBUG] [EvalIgnoreChanges] aws_autoscaling_group.asg - Ignoring diff attribute: name_prefix

And that's defined here https://github.com/hashicorp/terraform/blob/v0.11/terraform/eval_diff.go#L281. For some reason despite name_prefix changing Terraform decides that it does not need to recreate the resource. I'm still not sure how to fix this, though.

Based on testing (and communicating with @lowjoel), this behavior does not occur with Terraform 0.12.x. Just FYI for anyone watching this issue.

Was this page helpful?
0 / 5 - 0 ratings