github.com/pmcatominey/terraform@v0.7.0-rc2.0.20160708105029-1401a52a5cc5/website/source/docs/commands/state/mv.html.md (about) 1 --- 2 layout: "commands-state" 3 page_title: "Command: state mv" 4 sidebar_current: "docs-state-sub-mv" 5 description: |- 6 The `terraform state rm` command removes items from the Terraform state. 7 --- 8 9 # Command: state mv 10 11 The `terraform state mv` command is used to move items in a 12 [Terraform state](/docs/state/index.html). This command can move 13 single resources, single instances of a resource, entire modules, and more. 14 This command can also move items to a completely different state file, 15 enabling efficient refactoring. 16 17 ## Usage 18 19 Usage: `terraform state mv [options] SOURCE DESTINATION` 20 21 This command will move an item matched by the address given to the 22 destination address. This command can also move to a destination address 23 in a completely different state file. 24 25 This can be used for simple resource renaming, moving items to and from 26 a module, moving entire modules, and more. And because this command can also 27 move data to a completely new state, it can also be used for refactoring 28 one configuration into multiple separately managed Terraform configurations. 29 30 This command will output a backup copy of the state prior to saving any 31 changes. The backup cannot be disabled. Due to the destructive nature 32 of this command, backups are required. 33 34 If you're moving an item to a different state file, a backup will be created 35 for each state file. 36 37 This command requires a source and destination address of the item to move. 38 Addresses are 39 in [resource addressing format](/docs/commands/state/addressing.html). 40 41 The command-line flags are all optional. The list of available flags are: 42 43 * `-backup=path` - Path to a backup file Defaults to the state path plus 44 a timestamp with the ".backup" extension. 45 46 * `-backup-out=path` - Path to the backup file for the output state. 47 This is only necessary if `-state-out` is specified. 48 49 * `-state=path` - Path to the state file. Defaults to "terraform.tfstate". 50 51 * `-state-out=path` - Path to the state file to write to. If this isn't specified 52 the state specified by `-state` will be used. This can be 53 a new or existing path. 54 55 ## Example: Rename a Resource 56 57 The example below renames a single resource: 58 59 ``` 60 $ terraform state mv aws_instance.foo aws_instance.bar 61 ``` 62 63 ## Example: Move a Resource Into a Module 64 65 The example below moves a resource into a module. The module will be 66 created if it doesn't exist. 67 68 ``` 69 $ terraform state mv aws_instance.foo module.web 70 ``` 71 72 ## Example: Move a Module Into a Module 73 74 The example below moves a module into another module. 75 76 ``` 77 $ terraform state mv module.foo module.parent.module.foo 78 ``` 79 80 ## Example: Move a Module to Another State 81 82 The example below moves a module into another state file. This removes 83 the module from the original state file and adds it to the destination. 84 The source and destination are the same meaning we're keeping the same name. 85 86 ``` 87 $ terraform state mv -state-out=other.tfstate \ 88 module.web module.web 89 ```