Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.12.0 Error: Attribute name required #21444

Closed
pgporada opened this issue May 24, 2019 · 7 comments

Comments

Projects
None yet
3 participants
@pgporada
Copy link

commented May 24, 2019

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.
@apparentlymart

This comment has been minimized.

Copy link
Member

commented May 24, 2019

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.

@pgporada

This comment has been minimized.

Copy link
Author

commented May 28, 2019

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?

@apparentlymart

This comment has been minimized.

Copy link
Member

commented May 29, 2019

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"].

@pgporada

This comment has been minimized.

Copy link
Author

commented May 29, 2019

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.
@enver

This comment has been minimized.

Copy link

commented Jun 20, 2019

@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

@apparentlymart

This comment has been minimized.

Copy link
Member

commented Jun 20, 2019

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.

@pgporada

This comment has been minimized.

Copy link
Author

commented Jun 20, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.