I want to create something like this with terraform locals { groups = { "Java" = {}…
- User
I want to create something like this with terraform locals { groups = { "Java" = {} "PHP" = {} "Templates" = {} "Infra" = { "Terraform" = {} "Kubernetes" = {} } } } resource "gitlab_group" "main_group" { name = "client" path = "." description = "Groupe de gestions des projets applicatifs de Caprikorn" visibility_level = "private" parent_id = data.gitlab_group.ekwa_group.id } resource "gitlab_group" "subgroups" { for_each = local.groups name = each.key path = each.key parent_id = gitlab_group.main_group.id } resource "gitlab_group" "subsubgroups" { for_each = { for key, value in local.groups : key => { name = key parent_id = gitlab_group.subgroups[].id } } name = each.key path = each.key } can you fix this expression to enable Terraform group and kubernetes as child of the infra group ? and if the { } is empty, as for the PHP, Java, Template group, then do nothing . Or suggest me a better idea. for_each = { for key, value in local.groups : key => { name = key parent_id = gitlab_group.subgroups[].id } }
- Assistant
To enable Terraform and Kubernetes as child groups of the Infra group, you can update the
for_eachexpression as follows:terraformfor_each = { for key, value in local.groups : key => { name = key parent_id = value == local.groups.Infra ? gitlab_group.subgroups[value].id : null } }This expression checks if the current group is Infra, and if yes, it retrieves the ID of the parent group. If the current group is not Infra, it sets the
parent_idto null.Here's the updated code:
terraform