Google resources and API prerequisites
Identify service prerequisites before writing resources
Most Google Cloud APIs require enablement for the relevant consumer project. The project must exist, billing may need to be enabled, and the calling identity needs permission to use or enable the service as appropriate. A service being enabled does not grant authorization or guarantee quota, regional availability or organization-policy compliance. In a real architecture, service activation and the permissions to do it belong to an explicit project bootstrap owner. Service Usage itself may need to be bootstrapped separately. Do not automatically enable APIs in a project you do not own.
# Static fragment; requires approved project bootstrap and provider.resource "google_project_service" "compute" { project = "example-catalog-dev" service = "compute.googleapis.com" disable_on_destroy = false}This static example shows a possible ownership record for Compute Engine API enablement. The explicit false setting is intended to avoid disabling the service during deletion of this Terraform management record. The provider has changed defaults across releases; check the pinned schema, deletion behavior and dependencies rather than relying on an omitted field. It does not prevent an authorized external actor from disabling the API. Do not initialize or apply the illustration.
Create a network or look up a shared network
A resource block manages the lifecycle of an object; a data block reads information using the provider. A global VPC network can contain regional subnets, and a VM in a zone uses a compatible subnet in its region. A team may manage its own network or consume a Shared VPC in a host project. Shared VPC also requires appropriate attachment and network permissions, not just knowledge of the name. The following two snippets represent alternatives for a single network ownership decision.
# Static alternatives for a single network: choose ownership OR lookup.# Owned network in an approved dedicated project:resource "google_compute_network" "catalog" { project = "example-catalog-dev" name = "catalog" auto_create_subnetworks = false depends_on = [google_project_service.compute]}# Lookup alternative: shared network owned by a different team.data "google_compute_network" "shared" { project = "example-network-host" name = "shared-network"}The first declares a new custom-mode network and explicitly waits for the separately shown Compute API enablement record, a behavioral dependency with no otherwise referenced attribute. It does not create subnets by itself. The second looks up a host-owned network, assuming the identity can read it; the lookup can call an external API during plan and may fail. Neither snippet is a complete deployment. Never declare a second resource to manage an already-owned network merely because the data lookup fails. Check exact provider schema and authorization; a dependency edge does not guarantee that all service-side operations have finished propagating.
Understand IAM ownership before changing access
A service account represents a workload or automation identity. Creating one, granting it roles and using or impersonating it are different authorization operations. Project IAM management resources have different replacement scopes: google_project_iam_policy manages the project IAM policy as a whole; google_project_iam_binding manages members for a role; google_project_iam_member manages a single membership. Avoid combining a full-policy resource with binding or member resources for the same project, or mixing bindings and members for the same role. Conditions and inherited policies require additional review. A full-policy change can unintentionally revoke other teams’ access.
# Static fragment; review exact role scope and member ownership.resource "google_project_iam_member" "catalog_reader" { project = "example-catalog-dev" role = "roles/logging.viewer" member = "serviceAccount:catalog-reader@example-catalog-dev.iam.gserviceaccount.com"}The example grants a specific fictional service account the project-level logging viewer role. It assumes the service account exists and that access is required across the target project; prefer a narrower supported scope where possible. It does not grant permission to deploy infrastructure or impersonate the account. The grant should have a single management owner. Additive membership does not make access safe by itself; review actual permissions, inheritance and organization constraints. Never use broad owner permissions as a routine fix.
Diagnose missing prerequisites without bypassing controls
A disabled API, permission denial, quota exhaustion and a location mismatch are different problems. A disabled API calls for identifying the correct consumer project and bootstrap owner. A permission error calls for checking identity and required permission, not automatically granting broad roles. A quota error calls for reviewing limit, usage, metric and location; retries may help only for transient rate limits. A location mismatch calls for checking resource scope and API requirements. A newly enabled service or newly created service agent may take time to become usable; use documented readiness checks in an authorized workflow, not an arbitrary sleep as proof of readiness. A provider schema describes arguments and attributes; it cannot prove an operation is authorized or will succeed. Review schema offline only with trusted plugins in a separately approved environment.
Practice ownership and change review
Read the synthetic inventory in the worksheet. The platform team owns the shared network and its API bootstrap; the application team owns a separate project and consumes the subnet. Decide which state owns each managed object, which identifiers should be outputs or lookups, and who approves service enablement and IAM changes. Reject any plan that disables a shared API or replaces a full project policy without explicit ownership and approval. The model contains no real resources, credentials or account metadata. A future live lab needs a separately approved project, cost estimate, scoped identity, exact dependency lock and teardown plan; API calls and retained resources can have consequences even after a Terraform record is removed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Google resources and API prerequisites — knowledge check
Review Google Cloud project scope, service prerequisites and IAM.
Compute API is disabled in the target project. What should happen first?
Which block is appropriate to read an existing host-owned network?
Which IAM resource manages a single project-role-member relationship?
A binding and member resource manage the same project role. What should the reviewer do?
What does a successful provider schema check establish?