nerdexam
HashiCorp

TA-002-P · Question #433

Once a new Terraform backend is configured with a Terraform code block, which command(s) is (are) used to migrate the state file?

The correct answer is D. terraform init. After configuring a new backend in a Terraform code block, terraform init is the command used to initialize the backend and migrate the local state file to the newly configured remote location.

Implement and maintain state

Question

Once a new Terraform backend is configured with a Terraform code block, which command(s) is (are) used to migrate the state file?

Options

  • Aterraform apply
  • Bterraform push
  • Cterraform destroy, then terraform apply
  • Dterraform init

How the community answered

(42 responses)
  • A
    2% (1)
  • B
    7% (3)
  • C
    2% (1)
  • D
    88% (37)

Why each option

After configuring a new backend in a Terraform code block, `terraform init` is the command used to initialize the backend and migrate the local state file to the newly configured remote location.

Aterraform apply

terraform apply is used to create or modify infrastructure and does not handle backend initialization or state file migration between backends.

Bterraform push

terraform push is not a standard Terraform CLI command used for migrating state files between backends; this command does not exist in the official CLI.

Cterraform destroy, then terraform apply

terraform destroy removes infrastructure, and terraform apply provisions it; neither command is used for the specific task of migrating the state file to a new backend configuration.

Dterraform initCorrect

When a backend configuration is changed or first set up in Terraform, `terraform init` is the specific command responsible for initializing the backend and migrating the existing local state file to the newly defined remote backend.

Concept tested: Terraform backend initialization and state migration

Source: https://developer.hashicorp.com/terraform/language/settings/backends/configuration#migrating-state

Topics

#Terraform state#Backend configuration#State migration#Terraform CLI

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice