diff --git a/content/terraform/v1.12.x/docs/language/block/resource.mdx b/content/terraform/v1.12.x/docs/language/block/resource.mdx index 95194d4876..f0cde37be8 100644 --- a/content/terraform/v1.12.x/docs/language/block/resource.mdx +++ b/content/terraform/v1.12.x/docs/language/block/resource.mdx @@ -315,7 +315,7 @@ resource { You can specify the following lifecycle rules to manage how Terraform performs operations on the resource: - [`create_before_destroy`](#create_before_destroy): Terraform creates a replacement resource before destroying the current resource. -- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error. +- [`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). - [`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. - [`replace_triggered_by`](#replace-triggered_by): Terraform replaces the resource when any of the referenced resources or specified attributes change. - [`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 { Use this argument to prevent team members from accidentally replacing critical infrastructure, such as database instances. -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. +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. + +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). #### Summary diff --git a/content/terraform/v1.12.x/docs/language/meta-arguments.mdx b/content/terraform/v1.12.x/docs/language/meta-arguments.mdx index 89298d3f65..6a5f3fbf5f 100644 --- a/content/terraform/v1.12.x/docs/language/meta-arguments.mdx +++ b/content/terraform/v1.12.x/docs/language/meta-arguments.mdx @@ -180,7 +180,7 @@ The `lifecycle` block accepts a rule that customizes how Terraform performs the | Rule | Description | Terraform block | | --- | --- | --- | | `create_before_destroy` | Terraform creates a replacement resource before destroying the current resource. | `resource` | -| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. | `resource` | +| `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` | | `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` | | `replace_triggered_by` | Terraform replaces the resource when any of the referenced resources or specified attributes change. | `resource` | | `precondition` | Specifies a condition that Terraform evaluates before creating the resource. | `data`, `ephemeral`, `resource` | diff --git a/content/terraform/v1.13.x/docs/language/block/resource.mdx b/content/terraform/v1.13.x/docs/language/block/resource.mdx index 61c8f0b960..7b83432241 100644 --- a/content/terraform/v1.13.x/docs/language/block/resource.mdx +++ b/content/terraform/v1.13.x/docs/language/block/resource.mdx @@ -321,7 +321,7 @@ resource { You can specify the following lifecycle rules to manage how Terraform performs operations on the resource: - [`create_before_destroy`](#create_before_destroy): Terraform creates a replacement resource before destroying the current resource. -- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error. +- [`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). - [`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. - [`replace_triggered_by`](#replace-triggered_by): Terraform replaces the resource when any of the referenced resources or specified attributes change. - [`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 { Use this argument to prevent team members from accidentally replacing critical infrastructure, such as database instances. -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. +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. + +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). #### Summary diff --git a/content/terraform/v1.13.x/docs/language/meta-arguments.mdx b/content/terraform/v1.13.x/docs/language/meta-arguments.mdx index d66d68ffeb..c6dbb8a24c 100644 --- a/content/terraform/v1.13.x/docs/language/meta-arguments.mdx +++ b/content/terraform/v1.13.x/docs/language/meta-arguments.mdx @@ -186,7 +186,7 @@ The `lifecycle` block accepts a rule that customizes how Terraform performs the | Rule | Description | Terraform block | | --- | --- | --- | | `create_before_destroy` | Terraform creates a replacement resource before destroying the current resource. | `resource` | -| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. | `resource` | +| `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` | | `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` | | `replace_triggered_by` | Terraform replaces the resource when any of the referenced resources or specified attributes change. | `resource` | | `precondition` | Specifies a condition that Terraform evaluates before creating the resource. | `data`, `ephemeral`, `resource` | diff --git a/content/terraform/v1.14.x (beta)/docs/language/block/resource.mdx b/content/terraform/v1.14.x (beta)/docs/language/block/resource.mdx index 472d5adcf5..72930ed7a1 100644 --- a/content/terraform/v1.14.x (beta)/docs/language/block/resource.mdx +++ b/content/terraform/v1.14.x (beta)/docs/language/block/resource.mdx @@ -330,7 +330,7 @@ You can specify the following lifecycle rules to manage how Terraform performs o - [`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. - [`create_before_destroy`](#create_before_destroy): Terraform creates a replacement resource before destroying the current resource. -- [`prevent_destroy`](#prevent_destroy): Terraform rejects operations to destroy the resource and returns an error. +- [`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). - [`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. - [`replace_triggered_by`](#replace-triggered_by): Terraform replaces the resource when any of the referenced resources or specified attributes change. - [`precondition`](#precondition): Specifies a condition that Terraform evaluates before creating the resource. Refer to [Validate your configuration](/terraform/language/validate) for more information. diff --git a/content/terraform/v1.14.x (beta)/docs/language/meta-arguments.mdx b/content/terraform/v1.14.x (beta)/docs/language/meta-arguments.mdx index 682a8ef7ec..ba8a5bc6a6 100644 --- a/content/terraform/v1.14.x (beta)/docs/language/meta-arguments.mdx +++ b/content/terraform/v1.14.x (beta)/docs/language/meta-arguments.mdx @@ -185,17 +185,26 @@ Terraform performs the following operations when you apply a configuration: 1. Creates resources defined in the configuration that are not associated with a real infrastructure object in the state. 1. Destroys resources that exist in the state but not in the configuration. 1. Updates in-place resources whose arguments have changed. -1. Destroys and re-create resources whose arguments have changed but that Terraform cannot update in-place because of remote API limitations. +1. Destroys and re-creates resources whose arguments have changed but that Terraform cannot update in-place because of remote API limitations. 1. Invokes actions that are configured to run during an apply operation. -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: +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. +### State + +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. + +Terraform records the results of `precondition` and `postcondition` checks to state, but not the contents of the checks. + +### Rules + +The following table describes support for each `lifecycle` rule: | Rule | Description | Terraform block | | --- | --- | --- | | `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` | | `create_before_destroy` | Terraform creates a replacement resource before destroying the current resource. | `resource` | -| `prevent_destroy` | Terraform rejects operations to destroy the resource and returns an error. | `resource` | +| `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` | | `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` | | `replace_triggered_by` | Terraform replaces the resource when any of the referenced resources or specified attributes change. | `resource` | | `precondition` | Specifies a condition that Terraform evaluates before creating the resource. | `data`, `ephemeral`, `resource` |