Terraform-列表到字符串以创建天蓝色的订阅列表

时间:2020-05-30 20:58:22

标签: azure terraform terraform-provider-azure

我正在创建一个新的自定义Azure角色,并尝试使用以下代码将所有订阅ID传递给可分配范围参数,但是在从列表转换为具有正确字符串格式的字符串时遇到问题。这是角色定义模块doc-https://www.terraform.io/docs/providers/azurerm/r/role_definition.html

感谢任何输入或指导!

locals {
 subscription_list  = formatlist("/subscriptions/%s", data.azurerm_subscriptions.all.subscriptions[*].subscription_id)
  quoted_subsciption_list = formatlist("%q", local.sub_list)
}

当我使用join函数使用以下代码将其转换为字符串时, join(",", local.quoted_subsciption_list)

我得到的输出为“ \” / subscriptions / 7yed1028-4525-4533-b608-fb74c2a9c1rr \“,\” / subscriptions / 7uef9fad-dabf-8icf-8379-a3df99e7613c \“,

我希望输出为“ / subscriptions / 7yed1028-4525-4533-b608-fb74c2a9c1rr”,“ / subscriptions / 7uef9fad-dabf-8icf-8379-a3df99e7613c”。 当地人{ subscription_list = formatlist(“ / subscriptions /%s”,data.azurerm_subscriptions.all.subscriptions [*]。subscription_id) quoted_subsciption_list = formatlist(“%q”,local.sub_list) }

When I use join function to convert this into a string using the below code, 
```join(",", local.quoted_subsciption_list)```

I am getting the output as **"\"/subscriptions/7yed1028-4525-4533-b608-fb74c2a9c1rr\",\"/subscriptions/7uef9fad-dabf-8icf-8379-a3df99e7613c\",**

I want the output to be **"/subscriptions/7yed1028-4525-4533-b608-fb74c2a9c1rr", "/subscriptions/7uef9fad-dabf-8icf-8379-a3df99e7613c".**

1 个答案:

答案 0 :(得分:0)

local.subscription_list 已经是列表(字符串),这是azurerm_role_definition的 assignable_scopes 所需要的,因此您可以在 azurerm_role_definition 资源块:

assignable_scopes = local.subsciption_list