Meet101
Meet101

Reputation: 811

"Ambiguous attribute key" error after updating to terraform version 0.12.26

After terraform version update from 0.11 to 0.12.26, I'm seeing error with lookup and list of values inside map.

variable "foo" {
  type = map
}


foo = {
  x.y = "bar"
}

I have a map "foo" as variable type (map) and then i have key-value pair in map with x.y = "bar". In lookup, I'm trying to read value of x.y as,

lookup(var.foo, x.y)

with this, I'm getting error,

Error: Ambiguous attribute key

  on line 13:
  13:   x.y = "bar"

If this expression is intended to be a reference, wrap it in parentheses. If
it's instead intended as a literal name containing periods, wrap it in quotes
to create a string literal.

can someone help?

Upvotes: 3

Views: 6027

Answers (1)

Martin Atkins
Martin Atkins

Reputation: 74749

If you want to have a map key that contains a dot character . then you must write the key in quotes, so Terraform can see that you intend to produce a string containing a dot rather than to use the value of the y attribute of variable x:

foo = {
  "x.y" = "bar"
}

Likewise, to access that element you'll need to quote the key in the index expression, like foo["x.y"]. You could also potentially use lookup(foo, "x.y") -- still with the quotes -- but that approach is deprecated in Terraform 0.12 because foo["x.y"] has replaced it as the main way to access an element from a map value.

Upvotes: 4

Related Questions