A Cloud Engineer needs to migrate a local Terraform state file to a Google Cloud Storage (GCS) remote backend for a production deployment. Place the steps required to complete this migration in the correct execution order.
- 1Create a dedicated Google Cloud Storage bucket with Object Versioning enabled.
- 2Add a `backend "gcs"` configuration block specifying the bucket name into the Terraform code.
- 3Execute `terraform init` in the root configuration directory.
- 4Confirm the CLI prompt to copy the existing local state file to the GCS remote backend.
Answer
To migrate local Terraform state to a GCS remote backend, first provision the GCS bucket with versioning enabled, then define the backend "gcs" block in the Terraform code, run `terraform init` to reconfigure the backend, and lastly confirm the prompt to copy local state to GCS.
The correct sequence starts by provisioning the GCS storage bucket with object versioning enabled. Next, the engineer updates the Terraform code with a `backend "gcs"` block pointing to the bucket. Then, running `terraform init` prompts Terraform to recognize the new remote backend. Finally, confirming the migration prompt transfers existing local state into the GCS bucket.
Step-by-Step Solution
Key Concept
Terraform Remote State Migration to Google Cloud Storage Backend