Your team needs to migrate a monolithic local Terraform state file (`terraform.tfstate`) managing production GCP resources to an enterprise remote backend hosted on Google Cloud Storage (GCS) with object versioning and state locking. Place the steps in the correct order to perform this state migration safely without losing resource state or creating concurrency issues.
- 1Configure the `backend "gcs"` block inside the Terraform configuration file specifying the dedicated GCS bucket and state prefix.
- 2Run `terraform init` to detect the new backend configuration and prompt for backend initialization.
- 3Confirm 'yes' at the CLI prompt to copy the existing local state data to the new GCS remote backend.
- 4Verify remote lock functionality using `terraform plan` and archive or delete the local `terraform.tfstate` file.
Cevap
The correct sequence for migrating local Terraform state to a GCS remote backend begins by adding the backend block, running terraform init, approving the automatic state copy prompt, and validating remote locking before removing local state files.
The migration process requires declaring the backend configuration first, invoking backend initialization via terraform init, approving the state transfer to GCS, and finally validating state lock functionality before removing local state backups.
Adım Adım Çözüm
Anahtar Kavram
Migrating local Terraform state to remote Google Cloud Storage (GCS) backend with state locking.