From 2297c76be54d5fed7fe633dbd303538a92a9a6bd Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 3 Jun 2024 17:18:30 -0400 Subject: [PATCH] add section for removed block provisioners --- website/docs/language/resources/syntax.mdx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/website/docs/language/resources/syntax.mdx b/website/docs/language/resources/syntax.mdx index 9408ca6dc6..827ed908e1 100644 --- a/website/docs/language/resources/syntax.mdx +++ b/website/docs/language/resources/syntax.mdx @@ -137,6 +137,25 @@ The `from` argument is the address of the resource you want to remove, without a The `lifecycle` block is required. The `destroy` argument determines whether Terraform will attempt to destroy the object managed by the resource or not. A value of `false` means that Terraform will remove the resource from state without destroying it. +A `removed` block may also contain a [Destroy-Time Provisioner](/terraform/language/resources/provisioners/syntax#destroy-time-provisioners), so that the provisioner can remain in the configuration even though the `resource` block has been removed. + +``` +removed { + from = aws_instance.example + + lifecycle { + destroy = true + } + + provisioner "local-exec" { + when = destroy + command = "echo 'Instance ${self.id} has been destroyed.'" + } +} +``` + +The same referencing rules apply as in normal destroy-time provisioners, with only `count.index`, `each.key`, and `self` allowed. The provisioner must specify `when = destroy`, and the `removed` block must use `destroy = true` in order for the provisioner to execute. + ## Custom Condition Checks You can use `precondition` and `postcondition` blocks to specify assumptions and guarantees about how the resource operates. The following example creates a precondition that checks whether the AMI is properly configured.