github.com/wikibal01/hashicorp-terraform@v0.11.12-beta1/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 mv` command moves items in 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 where Terraform should write the backup for the
    44    original state. This can't be disabled. If not set, Terraform will write it
    45    to the same path as the statefile with a ".backup" extension.
    46  
    47  * `-backup-out=path` - Path where Terraform should write the backup for the
    48    destination state. This can't be disabled. If not set, Terraform will write
    49    it to the same path as the destination state file with a backup extension.
    50    This only needs to be specified if -state-out is set to a different path than
    51    -state.
    52  
    53  * `-state=path` - Path to the source state file to read from. Defaults to the
    54    configured backend, or "terraform.tfstate".
    55  
    56  * `-state-out=path` - Path to the destination state file to write to. If this
    57    isn't specified the source state file will be used. This can be a new or
    58    existing path.
    59  
    60  ## Example: Rename a Resource
    61  
    62  The example below renames a single resource:
    63  
    64  ```
    65  $ terraform state mv aws_instance.foo aws_instance.bar
    66  ```
    67  
    68  ## Example: Move a Resource Into a Module
    69  
    70  The example below moves a resource into a module. The module will be
    71  created if it doesn't exist.
    72  
    73  ```
    74  $ terraform state mv aws_instance.foo module.web
    75  ```
    76  
    77  ## Example: Move a Module Into a Module
    78  
    79  The example below moves a module into another module.
    80  
    81  ```
    82  $ terraform state mv module.foo module.parent.module.foo
    83  ```
    84  
    85  ## Example: Move a Module to Another State
    86  
    87  The example below moves a module into another state file. This removes
    88  the module from the original state file and adds it to the destination.
    89  The source and destination are the same meaning we're keeping the same name.
    90  
    91  ```
    92  $ terraform state mv -state-out=other.tfstate \
    93      module.web module.web
    94  ```