github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/website/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 Ignored when [remote state](/docs/state/remote.html) is used. 51 52 * `-state-out=path` - Path to the state file to write to. If this isn't specified 53 the state specified by `-state` will be used. This can be 54 a new or existing path. Ignored when 55 [remote state](/docs/state/remote.html) is used. 56 57 ## Example: Rename a Resource 58 59 The example below renames a single resource: 60 61 ``` 62 $ terraform state mv aws_instance.foo aws_instance.bar 63 ``` 64 65 ## Example: Move a Resource Into a Module 66 67 The example below moves a resource into a module. The module will be 68 created if it doesn't exist. 69 70 ``` 71 $ terraform state mv aws_instance.foo module.web 72 ``` 73 74 ## Example: Move a Module Into a Module 75 76 The example below moves a module into another module. 77 78 ``` 79 $ terraform state mv module.foo module.parent.module.foo 80 ``` 81 82 ## Example: Move a Module to Another State 83 84 The example below moves a module into another state file. This removes 85 the module from the original state file and adds it to the destination. 86 The source and destination are the same meaning we're keeping the same name. 87 88 ``` 89 $ terraform state mv -state-out=other.tfstate \ 90 module.web module.web 91 ```