A financial services firm utilizes a Cloud Build CI/CD pipeline to execute Terraform code that provisions microservices and database infrastructure across multiple Google Cloud projects. During release cycles, concurrent code merges from multiple engineering teams cause frequent Terraform state lock failures and pipeline build collisions. Additionally, developers have been downloading service account JSON keys to run terraform apply locally from their workstations to bypass pipeline queues. You need to redesign the CI/CD pipeline and SDLC process to eliminate state corruption, enforce execution order, and adhere to Google Cloud security best practices. Which solution should you implement?
- Configure a shared Cloud Storage backend with object versioning and state locking for Terraform, configure Cloud Build trigger concurrency limits to serialize deployment executions, and replace downloadable service account keys with Workload Identity Federation and service account impersonation.Answer
- BMaintain Terraform state files within the version-controlled application source repository, instruct developers to pull state changes before running deployments, and issue long-lived service account keys with specific permissions to developer workstations.
- CAssign the roles/iam.serviceAccountAdmin role to developers so they can generate and manage transient service account keys for local CLI deployments, and store Terraform state files in separate developer-owned Cloud Storage buckets.
- DGrant developers the primitive Editor role on the target GCP projects to allow direct manual intervention during build failures, and execute Cloud Build triggers simultaneously without concurrency limits to maximize build throughput.
Answer
Configure a shared Cloud Storage backend with object versioning and state locking for Terraform, configure Cloud Build trigger concurrency limits to serialize deployment executions, and replace downloadable service account keys with Workload Identity Federation and service account impersonation.
Centralizing Terraform state in Google Cloud Storage with object versioning and state locking guarantees atomic operations and prevents state corruption across concurrent runs. Configuring concurrency controls in Cloud Build serializes release execution, preventing race conditions during deployments. Utilizing Workload Identity Federation eliminates long-lived service account JSON keys by using short-lived, impersonated credentials.
Step-by-Step Solution
Key Concept
CI/CD Pipeline Security and Infrastructure as Code (IaC) State Lock Optimization