Google provider and project scope
Understand the project before the provider
A Google Cloud project groups cloud resources and is a common boundary for API enablement, permissions and quotas. Organizations and folders can organize projects and carry inherited policies. A Cloud Billing account pays for linked projects; it is not the parent of the project in the resource hierarchy. A project ID is a globally unique identifier when assigned, a project number is system-assigned, and a display name is a human label. In this example every identifier is fictional; a name that looks plausible is not proof that you own it.
Organization: Example company Folder: Development Project: example-catalog-dev (application resources) Project: example-network-host (shared network)Billing account: fictional finance owner; linked to projects separatelyThe network and application teams can own different projects while finance handles billing. Inherited IAM and organization policies still matter. A separate project can reduce accidental overlap, but it does not automatically make users or traffic isolated. Review the intended project ID, its parent, billing owner and permissions before any operation.
Configure the provider and location explicitly
The provider is a plugin translating Terraform resource operations into Google Cloud API calls. The Google provider configuration supplies defaults for resources that support a project, region or zone. A region groups zones; a zonal VM and a regional subnet have different scope. A VPC network is global. Some resources need an explicit location, some are global, and others use a differently named location field. Do not infer the scope from the provider defaults alone.
# Static example only. Do not initialize or authenticate.terraform { required_version = "= 1.14.8" required_providers { google = { source = "hashicorp/google" version = "= 7.25.0" } }}provider "google" { project = "example-catalog-dev" region = "us-central1" zone = "us-central1-a"}The project, region and zone above are teaching inputs, not verified account or service availability. The provider 7.25.0 configuration reference was found in the Registry; the version is illustrative, not asserted latest, patched or suitable for production. The CLI 1.14.8 pin is retained from earlier chapters. No provider has been downloaded. Before an authorized lab, verify both versions, exact schemas, checksums, lockfile, service availability and organizational restrictions. Resource-level project or location arguments may override defaults where supported.
Choose the provider channel deliberately
The normal google provider and google-beta provider have separate source addresses. The beta channel can expose features earlier than the normal channel. A beta provider is not a guarantee that every feature is beta, nor does choosing it enable all services. Use the normal provider unless a specifically reviewed feature needs the other channel. Verify the feature stage and release compatibility independently.
# Separate provider requirement for a reviewed beta feature.# Merge with the existing required_providers block; not a full file.google-beta = { source = "hashicorp/google-beta" version = "= 7.25.0"}This is a partial required_providers entry, not a standalone configuration. When a resource must use the beta provider, explicitly configure the corresponding provider and select it through its provider meta-argument (for example provider = google-beta). Do not rely on the resource type prefix to select beta automatically. Review compatibility and state migration before switching channels.
Separate Terraform identity from workload identity
Authentication establishes the calling identity; IAM authorization decides what that identity may do. Application Default Credentials (ADC) is a credential-discovery mechanism. Depending on environment, it may locate a configured credential file, local ADC credentials or an attached service identity via the metadata server. An ordinary gcloud login is distinct from configuring ADC. A local development session and a CI job may resolve different identities. Do not inspect actual ADC or authenticate for this lesson. In an approved environment, use short-lived credentials and a reviewed identity. For external CI, Workload Identity Federation can exchange external identity assertions for Google credentials, optionally using service account impersonation where configured. Federation requires a configured trust relationship and narrow permissions; it is not automatic access. A VM or application service account is its runtime identity, not necessarily the identity that deploys it. Never put real keys in HCL, tfvars, plans or state; avoid long-lived service account keys where possible.
Practice project and location review without a provider
The following complete configuration only assembles synthetic strings and exports a review object. It uses no external provider and does not check whether the named projects or subnets exist.
terraform { required_version = "= 1.14.8"}locals { host_project = "example-network-host" app_project = "example-catalog-dev" region = "us-central1" zone = "us-central1-a" subnet_path = "projects/${local.host_project}/regions/${local.region}/subnetworks/catalog"}output "review" { value = { network_owner = local.host_project app_owner = local.app_project subnet_path = local.subnet_path zone = local.zone }}Expected subnet_path: projects/example-network-host/regions/us-central1/subnetworks/catalog. Network owner is example-network-host; application owner is example-catalog-dev. The output is a model of resource scope, not a live resource ID lookup. In a real configuration prefer approved resource or data-source outputs over manually constructed identifiers. The expected string was independently checked with Python; Terraform itself was not executed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Google provider and project scope — knowledge check
Review Google Cloud project scope, service prerequisites and IAM.
Which identifier is system-assigned to a Google Cloud project?
Which resource is regional?
What does ADC determine?
Which identity design fits external CI when federation is configured?
When should google-beta be selected?