Separate Project Creation from Application Ownership
A bootstrap root is a factory, not a home. It creates the folder, the project, the state bucket and the identities that later roots will use, then hands them to a long-lived owner. Workload roots live inside the result, and an ordinary application deploy should never need the factory's credentials.
Four acts are usually bundled into one pipeline, and each belongs to a different principal. Creating a folder needs folder-creator rights on the parent, creating a project needs project-creator rights, linking billing needs a role on the billing account, and enabling a shared API needs service-usage rights in the target project. One credential holding all four can create, fund and reconfigure anything it can reach.
Billing is a relationship, not a container. The billing account sits outside the resource hierarchy and is linked to each project separately. Deleting a project disconnects that link immediately, and restoring the project does not restore it, so the link is an edge to re-establish rather than a property that comes back with the resource.
Folders inherit, projects isolate. A policy granted on a folder reaches every descendant project, while quotas, API activations and cost lines stay per project. Treat a change of parent as a migration with its own review, not as an in-place edit of a label.
The bootstrap project is the only one that must outlive every workload. It owns the state bucket, the workload identity pool, the deployment service accounts and the audit sink. Give it a lien, a deletion policy that refuses destroy, and an owner who is neither the factory nor the application pipeline.
Break the backend circle before the first remote plan. The bucket named in the backend block cannot be created by the configuration that needs that bucket to initialize. Google's state tutorial initializes with a local backend, applies the bucket, adds the backend, then migrates state; that is the supported shape, and it keeps the first apply auditable.
Adopt the seed; do not re-create it. A project that already exists enters state through an import block, and the plan after the import must be empty. A plan that proposes to create a project you can already see is the signal that adoption was skipped.
Figure 1 draws the four acts as separate edges, including the two that are not containment.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
OA["Organization administrator
folder and project creation"] -->|"creates"| F["Folder: platform
created once"]
OA -->|"creates"| P["Project: platform-bootstrap
created once"]
F -->|"contains"| P
BA["Billing administrator
separate role"] -.->|"billing user link"| P
P --> S["State bucket and WIF pool
seeded with local state"]
S -.->|"remote backend"| W["Workload projects
app-prod, app-nonprod"]
BA -.->|"links each workload too"| W
OP["Organization policy
inherits downward"] -.-> P
OP -.-> W
L["Project lien
blocks deletion"] -.-> P
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class OA,OP primary;
class F,W secondary;
class P,S ok;
class BA,L warn;
Read the dashed edges as the ones that need their own approval. Billing links and state dependencies cross the hierarchy without being contained by it, so neither is protected by folder policy. That is why they are the first things to place under a named owner.
Figure 2 turns the same split into three planes: the hierarchy that grants authority, the billing relationship that funds it, and the project contents that actually change.
| Act | Identity that performs it | Scope it needs | What it leaves behind |
|---|---|---|---|
| Create the folder | organization administrator | folder-creator on the parent | a folder that inherits organization policy |
| Create the project | project factory | project-creator on the parent | a project with no billing link yet |
| Link billing | billing administrator | billing-user on the account | a funded project, outside folder policy |
| Enable shared APIs | platform owner | service-usage admin in the project | activations every workload depends on |
| Write state | bootstrap runner | object admin on the bucket | the recovery record itself |
The table is a grant review, not a job description. If one row shares an identity with another, that identity can complete both acts in a single session. Review the rows for overlap before reviewing the role names.
Define API Activation and Service-Agent Ownership
Enabling an API is three events, not one. Service Usage accepts the request and returns an operation, the provider waits for that operation, and Google then creates the service agent and starts IAM propagation. A green apply proves the first two; it does not prove that the agent exists or that a grant to it is effective.
The first activation is a genuine chicken-and-egg problem. Terraform enables services through the Service Usage API, so Service Usage must already be enabled in the project before Terraform can enable anything else there. A new project arrives with a default set that you should read rather than assume. Make the seed activation an explicit step with its own evidence, run before the first root that manages APIs.
Default network creation is the other surprise in the create call. The provider's network flag defaults to true, and setting it false still lets Google create the network and then deletes it through the Compute API, which leaves that API enabled. An organization policy constraint avoids the round trip altogether.
Service agents are identities with their own allow policies. The Google APIs service agent appears with the project, while per-service agents appear when their API is enabled. Both can hold roles, both appear in audit logs, and both are invisible to a plan that only counts Terraform resources.
Not every agent is Terraform's to remove. The service-identity resource is beta-only and create-only: update and destroy are no-ops. Destroying it removes a state entry, not the agent, so a root that "cleans up" agents is usually just hiding them from the next reader.
Dependency ordering does not model propagation. A dependency edge orders the API calls; it does not wait for policy propagation or for an agent to become visible to the next service. Retry the first real call with a bounded backoff instead of sleeping for a fixed minute count.
The activation list needs one long-lived owner. Shared runtime APIs belong to the platform root, with state in the bootstrap bucket and a review that names the service owner. Workload roots consume the project and never declare the shared APIs, because a workload destroy must not be able to disable a dependency another team is using.
Figure 3 keeps each failure attached to the layer that produces it.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
P["Project created
billing linked"] --> Q{"Service Usage already
enabled in the project?"}
Q -->|"no"| X1["Enable fails
seed step missing"]
Q -->|"yes"| E["Activation resource
one service per object"]
E --> L["Long-running operation
provider waits"]
L --> A["API enabled
service agent exists"]
A --> G{"Agent granted
the role it needs?"}
G -->|"no"| X2["Workload call denied
activation looked green"]
G -->|"yes"| W["Workload can call the API"]
W --> D{"Destroy the root with
disable on destroy set?"}
D -->|"yes"| X3["API disabled
resources deleted or suspended"]
D -->|"no"| K["Activation outlives the root"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class P primary;
class Q,G,D secondary;
class E,L,A,W,K ok;
class X1,X2,X3 danger;
The left branch looks like a configuration bug and is not. If the enable call fails because Service Usage is off, no amount of retry or role widening helps; the project needs a seed step that runs outside the root.
The destroy branch is the ownership question in miniature. Leaving the activation enabled on destroy is the correct default for anything shared, and the provider already behaves that way unless a module sets the flag. Audit the module rather than trusting the intent in its README.
| Activation | Owner | Destroy setting | Why |
|---|---|---|---|
| Service Usage and Resource Manager | seed step, before the root | not managed | needed before any other activation |
| Storage for the state bucket | bootstrap root | left enabled | every workload reads the backend |
| Shared runtime APIs | platform root | left enabled, record protected | many projects depend on one activation |
| Project-local APIs | workload root | left enabled | the project is the boundary that ends them |
A worked example keeps the rule concrete. The state bucket's Storage API belongs to the bootstrap root and stays on, because every workload root reads that bucket through its backend. A single-service API used by one Cloud Run workload can be enabled in that workload root, because the project itself is what eventually removes it.
Review Disable and Delete Semantics Explicitly
A Terraform destroy is a request, and Google decides what it means. The provider sends the delete call that the resource supports, then waits. What happens next depends on the object: a project enters a shutdown window, an API disable cascades into the resources it serves, and an identity disappears while its bindings remain.
Project deletion is a 30-day state, not an instant. The project stops billing and becomes unusable immediately, and its billing link is disconnected; it stays recoverable for 30 days and is then permanently deleted. Some services, including Cloud Storage and Pub/Sub, can remove data sooner, so the window is not a data-retention guarantee.
The provider already refuses to delete a project by default. In hashicorp/google 8.10.0 the deletion policy defaults to prevent, so a destroy that would remove a project fails until someone changes the configuration. That default is a seatbelt, not a lock: a console or CLI delete is unaffected.
Folders carry their own protection. The folder resource also protects against destroy by default, and a folder can only be removed once it is empty. A parent folder holding one forgotten project is therefore a deletion that fails at the last step, after the rest of the retirement has already run.
API disable is the sharp edge. Disabling the Cloud Run API deletes the Cloud Run resources in the project, and disabling the Kubernetes Engine API suspends clusters, which are deleted after 30 days and can take up to 24 hours to reinstate after re-enable. A disable also fails when an enabled service depends on the target, unless dependent disabling is explicitly allowed.
Liens are boundaries you may not have created. Google applies liens automatically in some cross-project relationships, such as attaching a service account owned by another project, and anyone with the lien-modifier role can add more. List them before planning a deletion; an inherited lien turns a clean destroy into a permission puzzle at the end.
State and keys disappear on their own clocks. Deleting a service account leaves bindings that name an identity which no longer resolves, and recreating it produces a new unique ID, so every grant must be rebuilt. Key destruction is scheduled rather than immediate, and a bucket object survives only if versioning kept a copy.
Figure 4 stacks the four blast radii so the smallest one is not mistaken for the whole.
| Object | Destroy request | What Google does | What recovers it |
|---|---|---|---|
| Project | shutdown | billing detached, 30-day window, then permanent | restore inside the window, then relink billing |
| Folder | delete if empty | hierarchy entry removed, inheritance ends | recreate and re-grant; children must already be gone |
| Service, disable off | forget the record | API stays enabled and keeps serving | import the activation again |
| Service, disable on | disable call | Cloud Run resources deleted, GKE suspended | re-enable, then rebuild or wait for clusters |
| Service account | delete | bindings keep a stale identity reference | recreate and rebuild every binding |
| State object | delete | current state gone, history only if versioned | restore a noncurrent object version |
The table is read from the recovery column outward. If that column offers nothing durable, the object needs a prevent policy, a lien, or a copy outside the project before the first apply ever runs.
A detached project is riskier than a deleted one in the short term. Removing the resource from state without destroying it leaves a live project, a live billing link and no owner in the plan; the next team to import it inherits an unknown configuration. Use a removed block that sets destroy to false, then import it back in a reviewed change, and never leave it detached across a release.
Rehearse an Environment Retirement on Paper First
Retirement is an inventory exercise that ends in a destroy command. The command is the easy part; the inventory decides whether it is safe. Write the inventory before the plan, and make every row name an owner who is not the root being retired.
Start with what Terraform never created. Auto-applied liens, Google-managed service agents, the default network, console-made buckets, budget alerts, DNS delegations, log sinks in another project and any Marketplace subscription are all outside the state file. None of them appear in a destroy plan, and several of them can block it.
Then trace the IAM that reaches in from above. Organization and folder grants survive the project, group memberships change on their own schedule, and a conditional binding next to an unconditional one grants more than its expression suggests. A retirement that only removes project-level members leaves every inherited path intact.
APIs are shared by dependency, not by intent. Two projects can depend on the same activation without either team knowing. The inventory asks which enabled services have dependents, which agents are used across projects, and whether disabling anything would break a consumer that is not in the room.
Data retention has a longer clock than the resource. Bucket retention policies, dataset default table lifetimes, database backups and message retention all outlive the object that created them. A project shutdown can also destroy data sooner than the 30-day window suggests, so export obligations belong in the plan rather than in the cleanup notes.
Write the stop order, not just the list. Freeze writers, export state and policy, remove DNS or traffic, drain queues, delete workload resources, delete the project, then wait and verify. The bootstrap project, its bucket and the shared activations never appear in that sequence, and that absence is the point.
The rehearsal passes only when every shared item has a surviving owner and a check. An unknown dependency is a no-go, not a note for later. The review is cheap; discovering the dependency during the destroy is not.
Figure 5 places the shared spine between the project being retired and the projects that must keep working.
The centre column should be short enough to review in one sitting. A shared dependency list that fills a page is not shared; it is a sign that the boundary was drawn in the wrong place. Three entries cover most platforms: the activation set, the deployment identity and the state bucket.
Verify a Bounded Teardown Without Disabling Shared Services
The lab proves three properties: the seed is reproducible, the plan is empty, and the teardown is bounded. None of them is "the apply succeeded". Run it in a disposable organization or folder with Terraform 1.17.1 and hashicorp/google 8.10.0; the pins are part of the evidence because defaults move between releases.
The no-change plan is the control that makes everything else meaningful. After the seed and the import, a plan with the detailed exit code must return zero. A return of two means drift, and a return of one means the plan itself failed; neither is evidence of a working bootstrap.
Test teardown on a workload, never on the bootstrap. Create one disposable workload project, retire it, and confirm the bootstrap still plans cleanly and the shared APIs still serve the surviving project. A teardown that removes the thing you are measuring from proves nothing.
Test recovery by detaching before deleting. Remove the workload project from configuration without destroying it, plan, then import it back and require an empty plan. Then delete a second disposable project, restore it inside the window, relink billing and reconcile the state entry; that sequence rehearses the two failures that actually happen.
Keep the evidence sanitized and specific. Credential type, project suffix, provider versions, plan exit codes, the remaining-dependency inventory and the recovery transcript together reproduce the decision without publishing an identity or a full project ID.
Verify a Bounded Teardown Without Disabling Shared Services
Execution status: design-only. None of these steps were run against a live organization for this article, and none of the identifiers below are real. The sequence is written to be executed and recorded, not quoted as a transcript.
Prerequisites. A disposable folder under an organization, one billing account you may link, Terraform 1.17.1 with hashicorp/google 8.10.0, gcloud signed in, and four distinct principals: organization administrator, billing administrator, bootstrap runner and workload runner. Cost is close to zero: one small project, one bucket and a handful of API calls.
Setup. Two roots. The seed root uses local state and creates the folder, a minimal project and the state bucket. The bootstrap root adopts them through import blocks and switches to the remote backend. The workload root consumes the project and owns no shared activation.
- Record the four principals and their roles outside the repository. The lab fails if one principal can perform two of the acts in the ownership table.
- Seed with local state: create the folder, the project and one versioned bucket with uniform access. Set the project's deletion policy to prevent and add a lien.
- Confirm the provider can read the project, then add the backend block and migrate state. Expect the state object in the bucket and no change to the project.
- Plan with the detailed exit code. Expect zero, and record the Terraform and provider versions beside it.
- Detach the project with a removed block that sets destroy to false, plan, then import it back. Expect the plan after the import to be empty.
- Create one workload project through the factory. Link billing with the billing principal, not the factory. Expect the workload plan to add only the project and its local resources.
- Attempt to destroy the bootstrap project. Expect the deletion policy to refuse; then, in a scratch copy, remove the lien and expect the destroy to reach Google and stop on the policy instead.
- Destroy only the workload root. Expect the workload project to shut down, and expect the bootstrap bucket, lien and shared activations to remain.
- Delete a second disposable project, restore it inside the window, relink billing and import it. Expect a plan that reports drift until the relink, then an empty plan.
| Check | Evidence | Pass looks like |
|---|---|---|
| Seed | plan exit code | zero, with both versions pinned |
| Adoption | plan after import | no changes and no replacement |
| Billing separation | workload plan | create succeeds with the billing principal only |
| Deletion guard | destroy attempt | refusal naming the policy or the lien |
| Bounded teardown | bootstrap plan after workload destroy | zero, bucket readable, APIs still enabled |
| Detach and reattach | plan after re-import | zero, no replacement |
| Restore | plan after undelete and relink | drift cleared, no duplicate project |
Expected observation. The seed produces a readable project and a state object, every adoption plan is empty, the workload destroy changes only the workload project, and the bootstrap plan stays at zero throughout.
Failure checks. A seed that needs the API it is enabling is a circular dependency, not a permission bug. A destroy that fails on a lien means the inventory missed an absence. A plan that wants to replace the project after a restore means the state entry was recreated instead of imported.
Cost dimensions. One small project, one bucket with a few object versions and a short-lived second project; the API calls are negligible. Leaving the second project undeleted is the only realistic charge.
Cleanup. Destroy the workload roots, then the bootstrap root with deletion allowed, then remove the lien and the folder last. Confirm the billing account shows no linked projects and that the bucket's retained versions were deleted deliberately.
The seed transcript is the deliverable, not a screenshot of a green apply. It shows which principal created which boundary, which API had to exist before the root could run, and which recovery step actually returned the project. Keep it with the remaining-dependency inventory so the next reader can repeat the result instead of trusting it.