Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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?

like image 540
Meet101 Avatar asked Dec 02 '25 04:12

Meet101


1 Answers

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.

like image 175
Martin Atkins Avatar answered Dec 05 '25 15:12

Martin Atkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!