Tags: Modeling · Automation · Self-host Substrate: bare Terraform + GitHub Actions (greenfield, one stack per entity)
The canonical Terrantula pattern for greenfield multi-tenant SaaS infrastructure. If you're starting a fresh IaC repo and want Terrantula to drive it from day one, this is the layout. It exercises the full cascade: one command creates the entity graph and opens the right PRs in the right dependency order.
Every customer needs a dedicated AWS sub-account, an Argo CD project, a cluster binding, and the
tenant control-plane resources that compose all three. Each lives in its own Terraform stack with
its own state file, and the Tenant stack reads the upstreams via terraform_remote_state — so
it must apply after them.
One OnboardTenant command drives the whole cascade:
create-entity operation creates the Tenant entity (pending).createEntity rules create three more entities — AWSAccount, ArgoProject,
ClusterBinding — plus three relationships from the tenant to each. (4 entities, 3 relationships.)EntityType declares its applier, so four Apply Actions auto-fire: ApplyAWSAccount,
ApplyArgoProject, ApplyClusterBinding, and ApplyTenant.Action.dependsOn gates ordering. The three upstream applies fire immediately, each opening a
PR with one entity's Terraform. ApplyTenant depends on all three; it inspects the graph, sees
the upstreams aren't done, and transitions to blocked.postMergeDispatch fires a repository_dispatch event; one
entity-generic workflow runs terraform apply in that entity's directory and calls back.ApplyTenant, which
opens the tenant PR. Merge → dispatch → apply → callback → Tenant-acme becomes active.One command, the right four PRs in the right order, no human orchestration. Each workflow runs
terraform apply; Terrantula opens the PRs and never applies.
run-demo.sh boots a local stack, applies the blueprint, fires OnboardTenant, and asserts the
cascade graph. Without a real GitHub token the upstream PR opens fail with a 401 (expected); the
cascade-graph assertions still pass — 4 entities, 3 relationships, 4 Apply ActionRuns, and
ApplyTenant reaching blocked.
With real PRs against a fork of customer-iac-repo/:
| File | What it is |
|---|---|
run-demo.sh | The end-to-end runner (local stack + cascade-graph assertions). |
terrantula/blueprint.yaml | 4 EntityTypes + 3 RelationshipTypes + 4 Apply + 4 Deprovision actions + OnboardTenant with cascadeRules. |
customer-iac-repo/README.md | The directory + workflow conventions the customer's repo follows. |
customer-iac-repo/.github/workflows/terrantula-entity-apply.yml | The entity-generic terraform apply workflow (one for the whole fleet). |
customer-iac-repo/infra/_modules/ | Reusable per-entity-type modules (aws-account, argo-project, cluster-binding, tenant). |
applier, dependsOn, and cascade.