Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate — 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.

Show Answer
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

12 comments
Sign in to comment
dinesh198728
Sep 9, 2022

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
Feb 15, 2023

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
Mar 6, 2023

terraform init -migrate-state

alen995454
Jan 15, 2024

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
Aug 27, 2023

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
Jul 21, 2024

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

Daro_
Jan 27, 2023

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

tuso
Jun 3, 2024

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
May 31, 2024

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

LeyLey
Jan 31, 2023

terraform init --reconfigure is correct

yair319732
Jan 25, 2023

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

fedeX
Jan 10, 2023

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
Jan 11, 2023

"terraform init" would be enough

Daro_
Jan 27, 2023

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

BaburTurk
Dec 22, 2022

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