Terraform 地形生成嵌套数据

Terraform 地形生成嵌套数据,terraform,Terraform,我在terraform中有以下输入,但无法生成所需的输出 我在tf中没有看到任何选项可以通过for循环中的资源\应用\ id进行过滤 在过去的几天里一直坚持这个。感谢您的帮助 input_data = [ { "resource_app_id" = "62ec2d38-2d53-4204-989b-053a65534873" "id" = "b43b06f7-92d1-0a98-bcc5-b6d13557f

我在terraform中有以下输入,但无法生成所需的输出

我在tf中没有看到任何选项可以通过for循环中的资源\应用\ id进行过滤

在过去的几天里一直坚持这个。感谢您的帮助

input_data = [
  {
    "resource_app_id" = "62ec2d38-2d53-4204-989b-053a65534873"
    "id" = "b43b06f7-92d1-0a98-bcc5-b6d13557fafd"
    "Type"  = "Role"
  },
  {
    "resource_app_id" = "62ec2d38-2d53-4204-989b-053a65534873"
    "id" = "019aa34d-20ce-f301-586c-c5a1cbe410cf"
    "type"  = "Role"
  },
  {
    "resource_app_id" = "193b6dcb-1323-4f56-8dc5-eed6f9a2789e"
    "id" = "c72de1fc-b40d-4bfc-a08a-79a23c486cc7"    
    "type"  = "Role"
  },
]

期望输出


requiredResourceAccess": [
        {
            "resourceAppId": "62ec2d38-2d53-4204-989b-053a65534873",
            "resourceAccess": [
                {
                    "id": "b43b06f7-92d1-0a98-bcc5-b6d13557fafd",
                    "type": "Role"
                },
                {
                    "id": "019aa34d-20ce-f301-586c-c5a1cbe410cf",
                    "type": "Role"
                }
            ]
        },
        {
            "resourceAppId": "193b6dcb-1323-4f56-8dc5-eed6f9a2789e",
            "resourceAccess": [
                {
                    "id": "c72de1fc-b40d-4bfc-a08a-79a23c486cc7",
                    "type": "Role"
                } 
            ]
        }

是的,我们可以使用for循环和terraform提供的一些函数来实现这一点:
(清晰、平坦,如果有)

我对输入变量进行了一点压缩,以便代码更适合屏幕

有了这些,我们可以运行一个计划,我们将得到:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + requiredResourceAccess = [
      + {
          + resourceAccess = [
              + {
                  + id   = "b43b06f7-92d1-0a98-bcc5-b6d13557fafd"
                  + type = "Role"
                },
              + {
                  + id   = "019aa34d-20ce-f301-586c-c5a1cbe410cf"
                  + type = "Role"
                },
            ]
          + resourceAppId  = "62ec2d38-2d53-4204-989b-053a65534873"
        },
      + {
          + resourceAccess = [
              + {
                  + id   = "c72de1fc-b40d-4bfc-a08a-79a23c486cc7"
                  + type = "Role"
                },
            ]
          + resourceAppId  = "193b6dcb-1323-4f56-8dc5-eed6f9a2789e"
        },
    ]

------------------------------------------------------------------------
使用
“terraform_版本”进行测试:“0.14.5”


我还想指出,您的初始输入具有不同大小写的类型:

input_data = [
  { ...
    "Type"  = "Role"
  },
  { ...
    "type"  = "Role"
  },

我假设这是一个输入错误,所有的输入都应该在同一个案例中,否则会导致错误。

非常感谢您花时间给出答案。你节省了很多时间。。我刚接触terraform,还在学习。谢谢!!!它解决了我的问题。
input_data = [
  { ...
    "Type"  = "Role"
  },
  { ...
    "type"  = "Role"
  },