Terraform: NewComputed and ForcesNew attr only diffs dropped if ignore_changes used

Created on 13 Apr 2018  ·  10Comments  ·  Source: hashicorp/terraform

Terraform Version

Terraform v0.11.7
+ provider.aws v1.14.1

Terraform Configuration Files

variable "ami" {}

provider "aws" {
   region = "us-east-1"
}

resource "aws_launch_configuration" "test" {
  name_prefix   = "test-"
  image_id      = "${var.ami}"
  instance_type = "t2.micro"

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_group" "test" {
  availability_zones        = ["us-east-1e"]
  name                      = "${aws_launch_configuration.test.name}"
  max_size                  = 1
  min_size                  = 0
  desired_capacity          = 0
  launch_configuration      = "${aws_launch_configuration.test.name}"

  lifecycle {
    create_before_destroy = true
    ignore_changes = ["desired_capacity"]
  }
}

Debug Output

trace output created by script
https://gist.github.com/dpiddockcmp/c4eee7822364f5f737c769e5f810f8f6

Expected Behavior

Rerunning the plan with a different AMI should cause both the aws_launch_configuration and aws_autoscaling_group to be recreated.

Actual Behavior

Second run with different AMI causes only the aws_launch_configuration to be marked for recreation. The apply then fails as the aws_autoscaling_group is still using the original launch configuration which cannot be deleted.

Steps to Reproduce

  1. terraform init
  2. terraform apply -var ami=ami-1853ac65
  3. terraform apply -var ami=ami-97785bed

Additional Context

The presence of the ignore_changes lifecycle block causes this issue, even though it is ignoring an attribute that is not being changed. Removing the ignore_changes block causes terraform to behave as desired.

I haven't been able to get the null_resource to duplicate this issue as it does not set NewComputed on the triggers.

My first thought is a bug in terraform/eval_diff.go's processIgnoreChanges(). I'll put in a pull request for that soon. Or is the AWS provider behaving incorrectly by setting NewComputed on the name attribute when it is being specified by the user? I tried using name_prefix instead but get the same result as internally it sets name.

References

bug core v0.11

All 10 comments

Have that same issue in Terraform v0.11.10 .
It's quite annoying since running terraform while desired_capacity is not ignored and has a different value than one described in tf causes down/upscaling on running cluster.

Experience the same issue, not with launch_configuration but with launch_template. Equally annoying

This issue still exists in v0.11.11. Are there any plans to fix this?

The issue seems to be fixed in v0.12.4.

This issue still exist in Terraform 0.12.6 !

Hi folks! I'm sorry for the long silence on this issue.

Please react to the original issue comment with 👍, which we can and do report on during prioritization.

"+1" comments creates noise for others watching the issue and ultimately doesn't influence our prioritization. Thank you!

Same issue on 0.12.10

👍

Hi all,

The implementation of ignore_changes was rewritten as part of the configuration language revamp in Terraform v0.12. While I don't doubt that some of you are seeing some similar behavior in Terraform v0.12 releases, the v0.12 is so different that the reproduction cases and logs originally supplied from v0.11.7 are no longer helpful to understand what's going on with v0.12.

For that reason, I'm going to close this issue to represent that the v0.11 manifestation of this issue is resolved. If you are still seeing similar behavior in a v0.12 or later release, please open a new issue and complete the issue template so we can see a full reproduction case against the current implementation. We'll then investigate what's going on. ignore_changes saw further improvements in Terraform 0.12.9, so we'd ideally like to see reproduction information against a more recent 0.12 release to ensure we're reproducing with the latest ignore_changes implementation.

Thanks!

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ketzacoatl picture ketzacoatl  ·  3Comments

shanmugakarna picture shanmugakarna  ·  3Comments

franklinwise picture franklinwise  ·  3Comments

rnowosielski picture rnowosielski  ·  3Comments

larstobi picture larstobi  ·  3Comments