Platform · Flagship pipeline

From Form to Running Cluster: Self-Service Team Onboarding

A form submission becomes Vault config, cloud subscriptions, a landing zone with Kubernetes, cost-aware autoscaling and a GitOps control plane, with each stage firing the next.

  • Terraform
  • GitHub Actions
  • HashiCorp Vault
  • Azure AKS
  • CAST AI
  • FluxCD
  • Apps Script
  • Python
  • TFLint
  • Checkov

// Why this matters

A self-service team onboarding pipeline is the difference between a platform team that answers tickets and one that ships a product. Every internal team that wants an isolated cloud environment needs the same dozen things: a subscription per environment, a non-overlapping network, a Kubernetes cluster with identities, an autoscaling policy, and a GitOps control plane so deployments are auditable from day one. Built by hand, each of those is a ticket, a wait, and a chance to diverge from the standard.

The engineering motivation is determinism. If a request always produces the same naming, the same defaults and a network block no other team can receive, then support, cost reporting and security review all become tractable. The pipeline below turns a request into data (one CSV), data into configuration (Vault), and configuration into infrastructure (Terraform), with each stage small enough to be re-run on its own.

The business motivation is lead time. The operator docs for this system budget roughly half an hour end to end, replacing what used to be a multi-day manual runbook. The rest of this article shows the wiring so you can reproduce the pattern with your own cloud and your own modules.

// The problem

Hand-building per-team environments fails in predictable ways. Names drift ("team-a-dev" versus "teama-lo"), someone forgets the private cluster flag, two teams get overlapping address space and later cannot be peered, and the autoscaler never gets registered so the cluster runs on expensive on-demand nodes forever. Nothing is wrong at the moment of creation; the damage shows up six months later when you need to peer, audit or tear down.

The second problem is orchestration. A flagship flow like this spans several tools with different failure modes: a form, a script that writes configuration, a Terraform root that depends on subscription ids that did not exist a minute earlier, a second root that registers the cluster with a cost platform, and a third that installs GitOps. If you wire these as one giant workflow with needs: chains, a failure in stage four forces you to re-run stages one to three, and a reviewer approving the plan has no way to approve only the part they care about.

The third problem is honesty about planning. Downstream stages can only plan against state the upstream apply creates, so there is no true end-to-end plan. A design that pretends otherwise gives reviewers false confidence. The pipeline instead makes each stage independently plannable and documents the limitation.

// The solution

The architecture has three layers. At the edge is a form and a small Apps Script that validates and transposes the answers into a two-column CSV, then commits it to a folder in the platform repository. In the middle is Vault, which is the single source of configuration: a Python populator writes standard defaults, team overrides and computed values (see Vault as the Control Plane: A Five-Tier Key Model with Locking). At the bottom are Terraform roots that read everything from Vault and write results back so the next stage can read them.

Stage chaining is the key decision. Stage 0 (the parent workflow) has three jobs that run in order with ordinary needs:: populate Vault, create subscriptions, and call the onboarding workflow natively. From there on, the onboarding Terraform root itself ends with a null_resource that POSTs a workflow_dispatch to the autoscaling workflow, and that workflow's root dispatches the GitOps bootstrap (see Who Deploys the Deployer? Terraform-Bootstrapped FluxCD and One Reusable Plan/Apply Workflow for Cost-Optimised Autoscaling). Chaining through Terraform means a stage fires the next only if its own apply really succeeded, and every stage is a first-class workflow you can dispatch by hand with the same inputs.

Gating is expressed as data. Each downstream stage has a *_required flag in Vault; the dispatch resource only exists if the flag is true, the cluster and network were actually created in this run, a dispatch token is present, and (for GitOps) the cluster is not the HA secondary. A no-op apply never triggers anything, because the reusable workflow converts the plan exit code into a skip flag.

I considered and rejected three alternatives. One monolithic workflow with needs: was rejected for the re-run problem above. A message bus or external orchestrator was rejected as another system to run for what is a linear chain. Terraform Cloud run triggers would work but tie the design to one vendor and lose the per-stage GitHub environment approval. The accepted trade-off is that dispatch from Terraform needs a token with workflow scope, which is stored as a repository secret and never appears in configuration.

