A DevOps team is setting up an automated Continuous Integration/Continuous Deployment (CI/CD) pipeline using HashiCorp Terraform to provision infrastructure in Google Cloud. Multiple automated jobs and team members will execute Terraform deployments concurrently across shared environments. You need to configure a remote backend that prevents state file corruption from concurrent writes, maintains history for disaster recovery, and enforces least-privilege security access. Which solution should you implement?
- Store the Terraform state in a Google Cloud Storage bucket with Object Versioning enabled, configure the Terraform `gcs` backend to handle state locking automatically, and authenticate using fine-grained IAM roles via service account impersonation.Answer
- BStore the Terraform state file in a standard Cloud Storage bucket without versioning, relying on developers to maintain manual local state file backups prior to executing deployment runs.
- CConfigure a Cloud Storage remote backend and assign the primitive Project Owner IAM role to the CI/CD execution service account to eliminate permission errors during backend initialization and state updates.
- DConfigure the Terraform backend to use Cloud Storage and configure automated script retries in the CI/CD pipeline to resolve regional quota availability failures during execution.
Answer
The correct architecture uses a Google Cloud Storage remote backend with Object Versioning enabled, Terraform's native `gcs` backend for automatic state locking, and fine-grained IAM permissions using service account impersonation.
Configuring a Cloud Storage bucket with Object Versioning combined with Terraform's native `gcs` backend ensures state locking prevents concurrent modification while enabling historical state recovery. Authenticating using least-privilege predefined IAM roles aligns with Google Cloud security best practices.
Step-by-Step Solution
Key Concept
Enterprise Terraform Remote State Management on Google Cloud Storage