0
0
Terraformcloud~10 mins

Lifecycle customization 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 prevent Terraform from deleting the resource.

Terraform
resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"

  lifecycle {
    prevent_destroy = [1]
  }
}
Drag options to blanks, or click blank then click option'
A"true"
Btrue
Cfalse
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around true makes it a string, not a boolean.
Setting prevent_destroy to false allows deletion.
2fill in blank
medium

Complete the code to ignore changes to the 'tags' attribute.

Terraform
resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"

  lifecycle {
    ignore_changes = [[1]]
  }
}
Drag options to blanks, or click blank then click option'
A"tags"
B"ami"
C"instance_type"
D"user_data"
Attempts:
3 left
💡 Hint
Common Mistakes
Ignoring 'ami' would prevent updates to the image.
Ignoring 'instance_type' would block resizing the instance.
3fill in blank
hard

Fix the error in the lifecycle block to properly ignore changes to multiple attributes.

Terraform
resource "aws_db_instance" "db" {
  allocated_storage = 20
  engine            = "mysql"

  lifecycle {
    ignore_changes = [1]
  }
}
Drag options to blanks, or click blank then click option'
A[allocated_storage, engine]
B"allocated_storage, engine"
C["allocated_storage", "engine"]
D"[allocated_storage, engine]"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string with commas is invalid syntax.
Not quoting attribute names causes errors.
4fill in blank
hard

Fill both blanks to create a lifecycle rule that ignores changes to 'tags' and prevents resource replacement.

Terraform
resource "aws_lambda_function" "func" {
  function_name = "my-function"
  runtime       = "python3.8"

  lifecycle {
    ignore_changes = [[1]]
    [2] = true
  }
}
Drag options to blanks, or click blank then click option'
A"tags"
Bprevent_destroy
Ccreate_before_destroy
D"runtime"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create_before_destroy' instead of 'prevent_destroy' for deletion prevention.
Not quoting 'tags' in the list.
5fill in blank
hard

Fill all three blanks to create a lifecycle block that ignores changes to 'environment', prevents destroy, and enables create before destroy.

Terraform
resource "aws_ecs_service" "service" {
  name            = "my-service"
  desired_count   = 2

  lifecycle {
    ignore_changes     = [[1]]
    [2] = true
    [3] = true
  }
}
Drag options to blanks, or click blank then click option'
A"environment"
Bprevent_destroy
Ccreate_before_destroy
D"desired_count"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'prevent_destroy' and 'create_before_destroy' settings.
Not quoting the attribute name in the ignore_changes list.