Your enterprise cloud architecture team needs to safely migrate an existing production Terraform deployment from local state management to a centralized remote backend on Google Cloud Storage with state locking and version control enabled. What is the correct sequence of operational steps required to complete this migration without data loss?
- 1Provision a dedicated Cloud Storage bucket with Object Versioning enabled and grant least-privilege IAM permissions to the Terraform service account.
- 2Add a `backend "gcs"` configuration block specifying the target bucket name and state prefix into the Terraform code.
- 3Execute `terraform init` in the working directory to detect the backend change and trigger the backend initialization process.
- 4Approve the interactive confirmation prompt to copy the existing local state file into the remote GCS backend.
- 5Verify the updated state object in the GCS bucket and safely remove or archive the local `terraform.tfstate` file.
Answer
The correct order begins with provisioning and securing the target Cloud Storage bucket with versioning enabled, adding the backend configuration block to the Terraform code, executing terraform init to detect backend changes, confirming the state transfer prompt, and finally validating the remote state file while removing the local state file.
Migrating Terraform state to Google Cloud Storage requires preparing the destination infrastructure first (creating the versioned GCS bucket), defining the configuration (`backend "gcs"`), executing `terraform init` to register the new backend and transfer local state, confirming the interactive copy prompt, and finally validating remote state presence prior to local file cleanup.
Step-by-Step Solution
Key Concept
Terraform Remote State Migration to Google Cloud Storage
Estimated Time:1m 30s