Question

Difficulty: MediumImplementing Infrastructure as Code using Terraform and Deployment Manager

A cloud operations team is designing a CI/CD pipeline to automate infrastructure provisioning across multiple Google Cloud projects using Terraform. To meet strict enterprise security guidelines, the team must eliminate long-lived service account key files, prevent state file corruption during concurrent pipeline runs, and adhere to the principle of least privilege. Which deployment architecture and authentication strategy adhering to Google Cloud recommended best practices should the team implement?

  1. Configure a Cloud Storage remote backend with Object Versioning and state locking enabled, and authenticate the CI/CD pipeline using Workload Identity Federation with fine-grained IAM roles.Answer
  2. B
    Store Terraform state files in a versioned local directory on the CI/CD runner, and grant the pipeline service account the primitive Editor role to simplify resource creation across all target projects.
  3. C
    Configure a Cloud Storage remote backend for state files, and grant the CI/CD pipeline service account the Service Account Admin role across target projects to manage and impersonate compute workloads.
  4. D
    Store state files in an unversioned local storage directory on the build agent, committing updated state files back to the private repository after each execution while authenticating with static service account keys.

Answer

Configure a Cloud Storage remote backend with Object Versioning and state locking enabled, and authenticate the CI/CD pipeline using Workload Identity Federation with fine-grained IAM roles.
Configuring a Cloud Storage remote backend with Object Versioning provides automated state locking via GCS generation checks to ensure safe concurrent operations. Using Workload Identity Federation allows CI/CD systems to authenticate without long-lived keys while leveraging fine-grained IAM roles.

Step-by-Step Solution

1
Configure remote state locking and versioning
Terraform state is maintained centrally in a Cloud Storage bucket configured with state locking and Object Versioning.
This prevents state corruption from overlapping pipeline executions and allows state recovery in case of deployment failures.
2
Implement keyless authentication for CI/CD
Workload Identity Federation allows external CI/CD runners to exchange short-lived OpenID Connect (OIDC) tokens for Google Cloud IAM credentials.
This eliminates the security exposure associated with downloading and managing long-lived JSON service account key files.
3
Apply least-privilege access control
The impersonated service account is granted fine-grained predefined roles tailored exclusively to the required target GCP resources.
Avoiding primitive roles (Owner/Editor) and identity admin roles minimizes the blast radius of deployment pipeline actions.

Key Concept

Infrastructure as Code Centralized State Governance and Keyless CI/CD Authentication
Estimated Time:1m 30s
Rate this question