An organization uses Cloud Build to execute Terraform scripts as part of its automated CI/CD deployment pipeline. Currently, developers run into frequent infrastructure deployment conflicts and state corruption when multiple pipeline jobs execute simultaneously because Terraform state is maintained in the local build workspace. Which strategy should the team implement to resolve this CI/CD pipeline issue following Google Cloud best practices?
- Configure the Terraform backend to use a Google Cloud Storage bucket with object versioning and state locking enabled.Answer
- BStore the Terraform state files locally within the Cloud Build ephemeral workspace and commit them back to the source code repository after each run.
- CGrant the Cloud Build service account the Project Owner primitive role to automatically grant lock control over all project resources.
- DAssign the Service Account Admin role to the pipeline runner service account so it can reset credentials whenever pipeline collisions occur.
Answer
Configure the Terraform backend to store state files in a Google Cloud Storage bucket with object versioning and state locking enabled.
Configuring a Google Cloud Storage bucket with object versioning and state locking enabled acts as a centralized backend for Terraform. This ensures concurrent CI/CD pipeline executions wait for ongoing state operations to finish before modifying infrastructure, preventing state file corruption.
Step-by-Step Solution
Key Concept
Centralized IaC state management and concurrency control in CI/CD pipelines