How it flows flow1. Form submit → 2. Validate → 3. CSV to Git → 4. Populate Vault → 5. Subscriptions → 6. Onboard → 7. Gate: real apply → 8. Autoscaling → 9. Gate: GitOps flag → 10. GitOps bootstrap01Form submit02Validate03CSV to Git04Populate Vault05Subscriptions06Onboard07 · GATEGate: real apply08Autoscaling09 · GATEGate: GitOps flag10GitOps bootstrap
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. Form submitteam name, short name, environment (lower, upper or both), region, resource checkboxes, HA and mesh mode
  2. ValidateApps Script enforces naming rules and auto-enables dependencies (a cluster implies a VNet)
  3. CSV to Gitresponses become a two-column CSV; a workflow dispatch starts the pipeline
  4. Populate Vaultdefaults, then team overrides, then computed values such as network blocks
  5. SubscriptionsTerraform creates lower and upper subscriptions and stores their ids
  6. Onboardreusable Terraform workflow builds the network, cluster and identities from about 100 config keys
  7. Gate: real apply gatenext stage fires only on a non-empty apply with the right flags set
  8. Autoscalingcluster registered with the cost-optimisation platform
  9. Gate: GitOps flag gatebootstrap runs only if required, a cluster exists and it is not the HA secondary
  10. GitOps bootstrapFlux installed; the cluster reconciles itself from Git
Form/CSVParent workflowOnboarding TFAutoscalingGitOps bootstrapcommit CSV, dispatch with team namepopulate Vault, create subscriptions, call nativedispatch on real apply + flag + tokendispatch if required and not HA secondarybootstrap lock committed; cluster reconciles itself
Stage chaining: who triggers whom. Stage 0 is wired with needs; every later hop is a Terraform-issued dispatch, so each stage is independently re-runnable.
EdgeFormApps Script validatorCSV in GitOrchestrationParent workflowReusable TF workflowProtected environmentsConfigurationVault KV v2Python populatorCIDR ledgerInfrastructureSubscriptionsVNet + AKS + identitiesAutoscaling policyFlux bootstrap
Onboarding architecture layers. Each layer talks only to the one below it; Vault is the contract between data and infrastructure.

// Before you start

  • A GitHub organisation with Actions enabled, a protected environment per cloud environment (lower, upper) with required reviewers, and self-hosted or peered runners if your cluster API is private.
  • A HashiCorp Vault with a KV v2 mount and a CI identity (token or JWT auth) scoped to a path prefix per team.
  • Terraform 1.9+ with a remote state backend, plus TFLint and Checkov in the runner image.
  • Federated cloud auth for CI (OIDC to the cloud, workload identity federation to the state bucket) so no static cloud keys exist.
  • A Google Form and a bound Apps Script project (or any form tool that can call a webhook), and a service-level token that can commit to the repo and dispatch workflows.
  • Working knowledge of Terraform data sources, GitHub reusable workflows (workflow_call) and workflow_dispatch.

