【问题标题】:"Ambiguous attribute key" error after updating to terraform version 0.12.26更新到 terraform 版本 0.12.26 后出现“不明确的属性键”错误
【发布时间】:2020-10-16 12:23:08
【问题描述】:

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

variable "foo" {
  type = map
}


foo = {
  x.y = "bar"
}

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

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.

有人可以帮忙吗?

【问题讨论】:

    标签: terraform terraform-provider-aws terraform0.12+


    【解决方案1】:

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

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

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

    【讨论】:

    • @Meet101 这个答案是正确的,你应该接受它并投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 2013-11-12
    • 2020-05-25
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多