Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 149


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

Show Answer
Correct Answer: D

To migrate the state file once a new Terraform backend is configured, you should use the terraform init command. This command initializes the backend and will prompt you to confirm if you want to migrate your existing state file to the new backend. This process updates the backend configuration and migrates the state file as necessary.

Discussion

29 comments
Sign in to comment
keiffo2
Mar 6, 2023

D: I think Migrate the state file 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. $ terraform init Initializing Terraform Cloud... Do you wish to proceed? As part of migrating to Terraform Cloud, Terraform can optionally copy your current workspace state to the configured Terraform Cloud workspace. Answer "yes" to copy the latest state snapshot to the configured Terraform Cloud workspace. Answer "no" to ignore the existing state and just activate the configured Terraform Cloud workspace with its existing state, if any. Should Terraform migrate your existing state? Enter a value: Copy During reinitialization, Terraform presents a prompt saying that it will copy the state file to your Terraform Cloud workspace. Enter yes and Terraform will migrate the state from your local machine to Terraform Cloud.

kprodOption: B
Mar 5, 2023

B - The terraform state push command is used to manually upload a local state file to remote state. This command also works with local state.

Hizumi
Mar 5, 2023

Answer is A. After the backend is done initializing by running terraform init, you apply the configuration using terraform apply Reference: https://learn.hashicorp.com/tutorials/terraform/cloud-migrate

Hizumi
Mar 14, 2023

Changing my to D. Check section "Migrate the state file" in reference doc: "Once you have authenticated to Terraform Cloud, you're ready to migrate your local state file to Terraform Cloud. To begin the migration, reinitialize."

RVivekOption: D
Mar 27, 2023

terraform init -migrate-state is the command to be used

alirasouliOption: D
Jun 10, 2023

When you change a backend's configuration, you must run `terraform init` again to validate and configure the backend before you can perform any plans, applies, or state operations. Reference: https://developer.hashicorp.com/terraform/language/settings/backends/configuration#initialization

z466235244Option: D
Aug 27, 2023

Terraform push is no long functional

NunyabiznesOption: D
Oct 2, 2023

Terraform push has been retired after version 0.12.0

Stanislav4907Option: D
Oct 8, 2023

Once a new Terraform backend is configured with a Terraform code block, you can use the following command to migrate the state file from the previous backend to the new one: terraform init -migrate-state

lordogre16Option: D
Mar 21, 2023

D. Since "push" isn't a valid command anymore

yogishrb2020Option: B
Apr 9, 2023

B is right answer as per documentation. https://www.terraform.io/cli/commands/state/push

yogishrb2020
Apr 9, 2023

We have terrafom state push. and not Terraform Push. I go with community .. Answer : D

alifieOption: D
Apr 17, 2023

after you config the block for backend you have to init

ssanjaytOption: D
Jul 13, 2023

Answer is D coz terraform push is deprecated and does not operate in the current version of TFE.

Americanman
Sep 2, 2023

The terraform state push command is used to manually upload a local state file to remote state. Would go with D

campsOption: D
Sep 30, 2023

D. terraform init. When configuring a new Terraform backend, the state file needs to be migrated to the new backend so that it can be used to manage infrastructure state going forward. The terraform init command is used to initialize a new backend and migrate the state file to that backend.

DevoteamAnalytix
Oct 26, 2023

I think it's B not D because it is about MIGRATING the state file. "Usage: terraform state push [options] PATH" https://developer.hashicorp.com/terraform/cli/commands/state/push "The terraform push command was an early implementation of remote Terraform runs. It allowed teams to push a configuration to a remote run environment in a discontinued version of Terraform Enterprise." https://developer.hashicorp.com/terraform/cli/commands/push

donathonOption: B
Mar 6, 2023

https://www.terraform.io/cli/commands/state/push

Nani0107
Mar 15, 2023

The legacy Terraform Enterprise version that supported terraform push is no longer available, and there are no remaining instances of that version in operation. Without a service to push to, the command is now completely non-functional. https://www.terraform.io/cli/commands/push

xr19970428
Mar 23, 2023

D "When you change a backend's configuration, you must run terraform init again to validate and configure the backend before you can perform any plans, applies, or state operations."

mahwishOption: D
Mar 28, 2023

To migrate your existing state file to Terraform Cloud, you must reinitialize your configuration to update the backend. Reinitialize your configuration. Terraform detects your updated backend and confirms that you wish to migrate your state file to Terraform Cloud.

dani88geOption: B
Apr 11, 2023

B for sure

DerekKey
Jun 4, 2023

D - When you change a backend's configuration, you must run terraform init again to validate and configure the backend before you can perform any plans, applies, or state operations. https://developer.hashicorp.com/terraform/language/settings/backends/configuration#initialization

ArizonaClassics
Jun 7, 2023

D: Command: state push The terraform state push command is used to manually upload a local state file to remote state. This command also works with local state. This command should rarely be used. It is meant only as a utility in case manual intervention is necessary with the remote stat

InformationOverload
Jun 29, 2023

id go with B; terraform state push

InformationOverload
Jun 29, 2023

I change my answer to D since you first have to terraform init and then use terraform state push. (Answer B says just terraform push, and that is not correct)

Only5
Jul 19, 2023

This is from chatGPT - answer : B The command used to migrate the state file to a new Terraform backend is terraform state push. This command uploads the local state file to the new backend, replacing the state that may already exist in the backend.

lezgino
Aug 5, 2023

The correct command to migrate the state file to a new backend is: "terraform init". The "terraform init" command will detect the new backend configuration and prompt you to copy your existing state to the new backend. B is correct

princajen
Aug 16, 2023

After configuring a new Terraform backend with a Terraform code block, you will need to use the terraform init command to initialize the backend and download any necessary provider plugins. Once you have initialized the backend, you can use the terraform state command to manage the state file. If you have an existing state file that you need to migrate to the new backend, you can use the terraform state pull command to download the current state file, and then use the terraform state push command to upload it to the new backend.

mamoon_malta2022
Sep 4, 2023

Answer D: The terraform state push command is used to manually upload a local state file to remote state. This command also works with local state. This command should rarely be used. It is meant only as a utility in case manual intervention is necessary with the remote state.

[Removed]Option: D
Jun 16, 2024

B is correct if the command is "terraform state push"

nakuaadamOption: D
Sep 13, 2024

https://developer.hashicorp.com/terraform/tutorials/cloud/cloud-migrate Important: The terraform push command is no longer functional. https://developer.hashicorp.com/terraform/cli/commands/push

d759fb3Option: D
Jan 30, 2025

it can't be B. For one syntax is wrong, should be "terraform state push". Also "terraform state push" updates remote state from a local state file at PATH.