An enterprise energy management company is auditing its continuous integration and continuous delivery (CI/CD) pipelines used to deploy infrastructure and microservices on Google Cloud. The automated pipeline executes Terraform via Cloud Build. An audit reveals that the build pipeline currently stores Terraform state files locally inside the transient Cloud Build workspace container, and the Cloud Build service account is assigned the primitive Project Editor role (`roles/editor`). The architecture team must optimize the pipeline to ensure state persistence, prevent state corruption from concurrent runs, and align with least-privilege security standards. Which combination of architectural changes should the team implement?
- Configure a Google Cloud Storage bucket with object versioning and state locking as the Terraform remote backend, and replace the primitive Editor role on the Cloud Build service account with granular predefined IAM roles for the targeted GCP resources.Answer
- BStore the Terraform state files inside a version-controlled Cloud Source Repositories repository during build execution, and grant the Cloud Build service account the `roles/iam.serviceAccountAdmin` role to manage resource deployment identities.
- CRetain the local workspace state file execution model inside Cloud Build, but upgrade the Cloud Build service account from Project Editor to Project Owner (`roles/owner`) to eliminate resource creation permission errors.
- DExport local Terraform state files to Cloud Logging as custom log entries after each build run, and grant the Cloud Build service account the `roles/iam.serviceAccountAdmin` role to execute deployment tasks.
Answer
Configure a Google Cloud Storage bucket with object versioning and state locking as the Terraform remote backend, and replace the primitive Editor role on the Cloud Build service account with granular predefined IAM roles for the targeted GCP resources.
The solution properly resolves both pipeline deficiencies identified during the audit. Storing Terraform state in a Cloud Storage bucket configured with object versioning and state locking prevents state corruption and loss during parallel CI/CD runs. Replacing the primitive Editor role with fine-grained predefined roles ensures the Cloud Build service account operates strictly within least-privilege security boundaries.
Step-by-Step Solution
Key Concept
CI/CD Pipeline Optimization and Infrastructure as Code State & Security Management