我正在尝试完成类似的事情。
variable "custom_role_list" {
type = list(object ({ service_principal_id = string, role = string }) )
}
当我尝试从资源模块设置它时
resource "azurerm_role_assignment" "ad_sp_role_assignment" {
scope = azurerm_container_registry.acr.id
for_each = var.custom_role_list
role_definition_name = each.value.role
principal_id = each.value.service_principal_id
}
本质上,我正在尝试将 azure 容器注册表设置为与具有特定访问角色的多个服务主体一起使用。
以下是 var 定义。
custom_role_list = [
{
service_principal_id = aserviceprincipal.id
role = "Contributor"
},
{
service_principal_id = bserviceprincipal.id
role = "Contributor"
}
]
当我执行它时,我收到以下错误。
Error: Invalid for_each argument
on ../modules/az-acr/main.tf line 46, in resource "azurerm_role_assignment" "ad_sp_role_assignment":
46: for_each = var.custom_role_list
The given "for_each" argument value is unsuitable: the "for_each" argument
must be a map, or set of strings, and you have provided a value of type list
of object.
请如果有人可以指导将非常有帮助。谢谢!