Soru

Zorluk: KolayBuilding and Managing Infrastructure as Code (IaC)

An engineering team needs to migrate their local Terraform state file to a centralized Google Cloud Storage (GCS) bucket for collaborative management. Arrange the operational steps in the correct sequential order to complete this state migration.

  1. 1Add a `backend "gcs"` configuration block inside the Terraform root module pointing to the target Cloud Storage bucket.
  2. 2Run `terraform init` in the working directory to initialize the new backend configuration.
  3. 3Approve the interactive confirmation prompt to copy the existing local state file into the Cloud Storage bucket.
  4. 4Run `terraform plan` to verify that the remote state accurately reflects the live infrastructure without pending changes.

Cevap

The correct operational order begins with adding the `backend "gcs"` configuration block, executing `terraform init`, confirming the state transfer prompt, and finishing with `terraform plan` to verify remote state synchronization.
Safely migrating local Terraform state to a remote GCS backend requires defining the backend block in code, running `terraform init` to initiate migration, agreeing to transfer existing state data, and running `terraform plan` to confirm remote state integrity.

Adım Adım Çözüm

1
Declare the GCS backend in Terraform configuration
The Terraform project code now specifies the destination GCS bucket and state prefix.
Terraform must be informed of the new state backend target before any migration commands can run.
2
Run `terraform init`
Terraform detects the added backend block and triggers the migration routine.
The init command configures the backend plugins and prepares to transfer existing state to the new location.
3
Confirm the state copy prompt
The local state data is safely uploaded into the GCS bucket.
Explicit user approval ensures that local state is transferred rather than generating a fresh empty state.
4
Execute `terraform plan` for validation
Confirmation of zero unexpected infrastructure changes.
Running plan verifies that the remote state file is functioning properly and matches actual GCP resources.

Anahtar Kavram

Terraform Remote State Migration to Google Cloud Storage
Bu soruyu puanla