Skip to content

Commit a7e5e21

Browse files
IPE-1272-Review-and-update-prevent_destroy-directive-docs (#1095)
This PR addresses feedback in [issue 17599](hashicorp/terraform#17599)
2 parents 21f391a + 5d9b9e0 commit a7e5e21

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

content/terraform/v1.12.x/docs/language/block/resource.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ resource {
315315
You can specify the following lifecycle rules to manage how Terraform performs operations on the resource:
316316

317317
- [`create_before_destroy`](#create_before_destroy): Terraform creates a replacement resource before destroying the current resource.
318-
- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error.
318+
- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error. This rule doesn't prevent Terraform from destroying the resource if you remove the resource configuration. For instructions on how to remove a resource from state without destroying the actual resource, refer to [Remove a resource from state](/terraform/language/state/remove).
319319
- [`ignore_changes`](#ignore_changes): Specifies a list of resource attributes that Terraform ignores changes to. Otherwise, Terraform attempts to update the actual resource to match the configuration.
320320
- [`replace_triggered_by`](#replace-triggered_by): Terraform replaces the resource when any of the referenced resources or specified attributes change.
321321
- [`precondition`](#precondition): Specifies a condition that Terraform evaluates before creating the resource. Refer to [Validate your configuration](/terraform/language/validate) for more information.
@@ -369,7 +369,9 @@ resource {
369369

370370
Use this argument to prevent team members from accidentally replacing critical infrastructure, such as database instances.
371371

372-
When the `prevent_destroy` argument is set, you must either remove the resource from the configuration or change the `prevent_destroy` argument to `false` to destroy it. Use this argument with caution. The `prevent_destroy` argument can make applying resource changes or destroying resources more complex.
372+
When `prevent_destroy` is enabled, you must either remove the resource from the configuration or change the `prevent_destroy` argument to `false` to destroy it. Use this argument with caution. The `prevent_destroy` argument can make applying resource changes or destroying resources more complex.
373+
374+
This rule doesn't prevent Terraform from destroying the resource if you remove the resource configuration. For instructions on how to remove a resource from state without destroying the actual resource, refer to [Remove a resource from state](/terraform/language/state/remove).
373375

374376
#### Summary
375377

content/terraform/v1.12.x/docs/language/meta-arguments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ The `lifecycle` block accepts a rule that customizes how Terraform performs the
180180
| Rule | Description | Terraform block |
181181
| --- | --- | --- |
182182
| `create_before_destroy` | Terraform creates a replacement resource before destroying the current resource. | `resource` |
183-
| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. | `resource` |
183+
| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. This rule doesn't prevent Terraform from destroying the resource if you remove the resource configuration. For instructions on how to remove a resource from state without destroying the actual resource, refer to [Remove a resource from state](/terraform/language/state/remove). | `resource` |
184184
| `ignore_changes` | Specifies a list of resource attributes that Terraform ignores changes to. Otherwise, Terraform attempts to update the actual resource to match the configuration. | `resource` |
185185
| `replace_triggered_by` | Terraform replaces the resource when any of the referenced resources or specified attributes change. | `resource` |
186186
| `precondition` | Specifies a condition that Terraform evaluates before creating the resource. | `data`, `ephemeral`, `resource` |

content/terraform/v1.13.x/docs/language/block/resource.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ resource {
321321
You can specify the following lifecycle rules to manage how Terraform performs operations on the resource:
322322

323323
- [`create_before_destroy`](#create_before_destroy): Terraform creates a replacement resource before destroying the current resource.
324-
- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error.
324+
- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error. This rule doesn't prevent Terraform from destroying the resource if you remove the resource configuration. For instructions on how to remove a resource from state without destroying the actual resource, refer to [Remove a resource from state](/terraform/language/state/remove).
325325
- [`ignore_changes`](#ignore_changes): Specifies a list of resource attributes that Terraform ignores changes to. Otherwise, Terraform attempts to update the actual resource to match the configuration.
326326
- [`replace_triggered_by`](#replace-triggered_by): Terraform replaces the resource when any of the referenced resources or specified attributes change.
327327
- [`precondition`](#precondition): Specifies a condition that Terraform evaluates before creating the resource. Refer to [Validate your configuration](/terraform/language/validate) for more information.
@@ -375,7 +375,9 @@ resource {
375375

376376
Use this argument to prevent team members from accidentally replacing critical infrastructure, such as database instances.
377377

378-
When the `prevent_destroy` argument is set, you must either remove the resource from the configuration or change the `prevent_destroy` argument to `false` to destroy it. Use this argument with caution. The `prevent_destroy` argument can make applying resource changes or destroying resources more complex.
378+
When `prevent_destroy` is enabled, you must either remove the resource from the configuration or change the `prevent_destroy` argument to `false` to destroy it. Use this argument with caution. The `prevent_destroy` argument can make applying resource changes or destroying resources more complex.
379+
380+
This rule doesn't prevent Terraform from destroying the resource if you remove the resource configuration. For instructions on how to remove a resource from state without destroying the actual resource, refer to [Remove a resource from state](/terraform/language/state/remove).
379381

380382
#### Summary
381383

content/terraform/v1.13.x/docs/language/meta-arguments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ The `lifecycle` block accepts a rule that customizes how Terraform performs the
186186
| Rule | Description | Terraform block |
187187
| --- | --- | --- |
188188
| `create_before_destroy` | Terraform creates a replacement resource before destroying the current resource. | `resource` |
189-
| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. | `resource` |
189+
| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. This rule doesn't prevent Terraform from destroying a resource if you remove its configuration. Refer to [Remove a resource from state](/terraform/language/state/remove) for instructions on how to remove a resource from state without destroying the actual resource. | `resource` |
190190
| `ignore_changes` | Specifies a list of resource attributes that Terraform ignores changes to. Otherwise, Terraform attempts to update the actual resource to match the configuration. | `resource` |
191191
| `replace_triggered_by` | Terraform replaces the resource when any of the referenced resources or specified attributes change. | `resource` |
192192
| `precondition` | Specifies a condition that Terraform evaluates before creating the resource. | `data`, `ephemeral`, `resource` |

content/terraform/v1.14.x (beta)/docs/language/block/resource.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ You can specify the following lifecycle rules to manage how Terraform performs o
330330

331331
- [`action_trigger](#action_trigger)`: Specifies a set of arguments that determine which events trigger one or more provider actions, under which conditions the action runs, and which actions Terraform invokes.
332332
- [`create_before_destroy`](#create_before_destroy): Terraform creates a replacement resource before destroying the current resource.
333-
- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error.
333+
- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error. This rule doesn't prevent Terraform from destroying the resource if you remove the resource configuration. For instructions on how to remove a resource from state without destroying the actual resource, refer to [Remove a resource from state](/terraform/language/state/remove).
334334
- [`ignore_changes`](#ignore_changes): Specifies a list of resource attributes that Terraform ignores changes to. Otherwise, Terraform attempts to update the actual resource to match the configuration.
335335
- [`replace_triggered_by`](#replace-triggered_by): Terraform replaces the resource when any of the referenced resources or specified attributes change.
336336
- [`precondition`](#precondition): Specifies a condition that Terraform evaluates before creating the resource. Refer to [Validate your configuration](/terraform/language/validate) for more information.

content/terraform/v1.14.x (beta)/docs/language/meta-arguments.mdx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,26 @@ Terraform performs the following operations when you apply a configuration:
185185
1. Creates resources defined in the configuration that are not associated with a real infrastructure object in the state.
186186
1. Destroys resources that exist in the state but not in the configuration.
187187
1. Updates in-place resources whose arguments have changed.
188-
1. Destroys and re-create resources whose arguments have changed but that Terraform cannot update in-place because of remote API limitations.
188+
1. Destroys and re-creates resources whose arguments have changed but that Terraform cannot update in-place because of remote API limitations.
189189
1. Invokes actions that are configured to run during an apply operation.
190190

191-
The `lifecycle` block accepts a rule that customizes how Terraform performs the lifecycle stages for each resource. Support for each `lifecycle` rule varies across Terraform configuration blocks. Refer to the reference documentation for the Terraform block you are adding to your configuration for details. The following table describes support for each `lifecycle` rule:
191+
The `lifecycle` block accepts a rule that customizes how Terraform performs the lifecycle stages for each resource. Support for each `lifecycle` rule varies across Terraform configuration blocks. Refer to the reference documentation for the Terraform block you are adding to your configuration for details.
192192

193+
### State
194+
195+
Except for `create_before_destroy`, Terraform does not explicitly record a resource's `lifecycle` rule to state. As a result, Terraform destroys the actual infrastructure during an apply operation if you remove the resource's configuration, even if `prevent_destroy` is enabled. Refer to [Remove a resource from state](/terraform/language/state/remove) for instructions on how to remove a resource from state without destroying the actual resource.
196+
197+
Terraform records the results of `precondition` and `postcondition` checks to state, but not the contents of the checks.
198+
199+
### Rules
200+
201+
The following table describes support for each `lifecycle` rule:
193202

194203
| Rule | Description | Terraform block |
195204
| --- | --- | --- |
196205
| `action_trigger` | Terraform runs the configured action when the specified conditions are met. Refer to [Invoke an action](/terraform/language/invoke-actions) for details. | `resource` |
197206
| `create_before_destroy` | Terraform creates a replacement resource before destroying the current resource. | `resource` |
198-
| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. | `resource` |
207+
| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. This rule doesn't prevent Terraform from destroying a resource if you remove its configuration. Refer to [Remove a resource from state](/terraform/language/state/remove) for instructions on how to remove a resource from state without destroying the actual resource. | `resource` |
199208
| `ignore_changes` | Specifies a list of resource attributes that Terraform ignores changes to. Otherwise, Terraform attempts to update the actual resource to match the configuration. | `resource` |
200209
| `replace_triggered_by` | Terraform replaces the resource when any of the referenced resources or specified attributes change. | `resource` |
201210
| `precondition` | Specifies a condition that Terraform evaluates before creating the resource. | `data`, `ephemeral`, `resource` |

0 commit comments

Comments
 (0)