【问题标题】:Terraform Error : Invalid dot index foundTerraform 错误:找到无效的点索引
【发布时间】:2019-02-13 22:41:55
【问题描述】:

我使用的是 terraform 版本 0.11.8 并尝试了这个 POC https://github.com/salizzar/terraform-aws-docker 当我执行 terraform init 时,它会引发以下错误。 我是使用 terraform 的新手。谷歌搜索了很多,并尝试引用 terraform 模块注册表来摆脱这个错误,但徒劳无功。

有人可以运行此 POC 并指出需要更改的内容吗?

https://github.com/salizzar/terraform-aws-docker/blob/master/main.tf

**ERROR :**

[root@localhost test]# terraform init
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Error loading /home/tottally/main.tf: Invalid dot index found: 'var.aws_security_group.sg_count'. Values in maps and lists can be referenced using square bracket indexing, like: 'var.mymap["key"]' or 'var.mylist[1]'. in:

${var.aws_security_group.sg_count}

【问题讨论】:

  • 我在这里找到了一个参考:stackoverflow.com/questions/38375252/… 似乎 concat 函数在 terraform 中已过时,但我仍然坚持更换它
  • 其中一个失败的尝试是去掉 main.tf 中的 concat 并像这样替换它 :name = "terraform_security_group_${lookup(var.aws_security_group, "sg_[count.index]_name") }"

标签: terraform


【解决方案1】:

我认为 Terraform 对这行不满意:

count = "${var.aws_security_group.sg_count}"

不要使用这种双点符号,而是尝试使用方括号索引,正如 Terraform 本身在错误消息中所建议的那样:

count = "${var.aws_security_group[sg_count]}"

顺便说一下,这个 repo 真的很老了,你可以在公共 Terraform 注册表中找到更好和最新的示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 2020-07-06
    • 2017-01-12
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多