Soru

Zorluk: OrtaImplementing Infrastructure as Code using Terraform and Deployment Manager

A cloud engineering team needs to safely migrate an existing local Terraform state file to a secure Google Cloud Storage (GCS) remote backend with state locking enabled. Arrange the operational steps in the correct sequence to complete this migration.

  1. 1Provision a private GCS bucket with Object Versioning enabled and uniform bucket-level access enforced.
  2. 2Add the `backend "gcs"` configuration block specifying the bucket details into the root Terraform module file.
  3. 3Execute `terraform init` and confirm the prompt to copy existing local state data to the newly configured GCS backend.
  4. 4Verify the state file exists in the GCS bucket and safely remove the leftover local `terraform.tfstate` file.

Cevap

The correct operational sequence begins with provisioning the private GCS bucket with Object Versioning enabled, adding the GCS backend configuration block to the Terraform module, executing terraform init to migrate the state data, and finally verifying remote state creation before deleting the local state file.
Safely migrating Terraform state requires provisioning the remote GCS bucket with Object Versioning first, defining the backend block in the Terraform code second, executing terraform init to copy existing local state into GCS third, and removing local state files fourth to maintain a single source of truth.

Adım Adım Çözüm

1
Provision Destination GCS Bucket
A secure GCS bucket configured with Object Versioning and uniform bucket-level access is available.
Google Cloud Storage must exist to host state files and provide Cloud KMS/IAM lock capabilities.
2
Configure Terraform Backend
The backend configuration is declared in code.
Terraform requires explicit backend parameters in code to identify the migration target.
3
Run State Migration Command
Local state file contents are securely uploaded to GCS.
Executing terraform init triggers Terraform's internal state migration mechanism.
4
Post-Migration Verification and Cleanup
Local state artifacts are deleted, establishing GCS as the single source of truth.
Removing redundant local state files prevents unauthorized access and operational confusion.

Anahtar Kavram

Terraform GCS Remote Backend State Migration
Tahmini Süre:1m 30s
Bu soruyu puanla