Reputation: 25
how can i use the name of ressource as display_name without repeate action for each ressource, in the bellow my exemple, i want use the same template i change juste the resource "azuread_group" "name" :
resource "azuread_group" "dataops" {
display_name = "azad-rbac-grp-dataops"
owners = [data.azuread_client_config.azad.object_id]
security_enabled = true
}
resource "azuread_group" "finops" {
display_name = "azad-rbac-grp-finops"
owners = [data.azuread_client_config.azad.object_id]
security_enabled = true
}
resource "azuread_group" "archi" {
display_name = "azad-rbac-grp-archi"
owners = [data.azuread_client_config.azad.object_id]
security_enabled = true
}
resource "azuread_group" "secops" {
display_name = "azad-rbac-grp-secops"
owners = [data.azuread_client_config.azad.object_id]
security_enabled = true
}
thanks
Upvotes: 1
Views: 437
Reputation: 238299
You can't do this. Instead you should use a map
or a list
with count
or for_each
. For example:
variable "name" {
default = ["dataops","finops","archi","secops"]
}
then you use for_each
:
resource "azuread_group" "rg" {
for_each = toset(var.name)
display_name = "azad-rbac-grp-${each.key}"
owners = [data.azuread_client_config.azad.object_id]
security_enabled = true
}
Once this is done you can refer to individual rg
as:
azuread_group.rg["dataops"].display_name
azuread_group.rg["finops"].display_name
# and so on
Upvotes: 2