Exam Terraform Associate All QuestionsBrowse all questions from this exam
Question 191

FILL BLANK -

You need to migrate a workspace to use a remote backend. After updating your configuration, what command do you run to perform the migration?

Type your answer in the field provided. The text field is not case-sensitive and all variations of the correct answer are accepted.

    Correct Answer:

    To migrate a workspace to use a remote backend in Terraform, you should use the command: terraform init -migrate-state. This command reinitializes the Terraform configuration and migrates the existing state to the new backend. The -migrate-state flag ensures that the state migration is performed as part of the initialization process. If you are using Terraform 0.15 or later, this approach is recommended. In versions prior to Terraform 0.15, you would need to manually migrate the state file using the terraform state mv command.

Discussion
dinesh198728

terraform init Once you have authenticated to Terraform Cloud, you're ready to migrate your local state file to Terraform Cloud. To begin the migration, reinitialize. This causes Terraform to recognize your cloud block configuration.

XP_2600

I think terraform init -migrate-state The -migrate-state option will attempt to copy existing state to the new backend, and depending on what changed, may result in interactive prompts to confirm migration of workspace states. The -force-copy option suppresses these prompts and answers "yes" to the migration questions. Enabling -force-copy also automatically enables the -migrate-state option. https://developer.hashicorp.com/terraform/cli/commands/init

Nick_001

terraform init -migrate-state

alen995454

Re-running init with an already-initialized backend will update the working directory to use the new backend settings. Either -reconfigure or -migrate-state must be supplied to update the backend configuration https://developer.hashicorp.com/terraform/cli/commands/init I'm going w/ : terraform init -migrate-state

BaburTurk

terraform init -migrate-state. This command will tell Terraform to read the existing state file and migrate it to the new remote backend. The -migrate-state flag is only available in Terraform 0.15 and later. If you are using an older version of Terraform, you will need to use the terraform state mv command to manually migrate the state file. Here is an example of how to use the terraform init -migrate-state command: terraform init -migrate-state \ -backend=s3://my-bucket/my-workspace

enklau

i agree with ur answer but terraform state mv is for moving individual resources within the state file

Daro_

terraform init --reconfigure should be correct<<<<<<<<<<<< https://support.hashicorp.com/hc/en-us/articles/360001151948-Migrate-Workspace-State-Using-Terraform-State-Push-Pull

tuso

Just did it some days ago (from local to s3). I did "terraform init" and then terraform asks to confirm the migration of your state file. No "-migrate-state" needed.

Komas1999

terraform init -migrate-state missing the last part in the correct answer

LeyLey

terraform init --reconfigure is correct

yair319732

terraform init --reconfigure , but I think terraform init will be sufficient.

fedeX

terraform init -upgrade To migrate a workspace to use a remote backend, you need to run the terraform init command with the -upgrade flag. This will cause Terraform to upgrade the workspace to use the new backend configuration. For example, if you have updated your configuration to use an S3 backend. This will cause Terraform to create any necessary resources in the remote backend (such as an S3 bucket) and migrate the workspace state to the new backend. It is important to note that this will overwrite any existing state in the remote backend, so it is recommended to take a backup of the state before running this command.

E_aws

"terraform init" would be enough

Daro_

terraform init -upgrade -- to upgrade version of providers which are already installed

BaburTurk

https://support.hashicorp.com/hc/en-us/articles/360001151948-Migrate-Workspace-State-Using-Terraform-State-Push-Pull