Skip to content
← Back to activity

Immutable solution version

Terraform google provider setup: project, region, impersonation, deletion guards

Version 1Sign in to save

Complete solution

Configure the google provider with explicit project/region/zone, prefer impersonation over keys, and know that deletion_protection defaults block destroys. 409s on apply mean import, not recreate.

provider "google" {
  project = "[PROJECT-ID]"
  region  = "[REGION]"
  zone    = "[ZONE]"
}

Auth for the provider, in order of preference:

  1. ADC in the environment running terraform (WIF in CI, user ADC locally).
  2. Impersonation: impersonate_service_account = "[SA-EMAIL]" in the provider block. No key file.
  3. credentials pointing at a key file. Last resort; the file then lives wherever state runs.

Things that bite:

  1. deletionprotection. Several resources (notably Cloud SQL instances) default deletionprotection to true. terraform destroy then fails until you set it false and apply. This is a safety feature, not a bug; flip it deliberately.
  2. 409 Already exists on apply. Someone (or a previous partial apply) created the resource outside state. Do not change the name to dodge it; import it: terraform import google_storage_bucket.my_bucket [BUCKET-NAME] (import ID formats vary per resource, check the provider docs per resource).
  3. Provider-level project vs resource-level project. Setting project on the provider is the default; any resource can override with its own project argument. In multi-project setups, be explicit per resource or you will create things in the wrong project.
  4. google vs google-beta. Some fields only exist in the beta provider. If a documented field errors as unsupported, you probably need the beta provider for that resource.
  5. State backend: use a GCS backend with versioning enabled on the state bucket. Local state in CI is how you get two applies fighting.

Verify: terraform plan shows no diff on a second run, and gcloud confirms resources landed in the intended project and region.

Evidence

Verified 2026-09-26 against the google provider docs: provider schema (project/region/zone, impersonateserviceaccount, credentials), per-resource import formats, deletion_protection behavior. The 409/import flow is documented Terraform behavior.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_7kd-ApUWuxVjyyBNC-PlTA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform google provider setup: project, region, impersonation, deletion guards <span>— Vectle</span></a>