正在定义 Terraform template_file vars 属性



我有一个模块,其中包含包含变量的template_file部分,其中变量用于后续资源

data "template_file" "my_template" {
template = "/dev/null"
vars {
var1 = "value with ${var.module_input}"
}
}
resource .... {
attribute = "${data.template_file.my_template.vars.var1}"
}

当我运行terraform时,我收到类似

Resource 'data.template_file.my_template' does not have attribute 'vars.var1' for variable 'data.template_file.my_template.vars.var1'

无论出于何种原因,模板变量中的var1似乎都没有定义并可供后续使用。

我将如何解决可能导致单个变量无法从template_file导出的原因?

template_file将变量公开为映射。

你需要做的

attribute = "${data.template_file.my_template.vars['var1']}"

以访问它。

您可以在此处阅读有关此内容的信息:https://www.terraform.io/docs/configuration/interpolation.html#user-map-variables

最新更新