在Terraform 0.12中解析list(object)数据类型中的内部数组

时间:2019-04-02 04:29:23

标签: terraform terraform-provider-gcp

如何在terraform 0.12中解析此数据类型

 variable "groups" {
    type = list(object({
        group_id = string
        permissions = list(string)
    }))
}

示例:

 groups = [
    {
        group_id = "gcp-org-admin"
        permissions = [ "roles/resourcemanager.organizationAdmin",
                        "roles/resourcemanager.folderViewer",
                        "roles/viewer",
                        "roles/iam.organizationRoleViewer",
                        "roles/orgpolicy.policyViewer"
                      ]  
    },
    {
        group_id = "gcp-security-ops"
        permissions = [ "roles/resourcemanager.folderViewer",
                        "roles/logging.viewer",
                        "roles/monitoring.editor",
                        "roles/iam.securityReviewer"
                      ]
    }]

对于每个组,我想将group_id和每个权限配对 就像

  {
    group_id = "gcp-org-admin"
    permissions = "roles/resourcemanager.organizationAdmin"
  },
  {
    group_id = "gcp-org-admin"
    permissions = "roles/resourcemanager.folderViewer"
  },
  {
    group_id = "gcp-org-admin"
    permissions = "roles/viewer"
  }

想创建organization_iam_resource

对于每个group_id中的每个权限,我必须创建一个资源。

有没有办法做到这一点

1 个答案:

答案 0 :(得分:0)

看看这个例子,它为您显示了可能的答案以及与嵌套列表相关的一些问题:https://github.com/hashicorp/terraform/issues/11036