// Step-by-step implementation

  1. 01 Define the request contract: a two-column CSV with validation at the edge

    Everything downstream assumes the input is already sane, so validate where the human is: in the form script. The contract is a flat two-column CSV (key,value) because it diffs cleanly in Git, needs no schema migration when you add a field, and can be consumed by a 40-line Python reader. Free-text team names are the main risk, so the script enforces a lowercase, hyphen-safe short name with a length cap that fits your cloud's tightest naming limit (storage account names are usually the constraint).

    The other thing the edge script does is dependency expansion. If someone ticks "Kubernetes cluster" but not "virtual network", the script ticks the network for them, because a cluster without a network is never what anyone wants and would otherwise fail much later. Doing this in the form script keeps the dependency logic in one place and visible in review.

  2. 02 Write the parent workflow: populate, subscribe, trigger

    The parent workflow is deliberately boring. Three jobs, ordinary needs:, and a concurrency group keyed on the team so two runs for the same team queue instead of racing on Vault. cancel-in-progress is false because cancelling a half-finished apply is how you get orphaned resources.

    Note two details. The populate job always runs, even on a Plan, because later stages read what it wrote; it is idempotent by design. And the subscription job passes the environment input straight through, because the subscription state holds both environments of a team in a single state file (see Subscription Factory: Customer Onboarding That Starts by Minting Subscriptions for why that matters when someone dispatches only one environment).

  3. 03 Allocate network space from a ledger, never from a form

    Two teams must never receive the same address block, and that cannot be guaranteed by asking people to pick one. The populator allocates from a pre-seeded JSON ledger committed to the repository: a list of non-overlapping VNet, service and pod ranges, each with an available flag. Allocation takes the first free entry, flips it to used, and records who and when.

    Make allocation idempotent by keying reuse on the planned network name. If the pipeline is re-run after a partial failure, it finds the entry already assigned to that name and reuses it rather than burning a second block. The ledger change is committed through an auto-merged pull request so the history shows every allocation and a concurrent run cannot silently overwrite another.

  4. 04 Build the reusable Terraform workflow with a plan exit-code gate

    One reusable workflow serves every stage. It has a plan job and a gated apply job, and the plan job is where all the safety lives: format, init, validate, lint, scan, then terraform plan -detailed-exitcode -out=plan. The exit code is translated into three outcomes: 0 means no changes (skip apply and, importantly, do not trigger the next stage), 1 means error (fail), 2 means changes (apply).

    Applying the saved plan file, not re-planning, guarantees that what the reviewer saw is what runs. The plan is uploaded as an artifact and rendered to a markdown summary so the approval in the protected environment is an informed one.

  5. 05 Read all configuration from Vault, with required keys failing loudly

    The onboarding Terraform root has no team-specific defaults in code. One data source lists the team's secrets, a second reads each one, and a locals block decodes by type. Required keys are read bare so a missing key fails the plan with a clear error; optional keys use try() with a documented default.

    This is what makes the pipeline reproducible: the same root builds any team because the team is entirely data. The full tier model is in Vault as the Control Plane: A Five-Tier Key Model with Locking.

  6. 06 Chain stages with a Terraform dispatch resource and explicit gates

    At the end of the onboarding root, a null_resource with a local-exec provisioner POSTs a workflow_dispatch for the next stage. The resource only exists when count evaluates to 1, which encodes the gate: flag set, cluster and network exist in this configuration, and a token was supplied. Because it lives in the same apply, it runs only after the cluster module succeeded (depends_on), and on_failure = fail makes a broken dispatch fail the stage rather than silently stop the chain.

    A no-op apply creates or changes nothing, so the provisioner never re-fires: the plan-exit-code gate and the null_resource gate compose. For HA, a second resource dispatches the secondary with an is_secondary input, which is also how the GitOps stage knows not to run twice.

  7. 07 Bind applies to protected environments and write results back to Vault

    Approval belongs in the platform, not in a chat message. Create one GitHub environment per cloud environment, require reviewers on the upper one, and reference it from the plan and apply jobs. The reviewer sees the rendered plan artifact and approves exactly that plan. Lower environments can auto-apply; upper must not.

    The last piece is write-back. After apply, Terraform stores the ids later stages need (cluster name, resource group, identity client ids, subnet id) as Vault keys with a stable suffix. This is how stage 2 and 3 learn about stage 1 without passing outputs through workflow inputs, and it is why re-running any stage on its own works.

  8. 08 Add the safety rails: lint, scan, concurrency and the golden rules

    Two cheap rails pay for themselves quickly. First, run TFLint and Checkov in the plan job and upload their JSON as artifacts, even if you start by not failing on findings; the history tells you what to tighten. Second, write the golden rules down where operators will read them and enforce them by construction: read before write, plan before apply, never apply from a laptop (the runner identity is the only one with write permission), and update the docs in the same change.

    Finally, give every stage its own concurrency group keyed on team, environment and state suffix. That, plus cancel-in-progress: false, lets you re-dispatch a failed stage at any time without a race.

