terraform-provider-aws: Since v3.68.0 `aws_launch_template` no longer reports `latest_version` until after changes are applied

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 other comments that do not add relevant new information or questions, 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 CLI and Terraform AWS Provider Version

Terraform v0.14.6
+ provider registry.terraform.io/hashicorp/aws v3.68.0
+ provider registry.terraform.io/hashicorp/random v3.1.0

Affected Resource(s)

  • aws_launch_template

Expected Behavior

Expect aws_launch_template.<resource_name>.latest_version to update during apply stages.

Actual Behavior

aws_launch_template.<resource_name>.latest_version does not update during apply stages.

Steps to Reproduce

resource "random_pet" "asg_name" {
  separator = "-"
  length    = 2

  keepers = {
    # Generate a new pet name each time we switch the launch template
    lt_name = "${aws_launch_template.this.name}+${aws_launch_template.this.latest_version}"
  }
}

Using AWS Provider v3.67.0, this resulted in:

+/- resource "random_pet" "asg_name" {
      ~ id        = "key-dove" -> (known after apply)
      ~ keepers   = {
          - "lt_name" = "example-launch-template-20200311171713363100000001+267"
        } -> (known after apply) # forces replacement
        # (2 unchanged attributes hidden)
    }

With AWS Provider v3.68.0, the resource is not updated until a 2nd run with terrafrom apply.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 57
  • Comments: 16 (4 by maintainers)

Most upvoted comments

We have the same issue

Error: Provider produced inconsistent final plan   
When expanding the plan for module.asg.aws_autoscaling_group.asg to include 
new values learned so far during apply, provider 
"registry.terraform.io/hashicorp/aws" produced an invalid new value for 
.launch_template[0].version: was cty.StringVal("13"), but now 
cty.StringVal("14"). 
This is a bug in the provider, which should be reported in the provider's own 
issue tracker.  

We currently have a failing acceptance test that is showing this behavior:

=== RUN   TestAccEC2LaunchTemplate_update
=== PAUSE TestAccEC2LaunchTemplate_update
=== CONT  TestAccEC2LaunchTemplate_update
    launch_template_test.go:468: Step 3/3 error: Check failed: Check 5/5 error: aws_autoscaling_group.test: Attribute 'launch_template.0.version' expected "2", got "1"
--- FAIL: TestAccEC2LaunchTemplate_update (76.20s)

It passes on v3.67.0:

% make testacc TESTARGS='-run=^TestAccEC2LaunchTemplate_update$$' PKG_NAME=internal/service/ec2                  
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run=^TestAccEC2LaunchTemplate_update$ -timeout 180m
=== RUN   TestAccEC2LaunchTemplate_update
=== PAUSE TestAccEC2LaunchTemplate_update
=== CONT  TestAccEC2LaunchTemplate_update
--- PASS: TestAccEC2LaunchTemplate_update (84.60s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	88.074s

Just did a test with 3.69.0 provider and found the latest_version issue still exists

I can confirm that v3.71.0 fixes the issue.

I had excluded provider version 3.68.0 but with 3.69.0 I got the error back. I will keep my production using < 3.68.0 until it is fixed

required_providers {
-    aws = "> 3.26, != 3.68.0"
+    aws = "> 3.26, < 3.68.0"
}

This functionality has been released in v3.71.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

When will this be fixed?

@ewbankkit is working on it. See https://github.com/hashicorp/terraform-plugin-sdk/pull/829.

In meantime you could pin the AWS Provider version to v3.67.0. In our case, we just needed the latest_version as an indicator that the launch template has changed (not necessarily the latest), so weโ€™ve replaced latest_version with the sha256() function on the launch templateโ€™s user_data (which for us will always change when the version changes).

Slightly easier way to replicate this is just to output latest_version. When you update the launch template resource, the output value does not change. A subsequent apply (with no code changes) then causes the output to be updated.