A Cloud Engineer needs to migrate an existing local Terraform state file to a Google Cloud Storage (GCS) remote backend to allow team collaboration and state locking. What is the correct sequence of steps to safely execute this backend migration?
- 1Create a Google Cloud Storage bucket with object versioning enabled to securely store the state file.
- 2Add a backend "gcs" configuration block to the root Terraform module targeting the newly created bucket.
- 3Run the command `terraform init` to initialize the configuration and trigger the backend migration process.
- 4Confirm the state copy prompt when prompted by the CLI to complete the migration.
Cevap
The correct sequence starts with creating the GCS storage bucket, adding the backend block to the HCL configuration, running terraform init, and confirming the state migration prompt.
To migrate state securely to GCS, the target GCS bucket must first exist. Next, the backend "gcs" configuration block is defined in HCL code. Running `terraform init` detects the new backend configuration and initiates the migration. Finally, confirming the migration prompt copies the existing local state file to the remote GCS bucket.
Adım Adım Çözüm
Anahtar Kavram
Migrating Terraform Local State to GCS Remote Backend
Tahmini Süre:1m 0s