Skip to content

Commit

Permalink
Edit docs for replace_triggered_by lifecycle argument (#31129)
Browse files Browse the repository at this point in the history
- Note that it was added in v1.2, so users know whether they can use it yet.
- Fix nested indentation formatting, so the parent list item stays together.
- Minor copy edits.
- List all of the available lifecycle block arguments before diving into the
  docs for each argument, for ease of reading/scanning.
  • Loading branch information
nfagerlund committed May 26, 2022
1 parent 903ba7e commit 5bf4895
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions website/docs/language/meta-arguments/lifecycle.mdx
Expand Up @@ -30,7 +30,8 @@ resource "azurerm_resource_group" "example" {
The `lifecycle` block and its contents are meta-arguments, available
for all `resource` blocks regardless of type.

The following arguments can be used within a `lifecycle` block:
The arguments available within a `lifecycle` block are `create_before_destroy`,
`prevent_destroy`, `ignore_changes`, and `replace_triggered_by`.

* `create_before_destroy` (bool) - By default, when Terraform must change
a resource argument that cannot be updated in-place due to
Expand Down Expand Up @@ -110,24 +111,33 @@ The following arguments can be used within a `lifecycle` block:
Only attributes defined by the resource type can be ignored.
`ignore_changes` cannot be applied to itself or to any other meta-arguments.

* `replace_triggered_by` (list of resource references) - Forces Terraform to replace the parent resource when there is a change to a referenced resource or resource attribute. Supply a list of expressions referencing managed resources, instances, or instance attributes. When the containing resource uses `count` or `for_each`, you can use `count.index` or `each.key` in the expression to index specific instances.
* `replace_triggered_by` (list of resource or attribute references) -
_Added in Terraform 1.2._ Replaces the resource when any of the referenced
items change. Supply a list of expressions referencing managed resources,
instances, or instance attributes. When used in a resource that uses `count`
or `for_each`, you can use `count.index` or `each.key` in the expression to
reference specific instances of other resources that are configured with the
same count or collection.

References trigger replacement in the following conditions:

References trigger replacement in the following conditions:
- If the reference is to a resource with multiple instances, a plan to
update or replace any instance will trigger replacement.
- If the reference is to a single resource instance, a plan to update or
replace that instance will trigger replacement.
- If the reference is to a single attribute of a resource instance, any
change to the attribute value will trigger replacement.

You can only reference managed resources in `replace_triggered_by` expressions. This lets you modify these expressions without forcing replacement.
You can only reference managed resources in `replace_triggered_by`
expressions. This lets you modify these expressions without forcing
replacement.

```hcl
resource "aws_appautoscaling_target" "ecs_target" {
# ...
lifecycle {
replace_triggered_by = [
# Replace `aws_appautoscaling_target` each time this instance of
# Replace `aws_appautoscaling_target` each time this instance of
# the `aws_ecs_service` is replaced.
aws_ecs_service.svc.id
]
Expand Down

0 comments on commit 5bf4895

Please sign in to comment.