Skip to content

Commit

Permalink
Merge pull request #35112 from hashicorp/docs/atrujillo/lang-add-move…
Browse files Browse the repository at this point in the history
…d-ref

added reference page for  block

Manully cherrypicking PR35112 updates to v1.5
  • Loading branch information
trujillo-adam committed May 7, 2024
1 parent 3e6a61c commit 5ebd620
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
15 changes: 15 additions & 0 deletions website/data/language-nav-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@
}
]
},
{
"title": "Moved block",
"path": "moved"
},
{ "title": "Checks", "path": "checks" },
{
"title": "Import",
"routes": [
{ "title": "Overview", "path": "import" },
{
"title": "Generating Configuration",
"path": "import/generating-configuration"
}
]
},
{
"title": "Expressions",
"routes": [
Expand Down
62 changes: 62 additions & 0 deletions website/docs/language/moved.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
page_title: moved block configuration reference
description: Learn about the `moved` block that you can specify in Terraform configurations. The `moved` block programmatically changes the location of a resource.
---

# Moved block configuration reference

This topic provides reference information for the `moved` block.

## Introduction

The `moved` block programmatically changes the address of a resource. Refer to [Refactoring](/terraform/language/modules/develop/refactoring) for details about how to use the `moved` block in your Terraform configurations.

## Configuration model

The following list outlines field hierarchy, language-specific data types, and requirements in the `moved` block.

- [`moved`](#moved): map
- [`from`](#moved): string
- [`to`](#moved): string

## Complete configuration

When every field is defined, a `moved` block has the following form:

```hcl
moved = {
from = <old address for the resource>
to = <new address for the resource>
}
```

## Specification

This section provides details about the fields you can configure in the `moved` block.

### `moved`

Map that specifies addresses for the resource. The following table describes the fields you can set in the `moved` block.

| Field | Description | Type | Required |
| --- | --- | --- | --- |
| `from` | Specifies a resource's previous address. The syntax allows Terraform to select modules, resources, and resources inside child modules. | string | required |
| `to` | Specifies the new address to relocate the resource to. The syntax allows Terraform to select modules, resources, and resources inside child modules. | string | required |

Before creating a new plan for the resource specified in the `to` field, Terraform checks the state for an existing object at the address specified in the `from` field. Terraform renames existing objects to the string specified in the `to` field and then creates a plan. The plan directs Terraform to provision the resource specified in the `from` field as the resource specified in the `to` field. As a result, Terraform does not destroy the resource during the Terraform run.

## Example

The following example moves an AWS instance from address `aws_instance.a` to `aws_instance.b`:

```hcl
moved {
from = aws_instance.a
to = aws_instance.b
}
```





0 comments on commit 5ebd620

Please sign in to comment.