# Moving resources between remote states

Sometimes it's useful to be able to move resources between remote states without a need to recreate infrastructure. One use case is moving resources between directories.

`terraform state mv` command does not directly support remote states, but `-state` and `-state-out` parameters can be used against local states. This means remote states need to fetched first.

This can be done with for example `aws s3 cp` or `terraform state pull > local.tfstate`.

After both states are local, `state mv` command can be used in the following manner:

`terraform state mv -state=src.tfstate -state-out=dst.tfstate module.foo module.foo`

After this modified local state files need to pushed to remote storage, for example with:

`terraform state push /path/to/local/state`

## References:

* <https://github.com/hashicorp/terraform/pull/15652#issuecomment-410754814>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.tatusl.dev/terraform/moving-resources-between-remotes-states.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
