Identity & Access · Group creation
One Config, Two Clouds: Group and Role Management as Code
A single Terraform stack defines every security group, its members and its role assignments for both Entra ID and Google Workspace/GCP, and keeps them reconciled.
// Overview
The stack reads one large declarative config describing groups, members and role grants across two clouds. Azure groups are created in Entra ID and given RBAC at management group, subscription, resource group and resource scope. Users are pushed to Google through an Azure-to-Google SCIM sync group; Google groups are created via the Cloud Identity API and granted IAM at organisation, folder, project and billing level. Foundation, service-account and service-principal layers are applied first in a documented order.
// The problem
Access was managed per cloud, by hand or by many small stacks, so membership drifted and onboarding and offboarding were inconsistent between Azure and GCP.
// Flow
- Config changea pull request edits the declarative group, member and role config
- Lint and scanfmt, validate, TFLint and Checkov
- Existence validation gateplan fails early if a referenced user is missing in either directory
- Plandetailed exit code decides whether anything changed
- Gate: changes gateno changes skips apply; a plan error stops the run
- Approvalapply job runs in a protected environment
- Azure groups and RBACgroups, role assignments, eligible (PIM) assignments
- Sync to Googleadd to sync group, trigger SCIM, wait, verify
- Google groups and IAMcreate groups, then org, folder, project and billing roles
- Notifyoptional chat message with a plan summary
// Design decisions & guardrails
- Preconditions validate users at plan time to avoid cryptic apply-time errors; service accounts are excluded from user validation.
- A strict-membership option removes unauthorised members automatically.
- A create=false flag lets the stack manage permissions on pre-existing, imported groups.
- Cached JSON snapshots of the resource hierarchies avoid API rate limits; a large moved-block file preserves state through refactors.
- Honest gap, documented: monitoring for this stack was designed but still commented out.
// Outcome
One reviewed change path for 100+ groups across two clouds from a config of 1,500+ lines.