Question

Difficulty: EasyAnalyzing Software Development Lifecycle (SDLC) and CI/CD Pipelines

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?

  1. Configure the Terraform backend to use a Google Cloud Storage bucket with object versioning and state locking enabled.Answer
  2. B
    Store the Terraform state files locally within the Cloud Build ephemeral workspace and commit them back to the source code repository after each run.
  3. C
    Grant the Cloud Build service account the Project Owner primitive role to automatically grant lock control over all project resources.
  4. D
    Assign 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

1
Identify the root cause of CI/CD deployment conflicts
The pipeline relies on local state within an ephemeral container workspace, preventing state sharing and locking across concurrent executions.
Infrastructure as Code pipelines require a central, synchronized state repository to manage resources reliably.
2
Select the appropriate remote backend storage solution on GCP
Configure Cloud Storage as the remote backend for Terraform.
Cloud Storage provides persistent, central, and secure storage for state files across all CI/CD executions.
3
Enable concurrency controls and history tracking
Enable object versioning on the GCS bucket and leverage native Terraform state locking.
State locking prevents concurrent pipeline runs from corrupting the state file, while versioning provides rollback capabilities.

Key Concept

Centralized IaC state management and concurrency control in CI/CD pipelines
Rate this question