Back to Terraform

Google Bootstrap Deep Dive: Billing, APIs and Destruction Boundaries

November 6, 2026 Wasil Zafar 24 min read

Keep folder/org/billing administration outside ordinary service roots through a controlled provider-specific rehearsal

Table of Contents

  1. Separate Project Creation from Application Ownership
  2. Define API Activation and Service-Agent Ownership
  3. Review Disable and Delete Semantics Explicitly
  4. Rehearse an Environment Retirement on Paper First
  5. Verify a Bounded Teardown Without Disabling Shared Services

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.

Separate Project Creation from Application Ownership
%%{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.

Three ownership planes for a Google Cloud bootstrap The organization and two folders grant authority from above. A bootstrap project holds the Terraform state bucket, workload identity pool, deployment service accounts and a project lien, and outlives every workload. A workload project holds APIs, quota, data and its runtime identity, and never owns a shared activation. A billing account at the bottom funds both projects through links, and contains neither. Authority above, money beside, contents below Three planes that are easy to draw as one box and must not be owned as one. Organization: domain, organization policy, inherited grants creates nothing in this design, but every descendant inherits its decisions Folder: platform Folder: workloads PROJECT: PLATFORM-BOOTSTRAP state bucket, versions and lock objects workload identity pool and provider deployment service accounts project lien and prevent policy outlives every workload root PROJECT: APP-PROD APIs, quota, data, runtime identity created by the factory billing linked separately destroyed by its own root never owns a shared activation Billing account: funds both, contains neither a role on the account, not on the folder The factory creates the boundary. A different principal funds it, and a third one operates inside it.
ActIdentity that performs itScope it needsWhat it leaves behind
Create the folderorganization administratorfolder-creator on the parenta folder that inherits organization policy
Create the projectproject factoryproject-creator on the parenta project with no billing link yet
Link billingbilling administratorbilling-user on the accounta funded project, outside folder policy
Enable shared APIsplatform ownerservice-usage admin in the projectactivations every workload depends on
Write statebootstrap runnerobject admin on the bucketthe 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.

Define API Activation and Service-Agent Ownership
%%{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.

ActivationOwnerDestroy settingWhy
Service Usage and Resource Managerseed step, before the rootnot managedneeded before any other activation
Storage for the state bucketbootstrap rootleft enabledevery workload reads the backend
Shared runtime APIsplatform rootleft enabled, record protectedmany projects depend on one activation
Project-local APIsworkload rootleft enabledthe 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.

Four blast radii of one Terraform destroy Four bars compare what a destroy reaches. Deleting a project removes every resource, API and identity inside it and starts a 30-day recovery window. Disabling an API deletes or suspends the resources that service manages. Deleting a service account leaves bindings that no longer resolve. Deleting a state object loses the record unless object versioning kept a copy. A side panel lists what survives the project: the billing account, folder and organization policy, the state bucket in the bootstrap project, and the audit sink. One destroy command, four different blast radii The recovery column is what decides whether a guard is needed. Project every resource, API and identity inside it API disable Cloud Run deleted, GKE suspended then deleted Service account bindings remain, pointing at an identity that is gone State object current state is gone, history only if versioned SURVIVES THE PROJECT billing account but the link detaches folder and organization policy inheritance continues state bucket in bootstrap if it does not live here audit sink in another project if it was designed that way location is the protection not the deletion flag Billing detaches immediately and does not return with a restore. After 30 days the project and everything in it are permanently deleted. Put the recovery record outside the thing being destroyed.
ObjectDestroy requestWhat Google doesWhat recovers it
Projectshutdownbilling detached, 30-day window, then permanentrestore inside the window, then relink billing
Folderdelete if emptyhierarchy entry removed, inheritance endsrecreate and re-grant; children must already be gone
Service, disable offforget the recordAPI stays enabled and keeps servingimport the activation again
Service, disable ondisable callCloud Run resources deleted, GKE suspendedre-enable, then rebuild or wait for clusters
Service accountdeletebindings keep a stale identity referencerecreate and rebuild every binding
State objectdeletecurrent state gone, history only if versionedrestore 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.

A retirement plan crossing a shared spine it does not own The retiring app-prod project holds workloads, project APIs, project IAM, keys and datasets. A shared spine in the centre holds the activation set, the deployment identity and the state bucket. The surviving side holds app-nonprod, the bootstrap root, the audit sink and the DNS zone. Dashed crimson links from the retiring project to the spine mark dependencies that must not be deleted, while solid teal links from the surviving side show the same spine items still in use. The retirement stops at a boundary it does not own Everything in the centre column has a consumer outside the project being removed. RETIRING: APP-PROD workloads and jobs project-level API activations project IAM members service account keys datasets and buckets all of this may go if the inventory agrees the plan is allowed to remove only this column SHARED SPINE activation set deploy identity state bucket owned outside the retirement STILL RUNNING app-nonprod bootstrap root audit log sink shared DNS zone billing budget all of this must work after the destroy returns and none of it appears in the destroy plan × × × Every spine item needs an owner outside the root being destroyed. If it does not have one, the retirement is not ready, however clean the plan looks.

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.

Lab

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.

  1. 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.
  2. 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.
  3. 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.
  4. Plan with the detailed exit code. Expect zero, and record the Terraform and provider versions beside it.
  5. 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.
  6. 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.
  7. 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.
  8. Destroy only the workload root. Expect the workload project to shut down, and expect the bootstrap bucket, lien and shared activations to remain.
  9. 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.
CheckEvidencePass looks like
Seedplan exit codezero, with both versions pinned
Adoptionplan after importno changes and no replacement
Billing separationworkload plancreate succeeds with the billing principal only
Deletion guarddestroy attemptrefusal naming the policy or the lien
Bounded teardownbootstrap plan after workload destroyzero, bucket readable, APIs still enabled
Detach and reattachplan after re-importzero, no replacement
Restoreplan after undelete and relinkdrift 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.