Skip to content

feat: Support groups nested under a subgroup - #16

Merged
sirantd merged 2 commits into
mainfrom
feat/nested-subgroups-v2
Oct 27, 2026
Merged

sirantd merged 2 commits into
mainfrom
feat/nested-subgroups-v2

Conversation

@sirantd

@sirantd sirantd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

Groups can only be two levels deep: gitlab_group.subgroups sets parent_id = gitlab_group.parent_groups[each.value.parent].id, so parent must be a top-level group. A layout such as infra/terraform/terraform-aws-modules (a mirror per upstream GitHub org, with projects like infra/terraform/terraform-aws-modules/terraform-aws-vpc) can't be expressed: parent = "infra/terraform" is not a key of parent_groups and plan fails.

What

  • New gitlab_group.nested_subgroups resource for groups whose parent is a subgroup key ("<top>/<name>"). parent matches the subgroup's name, not its path.
  • gitlab_group.subgroups now only takes groups whose parent has no /. No existing config has a slash in parent, so no existing address moves.
  • local.group_ids maps every managed group (all three levels) to its ID. All per-group resources (memberships, shares, variables, access/deploy tokens, labels, badges, boards, SAML links, push rules and others) and gitlab_project.namespace_id resolve through it instead of the parent_groups/subgroups ternaries.
  • gitlab_groups validation rejects a parent deeper than one subgroup.
  • New output nested_subgroups_group_ids.
  • tests/nested_subgroups.tftest.hcl: subgroup stays in subgroups, nested group lands in nested_subgroups, a nested group works as share target and project namespace, too-deep parent is rejected.
  • Example examples/terraform/groups/infra.yaml + projects/infra_projects.yaml (infra/terraform/terraform-aws-modules with a project in it), a test run that plans the whole example, and a "Nested subgroups" section in the Readme.

Verification

  • terraform test: 12 passed, 0 failed.
  • A real Terragrunt unit with ~110 existing groups planned against this branch: no changes to infrastructure (only the new empty output). With infra/terraform plus 7 nested groups added: 9 to add, 0 to change, 0 to destroy.

🤖 Generated with Claude Code

A group can now set parent to a subgroup key, e.g. parent = "infra/terraform",
creating infra/terraform/<name>. Such groups live in a new
gitlab_group.nested_subgroups resource; groups whose parent is a top-level
group stay in gitlab_group.subgroups, so their addresses do not change.

Every group ID lookup (memberships, shares, variables, tokens, labels,
project namespaces and the rest) now goes through local.group_ids, which
covers all three levels. A parent deeper than one subgroup fails validation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sirantd sirantd self-assigned this Oct 27, 2026
@wiseelf

wiseelf commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Could you provide test examples?

Add infra.yaml and infra_projects.yaml to the terraform example: infra,
infra/terraform and infra/terraform/terraform-aws-modules with a project
in it. A test run plans the whole example and checks the nested group,
its settings, its project and the share on its parent. Document parent
and the name/path rule in the Readme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wiseelf
wiseelf self-requested a review October 27, 2026 13:42
@sirantd
sirantd merged commit 5e98a5f into main Oct 27, 2026
3 checks passed

@wiseelf wiseelf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT

@sirantd
sirantd deleted the feat/nested-subgroups-v2 branch October 27, 2026 13:43
@github-actions

Copy link
Copy Markdown

This PR is included in version 2.3.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants