0
0
Terraformcloud~10 mins

Create_before_destroy lifecycle rule in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a lifecycle rule that creates the new resource before destroying the old one.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  lifecycle {
    create_before_destroy = [1]
  }
}
Drag options to blanks, or click blank then click option'
Ayes
Bfalse
Ctrue
Dno
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values like 'yes' or 'no' instead of boolean true/false.
Setting the value to false which disables create before destroy.
2fill in blank
medium

Complete the lifecycle block to ensure Terraform creates the replacement resource before destroying the current one.

Terraform
lifecycle {
  [1] = true
}
Drag options to blanks, or click blank then click option'
Acreate_before_destroy
Breplace_triggered_by
Cignore_changes
Dprevent_destroy
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing with prevent_destroy which stops destruction.
Using unrelated lifecycle attributes.
3fill in blank
hard

Fix the error in the lifecycle block to enable create_before_destroy behavior.

Terraform
lifecycle {
  create_before_destroy = [1]
}
Drag options to blanks, or click blank then click option'
Ano
Bfalse
Cyes
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around boolean values causing syntax errors.
Setting the value to false disables the behavior.
4fill in blank
hard

Fill both blanks to complete the lifecycle block that creates the new resource before destroying the old one and ignores changes to tags.

Terraform
lifecycle {
  [1] = true
  [2] = ["tags"]
}
Drag options to blanks, or click blank then click option'
Acreate_before_destroy
Bprevent_destroy
Cignore_changes
Dreplace_triggered_by
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up lifecycle attribute names.
Using incorrect values for ignoring changes.
5fill in blank
hard

Fill all three blanks to complete the lifecycle block that creates before destroy, prevents accidental destroy, and triggers replacement when user_data changes.

Terraform
lifecycle {
  [1] = true
  [2] = true
  [3] = ["user_data"]
}
Drag options to blanks, or click blank then click option'
Acreate_before_destroy
Bprevent_destroy
Creplace_triggered_by
Dignore_changes
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing replace_triggered_by with ignore_changes.
Forgetting to set booleans without quotes.