The following statement was broken after upgrading from 0.11.14 => 0.12.0.
lifecycle {
create_before_destroy = true
ignore_changes = ["tags.%", "tags.kubernetes.io"]
}
The upgrade utility stated that nothing needed to be changed.
$ terraform 0.12checklist
Looks good! We did not detect any problems that ought to be
addressed before upgrading to Terraform v0.12.
This tool is not perfect though, so please check the v0.12 upgrade
guide for additional guidance, and for next steps:
https://www.terraform.io/upgrade-guides/0-12.html
$ terraform version
Terraform v0.11.14
+ provider.aws v2.12.0
+ provider.random v2.1.2
+ provider.template v2.1.2
Your version of Terraform is out of date! The latest version
is 0.12.0. You can update by downloading from www.terraform.io/downloads.html
Here's the terraform validate output from 0.12.0
$ terraform validate
Error: Attribute name required
on modules/vpc/vpc.tf line 28, in resource "aws_vpc" "ct":
28: ignore_changes = ["tags.%", "tags.kubernetes.io"]
Dot must be followed by attribute name.
Error: Attribute name required
on modules/subnets/template/subnet_tmpl.tf line 55, in resource "aws_subnet" "template":
55: ignore_changes = ["tags.%", "tags.kubernetes.io"]
Dot must be followed by attribute name.
Error: Attribute name required
on modules/subnets/template/subnet_tmpl.tf line 55, in resource "aws_subnet" "template":
55: ignore_changes = ["tags.%", "tags.kubernetes.io"]
Dot must be followed by attribute name.
Removing tags.% fixes the immediate issue and outputs this.
Error: Unsupported attribute
on modules/vpc/vpc.tf line 28, in resource "aws_vpc" "ct":
28: ignore_changes = ["tags.kubernetes.io"]
This value does not have any attributes.
Hi @pgporada!
Did you follow the steps in the upgrade guide? In particular, the step of running terraform 0.12upgrade after upgrading to Terraform 0.12 should have rewritten these to use the new Terraform v0.12 syntax.
I just followed the steps from the guide and this is the result I get.
Error: Unsupported attribute
on modules/vpc/vpc.tf line 30, in resource "aws_vpc" "ct":
30: tags.kubernetes.io,
This value does not have any attributes.
I noticed that terraform 0.12upgrade <dir> changed tags.% to tags. That's intended to happen, correct?
Indeed removing the .% is expected; that syntax was never officially supported and was working only due to an implementation detail of how maps were stored in the state in Terraform 0.11. However, it looks like you wanted to ignore only a specific attribute here, so I expect you'll want to remove that tags entry altogether in order to avoid ignoring changes to other tag names within the map.
Looking again at your other example, it looks like Terraform's parser understood that as being the io attribute of the kubernetes attribute of tags, rather than the kubernetes.io attribute. If you have a tag key that is named "kubernetes.io" then you'll need to ignore that using the index syntax instead, so that the dot can be understood as part of the key: tags["kubernetes.io"].
Using the following lifecycle block now produces the output below
lifecycle {
create_before_destroy = true
ignore_changes = [
tags["kubernetes.io"]
]
}
Error: Invalid expression
on modules/vpc/vpc.tf line 29, in resource "aws_vpc" "ct":
29: tags["kubernetes.io"]
A static variable reference is required.
@pgporada From documentation: "The lifecycle settings all effect how Terraform constructs and traverses the dependency graph. As a result, only literal values can be used because the processing happens too early for arbitrary expression evaluation."
https://www.terraform.io/docs/configuration/resources.html#lifecycle-lifecycle-customizations
Hi all,
We merged a fix for this in #21788, which will be included in the next release. After that is released, the correct syntax for ignoring a tag named "kubernetes.io" would be:
resource "aws_vpc" "example" {
# ...
tags = {
# ...
"kubernetes.io" = "unset" # initial value for Terraform to ignore changes to
}
lifecycle {
ignore_changes = [
tags["kubernetes.io"],
]
}
}
The fix also includes an extra paragraph and example in the lifecycle block documentation. That will be live on the site after the release; in the meantime you can, if you wish, review the equivalent source document.
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.
Most helpful comment
Hi all,
We merged a fix for this in #21788, which will be included in the next release. After that is released, the correct syntax for ignoring a tag named "kubernetes.io" would be:
The fix also includes an extra paragraph and example in the
lifecycleblock documentation. That will be live on the site after the release; in the meantime you can, if you wish, review the equivalent source document.