Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reference page for block #35112

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions website/data/language-nav-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@
}
]
},
{
"title": "Moved block",
"path": "moved"
},
{ "title": "Checks", "path": "checks" },
{
"title": "Import",
Expand Down
63 changes: 63 additions & 0 deletions website/docs/language/moved.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
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 resource.
trujillo-adam marked this conversation as resolved.
Show resolved Hide resolved
---

# 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

trujillo-adam marked this conversation as resolved.
Show resolved Hide resolved
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 the previous address of the resource addresses using a syntax that allows Terraform to select modules, resources, and resources inside child modules. | string | required |
trujillo-adam marked this conversation as resolved.
Show resolved Hide resolved
| `to` | Sepcifies the current address of the resource using a syntax that allows Terraform to select modules, resources, and resources inside child modules. | string | required |
trujillo-adam marked this conversation as resolved.
Show resolved Hide resolved

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 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.
trujillo-adam marked this conversation as resolved.
Show resolved Hide resolved

## Example

The following example moves and AWS instance from address `aws_instance.a` to `aws_instance.b`:
trujillo-adam marked this conversation as resolved.
Show resolved Hide resolved

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