An enterprise SaaS company manages its Google Cloud infrastructure using Terraform within a Cloud Build CI/CD pipeline. The lead cloud architect must establish a secure Terraform state management architecture that prevents concurrent execution conflicts, enables state rollback in the event of corruption, and avoids using static, long-lived service account keys for pipeline authentication. Which solution meets these requirements according to Google Cloud best practices?
- Store the Terraform state in a Google Cloud Storage bucket with Object Versioning enabled, rely on the GCS backend's native state locking capabilities, and authenticate Cloud Build via Workload Identity Federation using a fine-grained service account.Answer
- BStore the Terraform state file locally in the Cloud Build build runner directory, upload it to Cloud Storage upon pipeline completion, and grant the runner service account the primitive Editor role.
- CStore the Terraform state in a Google Cloud Storage bucket with Object Versioning disabled to reduce storage overhead, and grant the pipeline service account the primitive Owner role to ensure unrestricted access.
- DStore the Terraform state in a Google Cloud Storage bucket, and instruct operators to perform manual updates via the Google Cloud Console whenever state locks fail to release automatically during pipeline execution.
Answer
Store the Terraform state in a Google Cloud Storage bucket with Object Versioning enabled, rely on native GCS backend state locking, and authenticate the CI/CD pipeline using Workload Identity Federation with a dedicated, least-privilege service account.
The combination of a Cloud Storage remote backend with Object Versioning and native locking provides centralized, consistent, and recoverable state management. Paired with Workload Identity Federation, the CI/CD pipeline securely authenticates using short-lived credentials assigned to a least-privilege service account without requiring static key storage.
Step-by-Step Solution
Key Concept
Infrastructure as Code (IaC) Remote State Governance and Secure CI/CD Authentication