Question

Difficulty: EasyInfrastructure as Code and Environment Provisioning

A DevOps team uses Terraform to provision and maintain their Google Cloud environments. To ensure operational reliability and prevent state corruption caused by concurrent deployments, the team needs to configure a central backend for storing Terraform state files. Which configuration approach aligns with Google Cloud best practices for managing Infrastructure as Code state?

  1. Store the Terraform state file in a Google Cloud Storage bucket configured as a remote backend with object versioning enabled.Answer
  2. B
    Store the Terraform state file locally on the CI/CD runner's disk and commit the file to version control after each deployment execution.
  3. C
    Store the Terraform state file in a Google Cloud Storage bucket and assign the CI/CD deployment service account the Owner primitive role to ensure access.
  4. D
    Store the Terraform state file in a Google Cloud Storage bucket and grant the CI/CD pipeline service account the Service Account Admin role to run provisioning tasks.

Answer

Store the Terraform state file in a Google Cloud Storage bucket configured as a remote backend with object versioning enabled.
Using a Google Cloud Storage bucket as a remote backend for Terraform is the Google Cloud standard for managing Infrastructure as Code state. GCS remote backends natively support automatic state locking during execution and allow enabling object versioning to recover state in case of accidental corruption or invalid changes.

Step-by-Step Solution

1
Identify the requirement for managing Infrastructure as Code state safely across team members and automated pipelines.
Recognize that state files must be stored in a centralized, shared backend supporting concurrency locking and backup.
Local state files or version control commits do not provide locking mechanism during execution and risk race conditions.
2
Evaluate Google Cloud Storage features suitable for Infrastructure as Code state storage.
GCS natively supports state locking (via Terraform GCS backend) and Object Versioning to safeguard state history.
Enabling object versioning allows restoring past states if corruption occurs, ensuring environment provisioning reliability.

Key Concept

Terraform Remote State Backend Management in Google Cloud Storage
Rate this question