2020-10-27 02:15:36 +01:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "Moving Resources - Terraform CLI"
|
2021-07-23 20:53:20 +02:00
|
|
|
description: "Commands that allow you to manage the way that resources are tracked in state. They are helpful when you move or change resources."
|
2020-10-27 02:15:36 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# Moving Resources
|
|
|
|
|
|
|
|
Terraform's state associates each real-world object with a configured resource
|
2021-01-19 22:43:01 +01:00
|
|
|
at a specific [resource address](/docs/cli/state/resource-addressing.html). This
|
2020-10-27 02:15:36 +01:00
|
|
|
is seamless when changing a resource's attributes, but Terraform will lose track
|
|
|
|
of a resource if you change its name, move it to a different module, or change
|
|
|
|
its provider.
|
|
|
|
|
|
|
|
Usually that's fine: Terraform will destroy the old resource, replace it with a
|
|
|
|
new one (using the new resource address), and update any resources that rely on
|
|
|
|
its attributes.
|
|
|
|
|
|
|
|
In cases where it's important to preserve an existing infrastructure object, you
|
|
|
|
can explicitly tell Terraform to associate it with a different configured
|
|
|
|
resource.
|
|
|
|
|
2021-01-19 22:43:01 +01:00
|
|
|
- [The `terraform state mv` command](/docs/cli/commands/state/mv.html) changes
|
2020-10-27 02:15:36 +01:00
|
|
|
which resource address in your configuration is associated with a particular
|
|
|
|
real-world object. Use this to preserve an object when renaming a resource, or
|
|
|
|
when moving a resource into or out of a child module.
|
|
|
|
|
2021-01-19 22:43:01 +01:00
|
|
|
- [The `terraform state rm` command](/docs/cli/commands/state/rm.html) tells
|
2020-10-27 02:15:36 +01:00
|
|
|
Terraform to stop managing a resource as part of the current working directory
|
|
|
|
and workspace, _without_ destroying the corresponding real-world object. (You
|
|
|
|
can later use `terraform import` to start managing that resource in a
|
|
|
|
different workspace or a different Terraform configuration.)
|
|
|
|
|
2021-01-19 22:43:01 +01:00
|
|
|
- [The `terraform state replace-provider` command](/docs/cli/commands/state/replace-provider.html)
|
2020-10-27 02:15:36 +01:00
|
|
|
transfers existing resources to a new provider without requiring them to be
|
|
|
|
re-created.
|