首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建terraform hcl变量作为映射

创建terraform hcl变量作为映射
EN

Stack Overflow用户
提问于 2020-12-01 21:26:29
回答 1查看 1.2K关注 0票数 2

我正在使用tfe提供程序进行terraform工作区自动化工作,并希望使用下面的数据结构创建一个terraform变量作为使用custom_tags的映射。

代码语言:javascript
复制
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" = {}
  }
}

这是我的资源块

代码语言:javascript
复制
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
}

而且,我得到了这个错误。任何帮助都是非常感谢的,以解决这个问题。

代码语言:javascript
复制
**each.value.custom_tags is object with 4 attributes
Inappropriate value for attribute "value": string required.**

预期结果

custom_tags应该作为HCL变量创建。

代码语言:javascript
复制
custom_tags = 
{
   "Application" = "demo"
   "EnvironmentType" = "prod"
   "NamePrefix" = "sof"
   "ProductType" = "terraform"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-01 23:02:17

可惜你不能这么做。value属性必须是string,但是您正在尝试向它分配一个“具有4个属性的对象”。

您可以使用each.value.custom_tags将您的jsonencode转换为字符串,但这可能不是您想要的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65098819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档