Challenge - 5 Problems
Terraform Prevent_destroy Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Configuration
intermediate2:00remaining
Identify the effect of prevent_destroy in this Terraform resource
Given the following Terraform resource configuration, what will happen if you try to run
terraform destroy on this resource?Terraform
resource "aws_s3_bucket" "example" { bucket = "my-unique-bucket-name" lifecycle { prevent_destroy = true } }
Attempts:
2 left
💡 Hint
Think about what the prevent_destroy lifecycle rule is designed to do.
✗ Incorrect
The prevent_destroy lifecycle rule tells Terraform to block any attempt to destroy the resource. This protects important resources from accidental deletion.
❓ service_behavior
intermediate2:00remaining
What happens if prevent_destroy is not set and you run terraform destroy?
Consider a Terraform resource without the prevent_destroy lifecycle rule. What is the expected behavior when running
terraform destroy?Terraform
resource "aws_instance" "web" { ami = "ami-12345678" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
What is the default behavior if no lifecycle rules are set?
✗ Incorrect
Without prevent_destroy, Terraform will destroy resources normally when you run terraform destroy.
❓ Architecture
advanced2:30remaining
Choose the correct lifecycle block to protect a resource from accidental deletion but allow updates
You want to protect an AWS RDS instance from being destroyed accidentally but still allow updates to its configuration. Which lifecycle block achieves this?
Attempts:
2 left
💡 Hint
Think about which lifecycle rule stops destruction but not updates.
✗ Incorrect
The prevent_destroy rule blocks resource deletion but allows updates to other attributes.
❓ security
advanced2:30remaining
What security risk does prevent_destroy help mitigate in Terraform-managed infrastructure?
How does setting prevent_destroy = true in a Terraform resource lifecycle block improve security?
Attempts:
2 left
💡 Hint
Consider what kind of mistakes or attacks could cause resource loss.
✗ Incorrect
prevent_destroy stops Terraform from deleting resources, protecting against accidental or malicious removal.
✅ Best Practice
expert3:00remaining
When should you NOT use prevent_destroy in Terraform lifecycle rules?
Which scenario is NOT a good reason to use prevent_destroy in a Terraform resource lifecycle block?
Attempts:
2 left
💡 Hint
Think about when destruction is expected or necessary.
✗ Incorrect
Using prevent_destroy on temporary resources that need regular deletion can cause deployment issues.