1

在 terraform 版本从 0.11 更新到 0.12.26 后,我看到地图内的查找和值列表出现错误。

variable "foo" {
  type = map
}


foo = {
  x.y = "bar"
}

我有一个映射“foo”作为变量类型(映射),然后我在映射中有 xy =“bar”的键值对。在查找中,我试图读取 xy 的值,

lookup(var.foo, x.y)

有了这个,我得到了错误,

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.

有人可以帮忙吗?

4

1 回答 1

1

如果您想要一个包含点字符的映射键,.那么您必须将键写在引号中,以便 Terraform 可以看到您打算生成一个包含点的字符串,而不是使用yvariable 属性的值x

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

同样,要访问该元素,您需要在索引表达式中引用键,例如foo["x.y"]. 您也可以使用lookup(foo, "x.y")- 仍然使用引号 - 但该方法在 Terraform 0.12 中已弃用,因为foo["x.y"]已将其替换为从地图值访问元素的主要方式。

于 2020-06-25T23:22:46.113 回答