terraform init -migrate-state
The init option that copies existing state from the old backend into a newly configured one.
In more detail
Use it when you move from local state to a remote backend, or between backends. Take a backup of the state first and check the result with a plan that shows no changes.
Related terms
- terraform init — The command that prepares a directory for Terraform: it downloads providers, fetches modules, connects the backend and writes the lock file.
- terraform init -reconfigure — The init option that ignores any saved backend settings and sets the backend up from scratch, without copying existing state.
- Terraform backend — The setting that decides where Terraform stores state and how it locks it, from a local file to shared cloud storage.
- state backup — A saved copy of the state from before a change, kept so you can recover if the state is damaged or a repair goes wrong.
Taught in
- Initialising The Working Directory — Infrastructure as Code with Terraform
- Write, Plan, Apply, And What Init Prepares — HashiCorp Terraform Associate (004) Exam Prep
- Remote State With The Backend Block — HashiCorp Terraform Associate (004) Exam Prep
- VCS, CLI And API Workflows: Speculative Plans And Run Triggers — HashiCorp Terraform Associate (004) Exam Prep