// How to verify it works

  • Dispatch the parent with action Plan for a throwaway team. Expected: populate-vault succeeds and writes keys, the subscription plan shows two creates, and nothing is applied.
  • vault kv get -field=value PLATFORM/Lower/Teams/<team>-lower/vnet_cidr returns the block taken from the ledger, and the ledger diff in Git shows exactly one entry flipped to available: 0.
  • Re-run the same dispatch. Expected: the populator reuses the same block (no second allocation) and the onboarding plan exits 0, so the apply job and the dispatch are both skipped.
  • After a real Plan & Apply, gh run list --workflow autoscaling.yml shows a new run started by the onboarding apply, and later the bootstrap workflow starts from it.
  • Dispatch the autoscaling workflow by hand with the same inputs. Expected: it works standalone, proving each stage can be re-run without the one before it.

// Design decisions and trade-offs

  • Stages are chained by Terraform dispatching the next workflow, not by job dependencies, so a failed stage stops the chain and can be re-run alone.
  • Every stage takes Plan or Plan and Apply; applies are bound to a protected environment where required reviewers are the real approval gate.
  • Terraform reads all configuration from Vault with no hardcoded defaults for required values: a missing key fails the plan loudly.
  • Network ranges are allocated through an auto-merged pull request so two teams can never receive the same block.
  • Per-team concurrency groups prevent overlapping runs; subscriptions for both environments live in one state.
  • Golden rules in the operator guide: read before write, plan before apply, never apply from a laptop, update docs in the same change.
  • Honest limitation, documented: there is no true end-to-end plan, because downstream stages can only plan against state the upstream apply creates.

// Pitfalls and lessons learned

  • Using needs: for the whole chain. A stage-four failure then forces a re-run of everything and an approver cannot approve only part of the flow.
  • curl without --fail in the dispatch provisioner. A 401 from an expired token prints JSON and exits 0, so the chain silently stops and the stage looks green.
  • Dispatching on every apply. Without the plan exit-code gate and the count gate, a no-op re-run re-triggers downstream stages and can re-register or re-bootstrap a cluster.
  • Letting the form compute anything. Network blocks typed by humans will eventually collide; allocate from a ledger inside the pipeline.
  • Cancelling in-progress runs. A cancelled apply leaves partial state; set cancel-in-progress: false and let the queue serialise.
  • Assuming an end-to-end plan exists. Downstream roots depend on state the upstream apply creates; plan each stage when its predecessor has applied and say so in the docs.
  • Defaulting required values in Terraform. A silent default produces a cluster with the wrong size rather than a failed plan; read required keys bare.

// Frequently asked questions

How do I build a self-service team onboarding pipeline with GitHub Actions and Terraform?

Collect a small validated input (a form that commits a CSV), write it to a config store such as Vault, and have a parent workflow call reusable Terraform workflows. Chain later stages with workflow_dispatch from Terraform, gate every hop on a real apply, and bind applies to protected environments.

Why dispatch the next workflow from Terraform instead of using needs?

It lets each stage be an independent workflow that can be re-run alone, and it only fires after the previous stage genuinely applied something. A failed stage simply stops the chain; nothing earlier re-runs.

How do you stop two teams getting the same CIDR range?

Allocate from a pre-seeded ledger inside the pipeline: take the first free block, mark it used, and commit the change through an auto-merged pull request so allocations are serialised and auditable.

Can the whole chain be planned before applying?

No, and it is better to say so. Later roots need ids that only exist after the earlier apply, so each stage is planned and approved on its own.

Where do secrets live in this design?

Never in the repository or workflow files. Cloud access uses OIDC federation, configuration lives in Vault, and the only long-lived credential is the dispatch token stored as a repository secret.

// The outcome

Six stages, about 100 config keys read and about 73 result keys written back per environment, replacing a multi-day manual runbook.

// Where to take it next

// Keep reading