Skip to main content

Terraform Cloud Integration

Badal Foundations uses Terraform Cloud (TFC) as the central hub for infrastructure state management, workspace orchestration, and automated deployments. This guide explains the workspace hierarchy, naming conventions, module registry, and deployment workflows.

TFC Organization

SettingValue
OrganizationBadal_devex
Total workspaces46
VCS providerGitHub (badal-io)
Execution modeRemote (default)

Workspace Naming Conventions

Foundations uses two naming conventions — a newer standard and a legacy format from earlier deployments.

New Convention

{type}-{name}-{env}-{suffix}
ComponentDescriptionExamples
typeResource typebu, data, devex, platform
nameResource namedata, backstage, governance
envEnvironment codec (common), d (dev), np (non-prod), p (prod), ce (cross-env)
suffixRandom 5-char identifier80r13, 9c9dl, mly9n

Examples:

  • bu-data-c-80r13 — Data BU, common/cross-env workspace
  • data-governance-d-f6y39 — Data governance tenant, dev environment
  • devex-backstage-np-mly9n — Backstage tenant, non-prod environment

Legacy Convention

wrkspc-{env}-{domain}-{name}

Examples:

  • wrkspc-ce-bu-devex — DevEx BU, cross-environment
  • wrkspc-np-devex-backstage — Backstage, non-prod
  • wrkspc-p-data-tenant-0001 — Data tenant, prod

Environment Codes

Full NameNew CodeLegacy Code
Common / cross-environmentcce
Developmentdd
Non-productionnpn or np
Productionpp

Workspace Hierarchy

When a Business Unit and its Tenants are created, TFC workspaces are organized in a three-tier hierarchy:

BU Cross-Environment Workspace

  • Purpose: Manages the BU-level resources (folders, WIF, GAR, tenant definitions)
  • VCS: Connected to the BU repository (e.g., bu-data-80r13)
  • Trigger: Runs on merge to main branch
  • Creates: Tenant projects, repos, and per-env workspaces

Shared Workspace

  • Purpose: Manages BU-level shared resources (shared GAR repos, shared configurations)
  • Example: data-shared-c-80r13

Per-Environment Tenant Workspaces

  • Purpose: Deploys the tenant's infrastructure for a specific environment
  • VCS: Connected to the tenant repository
  • Trigger: Branch-based (environment branches) or tag-based (trunk-based), depending on the tenant's branching model
  • Scope: Can only access resources in its designated environment

How Workspaces Are Created Automatically

Workspaces are not created manually. The platform modules handle workspace creation as part of BU and Tenant provisioning:

  1. BU creation (create-business-unit/platform) creates the BU workspace and shared workspace.
  2. Tenant creation (create-tenant/platform) creates per-environment tenant workspaces.

Each workspace is automatically configured with:

  • VCS connection to the appropriate GitHub repository
  • Correct working directory
  • Environment variables (GCP project ID, region, etc.)
  • Terraform variables from the module configuration
  • Appropriate execution mode

VCS Connections and Branch-Based Deployments

VCS-Driven Workspaces

Most workspaces are connected to a GitHub repository and trigger automatically:

EventResult
PR openedSpeculative plan (shows what would change)
PR merged to main/env branchApply run (deploys changes)
Manual triggerOn-demand plan or apply

Branch Mapping

For environment-based branching:

BranchWorkspace Environment
developmentDev workspace
non-productionNon-prod workspace
productionProd workspace
mainCross-env / common workspace

For trunk-based branching:

EventWorkspace Environment
Push to mainDev and/or non-prod
Git tag (v*)Production

Auto-Apply vs Manual Confirm

Workspace TypeAuto-ApplyRationale
Module registryYesRegistry updates should propagate immediately
Dev workspacesConfigurableTeams can choose to auto-apply in dev
Non-prod workspacesConfigurableDepends on team preference
Prod workspacesNo (default)Production changes require manual confirmation

The Module Registry

Repository: devex-terraform-module-registry Workspace: devex-terraform-module-registry (auto-apply, 122 resources)

The TFC private module registry hosts all custom Terraform modules used by Foundations. Key modules:

Platform Modules

ModuleRegistry PathPurpose
create-business-unitapp.terraform.io/Badal_devex/create-business-unit/platformProvisions a complete Business Unit
create-tenantapp.terraform.io/Badal_devex/create-tenant/platformProvisions a Tenant within a BU
business_unit_breakoutapp.terraform.io/Badal_devex/business_unit_breakout/googleBreaks out BU resources into per-env folders

How Modules Are Published

  1. Module source code is maintained in the respective GitHub repository.
  2. The tfc-private-module-registry repo manages the registry configuration.
  3. The devex-terraform-module-registry workspace (auto-apply) keeps the registry in sync.
  4. Modules are versioned semantically — consumers pin to specific versions in their source blocks.

Environment Promotion Path

Infrastructure changes flow through environments in a controlled sequence:

Promotion Strategies

For environment-based branching:

  1. Make changes in the development branch
  2. Verify the dev workspace apply succeeds
  3. Merge development into non-production
  4. Verify the non-prod workspace apply succeeds
  5. Merge non-production into production
  6. Manually confirm the production apply in TFC

For trunk-based branching:

  1. Open a PR against main — speculative plan runs
  2. Merge PR — dev/non-prod workspaces apply
  3. Create a release tag — production workspace triggers
  4. Manually confirm the production apply in TFC

Key Workspaces

Active BU Workspaces

WorkspaceResourcesVCS RepoPurpose
bu-data-c-80r13346bu-data-80r13Data BU (largest)
bu-platform-c-0r4dp199bu-platform-0r4dpPlatform BU
wrkspc-ce-bu-devex149repo-bu-devexDevEx BU (legacy naming)

Infrastructure Workspaces

WorkspaceResourcesPurpose
devex-terraform-module-registry122Module registry (auto-apply)
wrkspc-np-devex-backstage110Backstage non-prod (auto-apply)
gcp-foundations-projects-workspace-managerN/AWorkspace management (no VCS)

Shared Workspaces

WorkspaceBU
data-shared-c-80r13data
devex-shared-c-9c9dldevex
platform-shared-c-0r4dpplatform

Workspace Variables

Common variables set on TFC workspaces:

VariableTypeDescription
TF_VAR_project_idTerraformGCP project ID for this workspace
TF_VAR_regionTerraformPrimary GCP region
GOOGLE_CREDENTIALSEnvironmentService account key or WIF token
TF_VAR_environmentTerraformEnvironment name
TF_VAR_business_unitTerraformParent BU identifier

Troubleshooting

IssueResolution
Workspace stuck in "Planning"Check for state locks. Another run may be in progress. Cancel queued runs if needed.
VCS connection failedVerify the GitHub OAuth token is valid and has access to the repository. Re-authorize in TFC settings if needed.
Module version not foundCheck that the module is published in the registry. Run the devex-terraform-module-registry workspace to sync.
Speculative plan on PR shows no changesEnsure the workspace's VCS working directory matches the Terraform root module path.
Apply fails with permission errorThe service account may lack IAM permissions. Check the WIF configuration and SA bindings.

Next Steps