5. You want to replace a resource safely without downtime. Which lifecycle settings should you use to ensure the new resource is created before the old one is destroyed, and prevent accidental deletion?
hard
A. Set create_before_destroy = true and prevent_destroy = true
B. Set create_before_destroy = false and prevent_destroy = true
C. Set create_before_destroy = true and ignore_changes = [all]
D. Set prevent_destroy = false and ignore_changes = [all]
Solution
Step 1: Use create_before_destroy for safe replacement
This ensures the new resource is ready before the old one is removed, avoiding downtime.
Step 2: Use prevent_destroy to block accidental deletion
This stops Terraform from deleting the resource unless explicitly allowed, adding safety.
Final Answer:
Set create_before_destroy = true and prevent_destroy = true -> Option A