Map Organization, Folder, Project and Billing Ownership
Google Cloud has four ownership layers, and only one of them is a workload boundary. An organization is the domain. Folders group projects for inherited policy. A project is where APIs, quotas, billing and IAM meet. A billing account pays for projects but sits outside the resource hierarchy, and it can be linked to only one organization at a time.
The organization is a domain, not something Terraform creates. It appears when a Cloud Identity or Workspace domain is enrolled, and the provider can only read it. Every folder and project below inherits organization policy and organization-level IAM, so a grant made there reaches workloads nobody remembered to scope.
Folders carry inheritance, not isolation. A folder takes a display name and a parent of either an organization or another folder. IAM and policy granted at that level flow down to every descendant project, but two projects in the same folder still have separate quotas, separate APIs and separate cost lines.
The project is the boundary that changes behaviour. It owns API enablement, quota, billing, labels, the default network and the identity namespace for service accounts. Its identifier is globally unique and immutable, while its project number is what many API resource names carry.
Billing is attached, not inherited. A project with no billing account can exist, hold IAM and enable a few free APIs; it simply cannot create billable resources. Linking the account needs a role on the billing account itself, so a project owner without that grant still cannot finish the setup.
Keep bootstrap in its own project under its own folder. The state bucket, the workload identity pool, the deployment service accounts and any KMS keys belong to an administrative root. The application pipeline can then read that root without holding permission to delete the bucket or rewrite the identity that runs it.
Three separations make the layout defensible. Bootstrap identity writes state and IAM. Workload identity reads state and writes application resources. Organization policy and billing stop either identity from leaving the intended envelope, even after a mistaken apply.
%%{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
ORG["Organization
Cloud Identity or Workspace domain
org policy and org IAM"] --> FB["Folder: bootstrap
state, deploy identities, keys"]
ORG --> FW["Folder: workloads
environment policy"]
FB --> PB["Project: platform-bootstrap
state bucket, WIF pool
deploy service accounts"]
FW --> PP["Project: app-prod
APIs, quotas, workloads"]
FW --> PN["Project: app-nonprod
same shape, lower quota"]
B["Billing account
payment method and budgets"] -.->|"linked per project"| PB
B -.->|"linked per project"| PP
B -.->|"linked per project"| PN
ORG -.->|"policy inherits downward"| PP
PB -.->|"state and identity outlive the app"| PP
DEL["Project deletion
removes objects Terraform never created"] -.->|"irreversible after recovery window"| PP
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 ORG primary;
class FB,FW secondary;
class PB,PP,PN ok;
class B warn;
class DEL danger;
Figure 1 draws containment downward and billing across. The dashed edges are the ones that surprise people: the billing account funds projects it does not contain, and the bootstrap project's state and identity outlive every application project that depends on them.
Organization policy is the backstop that survives a rushed pull request. Two constraints earn their place early: one blocks service-account key creation, the other skips the default network on new projects. Both remove a decision that otherwise gets made by whoever runs the first apply.
Authenticate Terraform Through ADC
Application Default Credentials are a lookup, not a login. When the provider has no explicit credential, it asks the Google client libraries for default credentials, which check the credentials-file variable, then the gcloud ADC file, then the metadata server of the machine. Whichever answers first wins, and nothing verifies that it was the one you meant.
The two gcloud commands are easy to confuse. gcloud auth login signs the CLI in; gcloud auth application-default login writes ADC. The first is invisible to Terraform, and the second is what a local plan actually consumes.
A gcloud login therefore proves nothing about Terraform. A laptop can show an active account and a configured project while the provider reads an older ADC file written by a different account months ago. The CLI state and the provider's credential are separate, and only one of them appears in the audit log of the API call.
User ADC carries a Google-owned quota project. Credentials created by the application-default login are user credentials, not project credentials, so quota is charged to a project Google owns rather than yours. The provider documentation recommends turning on the quota override for exactly this case, because some APIs reject a quota project the caller does not own.
Service-account credentials carry their own project. A key or an attached service account is associated with the project that owns it, so quota lands there by default. That is convenient and misleading: the quota project is not the target project, and the target still has to be named.
Impersonation swaps the identity, not the project. Setting the impersonation argument makes the provider mint tokens for a target service account from the base ADC. The base principal needs the token-creator role on that account, and the target service account needs the actual resource permissions. The project argument is untouched by either grant.
Impersonation is the best default for a human-run pipeline. There is no key on disk, the audit log names the service account rather than a person, and revoking one IAM grant ends access. The application-default login can even write an impersonated credential file, which keeps the local workflow identical to the automated one.
Federation is the same idea for an external runner. A workload identity pool trusts an external OIDC issuer, a provider maps claims into attributes, and an attribute condition pins which repository, branch or environment may exchange a token. The runner points the credentials variable at a generated config file, and the provider treats it as ordinary ADC.
A key file is a password that never expires. It survives offboarding, laptop loss and repository leaks, and it is the one option that puts a long-lived secret in the runner. Organization policy can refuse to create them, which is a better control than a review comment.
Short-lived tokens have a clock. Supplying an access token directly bypasses the ADC lookup but gives the provider a static value with roughly an hour of life. A plan that runs longer than that fails mid-apply, after some resources already changed.
%%{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
S["terraform plan starts"] --> Q{"What did the provider receive?"}
Q -->|"credentials argument or file variable"| K["Key or external account file
configuration read at startup"]
Q -->|"access_token"| T["Static bearer token
no refresh during apply"]
Q -->|"impersonation argument"| I["Base ADC mints a token
for the target service account"]
Q -->|"nothing set"| A["Application Default Credentials"]
A --> A1["Credentials file variable"]
A --> A2["gcloud ADC file
user or impersonated"]
A --> A3["Metadata server
attached service account"]
A1 --> V{"Usable credential found?"}
A2 --> V
A3 --> V
V -->|no| X1["Could not find default credentials
plan stops before any API call"]
V -->|yes| C["Token minted for cloud-platform scope"]
K --> C
T --> C
I --> C
C --> P{"Target project readable?"}
P -->|"403 permission denied"| X2["No role on the project"]
P -->|"403 service disabled"| X3["API not enabled in that project"]
P -->|yes| OK["Provider configures
plan continues"]
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 S primary;
class Q,A,V,P secondary;
class K,T,I,A1,A2,A3,C,OK ok;
class X1,X2,X3 danger;
Figure 3 ends at the project read because that is where identity stops and authorization begins. The same token that lists one project returns a denial on another, and the message rarely says which of the two failures you hit. A missing role and a disabled API both arrive as a refusal from the same endpoint.
Verify Project and Quota Context for Every Alias
An alias is a project, a region and an identity, not just a name. Name aliases for the environment and the project role, pass them into child modules, and never let a module build a provider from environment variables the caller cannot see. A module that declares its own provider block cannot be repointed by the root.
The resource argument beats the provider argument, and the provider beats the environment. Resolution runs from the most local setting outward, so an explicit project on one resource silently overrides a default that was reviewed. That is useful for a shared DNS zone and dangerous when it happens by accident.
Environment fallback is a chain you should not rely on. Four variable names are consulted in order, and the first one set wins. Only the provider argument appears in the configuration review, so set the argument and treat the variables as a local convenience.
Region and zone follow the same pattern one level down. The provider sets defaults, a resource can override them for one object, and environment variables fill the gap when neither is present. A bucket is global, a subnet is regional, an instance is zonal, and the argument names differ accordingly.
Not every resource accepts a project override. Some derive it from a parent reference, some take a full resource path, and a few are global. Read the argument list for the resource in front of you; the absence of a project field is not permission to assume the provider default is harmless.
API enablement belongs to the project, not the provider. One service resource switches on one API, and its default destroy behaviour switches that API off again. If another stack still uses the API, that default turns a routine destroy into someone else's outage.
Enablement is eventually consistent. A successful apply does not mean the next request succeeds; the first call can return a permission-style error that carries an activation link. Dependency ordering controls when Terraform sends requests, not when Google finishes propagating the change.
Quota is per project, per region and per service. A plan that succeeds in one region can fail in another for a quota nobody requested, and a closed billing account fails differently from one that was never linked. Read the error text before changing the configuration.
The quota override is a switch with a permission attached. When it is true, the provider sends the billing project as the quota project on requests that support the header. The caller then needs the use permission on that project, or a quota warning becomes a hard denial.
Prefer the additive IAM resource. A member resource adds one principal to one role and leaves other members alone. The binding and policy variants own the entire role, so a stack that uses them will remove principals another stack added.
Pin Google and Google-Beta Deliberately
Two providers, one API surface, two release contracts. The GA provider ships generally available features. The beta provider ships preview features with no SLA and no deprecation policy, against the same endpoints and the same credentials. Sharing a credential is not sharing a guarantee.
Pin both to the same exact version. In the 8.x line the two releases share a version number, so one block can pin 8.10.0 twice. A range lets the Registry resolve a different binary for each provider, which is how a field appears in one plan and vanishes from the next.
Declare the provider on every resource that needs beta. Provider selection is by name, not by feature detection. A resource with no provider argument goes to the default GA instance even when a beta block exists in the same directory.
The beta block does not inherit the GA block's project or region. The two provider configurations are resolved independently from arguments and environment. Duplicate the values, or pass both providers into a module that declares both configuration aliases.
One object, one writer. A cluster, a bucket or a network exists once in the API. If two resources manage it, one through each provider, every apply writes its own schema view and the other reports drift on the next plan. The graph orders dependencies; it does not enforce exclusive ownership.
Move the whole resource, not one field. When a beta-only field is required, set that resource's provider to beta and leave the rest on GA. Keeping a second resource for the same object to obtain one field creates the revert loop the previous paragraph describes, and the switch itself can force a replacement on the first plan.
Beta upgrades are not patch releases. A minor version can change a beta schema, and the plan after an upgrade can propose a replacement for a resource that has not changed in your configuration. Pin the version, read the beta changelog before moving, and rehearse the upgrade in the non-production project.
| Question | hashicorp/google | hashicorp/google-beta |
|---|---|---|
| API surface | generally available features only | preview features, no SLA or deprecation policy |
| Version in this build | 8.10.0 | 8.10.0 |
| State entry | the GA provider owns the object in state | the same type name, owned by the beta provider |
| Choose it when | the resource and its fields are GA, which is almost always | exactly one resource needs a beta-only field |
| Mixing cost | a second writer on an object causes a permanent diff | the same, plus schema changes on minor upgrades |
The table is an ownership contract, not a feature list. A resource may appear in only one column for a given object. When a beta field graduates to GA, move the resource back in a dedicated change, not during a feature release.
Escalate to beta by exception, not by default. Every beta-only field is outside the GA contract, so the count of resources pinned to beta belongs in the review. A directory where everything uses beta has quietly opted out of the stable surface.
Prove the Caller and Project Before Creating Resources
The Google provider ships no account guard, so the configuration must be one. The client-config data source reports what the provider actually resolved: project, region, zone and a token. Comparing those values with your intent is the cheapest check that an alias points where you believe it does.
Read the resolved values, not the shell's. The gcloud configured project describes the CLI, not the provider. A pipeline can carry the right CLI project and the wrong provider project, and the plan is the first place that difference becomes visible.
Keep the token out of outputs. The data source stores the access token in state, and a sensitive output still writes it into the same state and into any saved plan. Output the project and region; never output the token.
A precondition is a gate, a check block is advice. A check block reports a warning and still exits zero, which is fine for hygiene and useless as a control. A precondition on a resource that creates nothing remote fails the plan with your own message before the first create.
Authorization needs a read, not just a token. Reading the target project through the same alias proves the identity can see it. A valid token with no role returns a denial at that read, which is the earliest honest failure and the one a reviewer can reproduce.
Prove the override as well as the default. A resource that sets its own project must be checked against the same expected value, or a guard on the default instance proves nothing about the object that changes. The assertion has to travel with the resource, not with the provider.
Prove the Caller and Project Before Creating Resources
Status: design-only. No Google Cloud project, credential or billable resource was used here, and none of these commands were executed. Every identifier is a placeholder: the sandbox is a project you nominate, and the second is a project you may name but cannot read or write.
Prerequisites. Terraform CLI 1.17.1, the GA and beta providers at 8.10.0, gcloud signed in, ADC present for the same principal, and read access to the sandbox project. Cost is zero: client-config reads, a project read and the built-in test resource create nothing billable.
Setup. Four files in one directory, no modules: version pins, a provider block with project and region, and a main file holding two data reads, one test resource with the preconditions, and one non-sensitive output. Variables hold the expected project, the expected region, and a second project the identity cannot read.
Two gates, tested separately. They fail at different moments, which is why the lab keeps both.
| Gate | What it proves | Failure looks like |
|---|---|---|
| Precondition on the test resource | the resolved project and region match the expected values | plan-time error carrying your message |
| Project read through the same alias | the principal can actually see the target project | denial or not-found before any create |
- Read only the type field of the ADC file, never the whole file. Expect one of the common types: user, service account, external account or impersonated service account.
- Record the CLI view separately: the active account and the configured project. Treat both as context, not as evidence.
- Run
terraform init, keep the lock file, then runterraform versionto confirm 8.10.0 for both provider entries. - Plan with the correct values. Expect one test resource and the resolved project in the identity output, with no other changes.
- Point the provider project at the project the identity cannot read. Expect a denial at the project read, a non-zero exit and no create.
- Restore the provider project and move the expected value to the other project. Expect your precondition message, not an API error.
- Add a resource that accepts a project argument and point it at the other project, carrying the same precondition. Expect the assertion to fail even though the provider default is correct.
- Point the provider at a project you can read but did not expect, and replace the client-config read with the gcloud configured project. Expect the guard to pass, proving the CLI is not evidence.
- Sanitize: keep the credential type, a project suffix, the region and the provider versions. Delete the plan file, local state and provider cache.
Expected observation. The correct run produces a one-object plan, a resolved project and region that match the variables, and a successful read of the target project. Every wrong run stops before a create, and the error names the gate that caught it rather than a downstream API.
Failure check. If a wrong-project plan succeeds, look for the leak: a resource that omits the project and falls back to the default, a variable exported in the shell, an assertion attached to the default alias while the resource uses another, or a data source whose value was already in state and therefore not re-read.
Evidence to keep. The credential type, the resolved project and region, the provider version output, the precondition transcript with its exit code, the denial text from the wrong-project run, and a note naming which gate rejected which attempt. Together they reproduce the decision without publishing a live identity or a full project identifier.
Next in the Series
In Google Cloud IAM and APIs: Authoritative Policies and Service Activation, we'll explore Choose precise IAM ownership and avoid removing access or disabling shared APIs unintentionally.