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.
We'll cover the following...
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-runflag can be thought of as a what-if. It tells us what it’ll do without making any changes. -
The
stateflag is the path of the source state file, which needs to be specified if we’re not using theterraform.tfstatefile or a remote back-end. -
The
state-outflag is the path of the destination file. Terraform uses the source state file unless this ...