【发布时间】:2020-11-06 09:53:31
【问题描述】:
我在迭代由templatefile 函数解释的模板中的对象列表时遇到问题。
我有以下变量:
variable "destinations" {
description = "A list of EML Channel Destinations."
type = list(object({
id = string
url = string
}))
}
这将作为destinations 传递给templatefile 函数。模板相关的sn-p是这样的:
Destinations:
%{ for dest in destinations ~}
- Id: ${dest.id}
Settings:
URL: ${dest.url}
%{ endfor }
在规划 Terraform 时会出现以下错误:
Error: "template_body" contains an invalid YAML: yaml: line 26: did not find expected key
我已尝试将模板代码切换为以下内容:
Destinations:
%{ for id, url in destinations ~}
- Id: ${id}
Settings:
URL: ${url}
%{ endfor }
这给出了不同的错误:
Call to function "templatefile" failed:
../../local-tfmodules/eml/templates/eml.yaml.tmpl:25,20-23: Invalid template
interpolation value; Cannot include the given value in a string template:
string required., and 2 other diagnostic(s).
[!] something went wrong when creating the environment TF plan
我觉得我在这里对数据类型的迭代是不正确的,但我无法理解怎么做,而且我根本找不到任何关于此的文档。
这是我如何调用此模块的简化示例:
module "eml" {
source = "../../local-tfmodules/eml"
name = "my_eml"
destinations = [
{
id = "6"
url = "https://example.com"
},
{
id = "7"
url = "https://example.net"
}
]
<cut>
}
【问题讨论】:
标签: function terraform terraform0.12+