Soru

Zorluk: OrtaInfrastructure as Code and Environment Provisioning

A streaming media platform uses Terraform within automated Cloud Build pipelines to provision short-lived staging environments. During high-frequency deployment periods, multiple pipeline runs targeting the same Google Cloud Storage remote backend fail because concurrent execution attempts cause state file conflicts and partial environment provisioning. Which configuration should the DevOps team implement to ensure state locking and state recovery for reliable environment provisioning?

  1. Configure the Terraform backend using the standard Google Cloud Storage (gcs) backend type and enable Object Versioning on the Cloud Storage bucket.Cevap
  2. B
    Store state files locally within the Cloud Build build container workspace and run a post-build script using gsutil rsync to push state files to storage.
  3. C
    Assign the IAM Owner primitive role to the Cloud Build service account to allow it to override concurrent state locks dynamically.
  4. D
    Establish a VPC Network Peering connection between Cloud Build execution networks to route state traffic transitively without using Cloud Storage API locks.

Cevap

Configure the Terraform backend using the standard Google Cloud Storage (gcs) backend type and enable Object Versioning on the Cloud Storage bucket.
The standard Google Cloud Storage (gcs) backend for Terraform natively supports state locking by utilizing GCS object generation and metageneration preconditions. When combined with GCS Object Versioning, state files are protected against concurrent modifications and accidental corruption during automated CI/CD environment deployments.

Adım Adım Çözüm

1
Identify the root cause of concurrent environment provisioning failures in IaC pipelines.
Concurrent pipeline runs collide when writing to the remote state file without proper state locking mechanisms.
Terraform state integrity requires exclusive lock acquisition during modifications to prevent race conditions and partial state updates.
2
Select the native Google Cloud API mechanism for state management in GCP.
The standard gcs backend type leverages Cloud Storage strong consistency and built-in object lock capabilities automatically.
Google Cloud Storage natively handles atomic operations and generation-based locking for Terraform state operations.
3
Implement state safety and recovery best practices.
Enabling Cloud Storage Object Versioning ensures previous versions of the state file are retained.
Object Versioning protects against unintended state file corruption or manual execution drift, allowing rapid rollback if needed.

Anahtar Kavram

Terraform State Locking and Remote State Management on Google Cloud Storage
Bu soruyu puanla