Complete the code to add a lifecycle rule that creates the new resource before destroying the old one.
resource "aws_instance" "example" { ami = "ami-12345678" instance_type = "t2.micro" lifecycle { create_before_destroy = [1] } }
The create_before_destroy lifecycle rule must be set to true to ensure the new resource is created before the old one is destroyed.
Complete the lifecycle block to ensure Terraform creates the replacement resource before destroying the current one.
lifecycle {
[1] = true
}prevent_destroy which stops destruction.The create_before_destroy attribute tells Terraform to create the new resource before destroying the old one.
Fix the error in the lifecycle block to enable create_before_destroy behavior.
lifecycle {
create_before_destroy = [1]
}The value must be a boolean true without quotes, not a string. Remove the quotes to fix the error.
Fill both blanks to complete the lifecycle block that creates the new resource before destroying the old one and ignores changes to tags.
lifecycle {
[1] = true
[2] = ["tags"]
}create_before_destroy = true ensures the new resource is created first. ignore_changes = ["tags"] tells Terraform to ignore tag changes.
Fill all three blanks to complete the lifecycle block that creates before destroy, prevents accidental destroy, and triggers replacement when user_data changes.
lifecycle {
[1] = true
[2] = true
[3] = ["user_data"]
}replace_triggered_by with ignore_changes.create_before_destroy = true creates new resource first. prevent_destroy = true stops accidental deletion. replace_triggered_by = ["user_data"] forces replacement if user_data changes.