'Create multiple scalable role_assignments in Terraform
i have been tasked to write the below code with minimal lines, rather having 3 resource blocks can this be done in a single block using for_each function. It should be scalable in near future when we add additional role assignements
resource "azurerm_role_assignment" "role_assignment_01" {
scope = data.azurerm_subscription.primary.id
role_definition_name = "Reader"
principal_id = data.azurerm_client_config.example.object_id
}
resource "azurerm_role_assignment" "role_assignment_02" {
scope = data.azurerm_subscription.primary.id
role_definition_name = "Contributor"
principal_id = data.azurerm_client_config.example.object_id
}
resource "azurerm_role_assignment" "role_assignment_03" {
scope = data.azurerm_subscription.primary.id
role_definition_name = "Network Contributor"
principal_id = data.azurerm_client_config.example.object_id
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|