A DevOps engineer needs to migrate an existing local Terraform state file to a Google Cloud Storage (GCS) remote backend for shared team access. What is the correct sequence of steps to migrate the local Terraform state to the GCS remote backend?
- 1Create a Google Cloud Storage (GCS) bucket with object versioning enabled.
- 2Define the GCS backend configuration block in the Terraform code.
- 3Run terraform init to copy local state to the newly configured GCS backend.
- 4Confirm state migration success and safely clean up local terraform.tfstate files.
Cevap
The correct sequence begins with creating the GCS storage bucket with versioning, followed by declaring the GCS backend in the Terraform code, executing terraform init to migrate state, and finally confirming successful migration before cleaning up local state files.
The GCS bucket must be created first because Terraform requires an existing bucket to initialize its remote state. Once the bucket exists, the backend configuration block is added to code. Running terraform init detects the new backend configuration and performs the migration from local disk to GCS. Finally, verification and cleanup ensure all team members use the single remote source of truth.
Adım Adım Çözüm
Anahtar Kavram
Terraform GCS Remote Backend State Migration Workflow