Question

Difficulty: EasyImplementing Infrastructure as Code using Terraform and Deployment Manager

A cloud engineering team is preparing to collaborate on provisioning Google Cloud resources using Terraform. To ensure concurrent state locking and prevent state file corruption during team deployments, which remote backend configuration should they use?

  1. Configure a Google Cloud Storage (GCS) bucket backend with object versioning enabled.Answer
  2. B
    Store the state file in a local git repository directory and rely on git merge operations for concurrency.
  3. C
    Configure a Cloud Storage bucket backend and assign the primitive Owner role to the deployment pipeline service account.
  4. D
    Store the state file in Cloud Storage while granting developers the Service Account Admin role to access the backend.

Answer

Configure a Google Cloud Storage (GCS) bucket backend with object versioning enabled.
Configuring a Google Cloud Storage bucket backend provides native lock support during plan and apply actions, preventing race conditions. Enabling object versioning ensures state history is maintained for recovery.

Step-by-Step Solution

1
Identify team collaboration requirements for Terraform state.
Remote state storage with lock capabilities is required to handle concurrent executions safely.
Simultaneous execution on a shared state file without locking can lead to state corruption.
2
Select the standard GCP-native backend for Terraform.
The GCS backend (`gcs`) leverages Cloud Storage native strong consistency and locking.
Terraform integrates directly with GCS to automatically lock state during operations and unlock upon completion.
3
Enable Object Versioning on the target Cloud Storage bucket.
Historical state versions are preserved.
Versioning allows rapid rollback and recovery if state becomes corrupted or accidentally overwritten.

Key Concept

Terraform Remote State Management with Google Cloud Storage
Estimated Time:1m 0s
Rate this question