Recall & Review
beginner
What does the
prevent_destroy lifecycle rule do in Terraform?It stops Terraform from deleting a resource, even if you run
terraform destroy or remove the resource from your configuration. This protects important resources from accidental deletion.Click to reveal answer
beginner
How do you enable the
prevent_destroy rule in a Terraform resource?Inside the resource block, add a
lifecycle block with prevent_destroy = true. For example:<br>resource "aws_s3_bucket" "example" {
lifecycle {
prevent_destroy = true
}
}Click to reveal answer
intermediate
Why is using
prevent_destroy considered a best practice for critical resources?Because it acts like a safety lock, preventing accidental deletion of resources that could cause downtime or data loss if removed unintentionally.
Click to reveal answer
beginner
What happens if you try to delete a resource with
prevent_destroy enabled?Terraform will show an error and stop the deletion process. You must first remove or disable
prevent_destroy to delete the resource.Click to reveal answer
intermediate
Can
prevent_destroy protect resources from manual deletion outside Terraform?No. It only protects resources managed by Terraform during Terraform operations. Manual deletion outside Terraform is not prevented by this rule.
Click to reveal answer
What is the purpose of the
prevent_destroy lifecycle rule in Terraform?✗ Incorrect
The
prevent_destroy rule stops Terraform from deleting a resource during destroy or update operations.How do you enable
prevent_destroy for a resource?✗ Incorrect
You enable it by adding
prevent_destroy = true inside the resource's lifecycle block.What happens if you try to delete a resource with
prevent_destroy enabled?✗ Incorrect
Terraform will stop and show an error to prevent accidental deletion.
Does
prevent_destroy protect resources from manual deletion outside Terraform?✗ Incorrect
It only prevents deletion during Terraform runs, not manual deletion outside Terraform.
Which of these is a good use case for
prevent_destroy?✗ Incorrect
Critical resources like databases should be protected from accidental deletion using
prevent_destroy.Explain how the
prevent_destroy lifecycle rule works in Terraform and why it is useful.Think about how to keep important things safe from being removed by mistake.
You got /4 concepts.
Describe a scenario where using
prevent_destroy would be important and how you would configure it.Consider resources that hold valuable data or services.
You got /4 concepts.