Search⌘ K
AI Features

Moving Items in Terraform State

Explore how to use the terraform state mv command to move resources, instances, or modules between state files without destroying infrastructure. Learn to rename resources and reorganize configurations safely, ensuring updates require no recreation.

The mv subcommand

The terraform state mv command is used to move items in a Terraform state.

Syntax

The mv subcommand has the following syntax: terraform state mv [options] SOURCE DESTINATION.

Arguments

Within the options, there are a few important flags to highlight.

  • The dry-run flag can be thought of as a what-if. It tells us what it’ll do without making any changes.

  • The state flag is the path of the source state file, which needs to be specified if we’re not using the terraform.tfstate file or a remote back-end.

  • The state-out flag is the path of the destination file. Terraform uses the source state file unless this ...