我正在使用tfe提供程序进行terraform工作区自动化工作,并希望使用下面的数据结构创建一个terraform变量作为使用custom_tags的映射。
workspaces = {
"PROD" = {
"custom_tags" = {
"Application" = "demo"
"EnvironmentType" = "prod"
"NamePrefix" = "sof"
"ProductType" = "terraform"
}
"env_variables" = {}
"id" = "alfsdfksf"
"name" = "PROD"
"repo" = "github/something"
"tf_variables" = {}
}
"UAT" = {
"custom_tags" = {
"Application" = "demo"
"EnvironmentType" = "uat"
"NamePrefix" = "sof"
"ProductType" = "terraform"
}
"env_variables" = {}
"id" = "ws-k7KWYfsdfsdf"
"name" = "UAT"
"repo" = "github/otherthing"
"tf_variables" = {}
}
}这是我的资源块
resource "tfe_variable" "terraform_hcl_variables" {
for_each = { for w in local.workspaces : w.name => w }
key = "custom_tags"
value = each.value.custom_tags
category = "terraform"
hcl = true
sensitive = false
workspace_id = tfe_workspace.main[each.key].id
}而且,我得到了这个错误。任何帮助都是非常感谢的,以解决这个问题。
**each.value.custom_tags is object with 4 attributes
Inappropriate value for attribute "value": string required.**预期结果
custom_tags应该作为HCL变量创建。
custom_tags =
{
"Application" = "demo"
"EnvironmentType" = "prod"
"NamePrefix" = "sof"
"ProductType" = "terraform"
}发布于 2020-12-01 23:02:17
可惜你不能这么做。value属性必须是string,但是您正在尝试向它分配一个“具有4个属性的对象”。
您可以使用each.value.custom_tags将您的jsonencode转换为字符串,但这可能不是您想要的。
https://stackoverflow.com/questions/65098819
复制相似问题