0
0
Terraformcloud~10 mins

Creation-time vs destruction-time in Terraform - Interactive Practice

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

Complete the code to define a resource that creates an AWS S3 bucket.

Terraform
resource "aws_s3_bucket" "my_bucket" {
  bucket = "[1]"
  acl    = "private"
}
Drag options to blanks, or click blank then click option'
Abucket_name
Baws_s3_bucket
Cmy-unique-bucket-123
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using resource type name instead of bucket name
Using ACL value in bucket name field
2fill in blank
medium

Complete the code to add a lifecycle rule that prevents deletion of the S3 bucket during destruction-time.

Terraform
resource "aws_s3_bucket" "my_bucket" {
  bucket = "my-unique-bucket-123"
  acl    = "private"

  lifecycle {
    [1] = true
  }
}
Drag options to blanks, or click blank then click option'
Aprevent_destroy
Bcreate_before_destroy
Cignore_changes
Dreplace_triggered_by
Attempts:
3 left
💡 Hint
Common Mistakes
Using lifecycle arguments unrelated to destruction protection
Setting the wrong lifecycle argument name
3fill in blank
hard

Fix the error in the code that tries to reference a resource attribute at destruction-time, which is not allowed.

Terraform
output "bucket_name" {
  value = aws_s3_bucket.my_bucket.[1]
}
Drag options to blanks, or click blank then click option'
Atags
Barn
Cid
Dbucket
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing attributes that only exist after creation
Using resource IDs that may be null during destruction
4fill in blank
hard

Fill both blanks to create a resource with a creation-time computed attribute and a destruction-time lifecycle rule.

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

  [1] = true

  lifecycle {
    [2] = true
  }
}
Drag options to blanks, or click blank then click option'
Aassociate_public_ip_address
Bprevent_destroy
Cdisable_api_termination
Dcreate_before_destroy
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing lifecycle arguments with resource arguments
Using wrong lifecycle argument names
5fill in blank
hard

Fill all three blanks to define an output that depends on a creation-time attribute, uses a destruction-time lifecycle ignore change, and references the correct attribute.

Terraform
resource "aws_security_group" "sg" {
  name        = "example-sg"
  description = "Example security group"

  lifecycle {
    [1] = ["ingress"]
  }
}

output "sg_id" {
  value = aws_security_group.sg.[2]
  description = "Security group ID"
  depends_on = [aws_security_group.sg]
  [3] = true
}
Drag options to blanks, or click blank then click option'
Aignore_changes
Bid
Csensitive
Dprevent_destroy
Attempts:
3 left
💡 Hint
Common Mistakes
Using prevent_destroy in output block
Referencing attributes not available at creation-time
Not marking sensitive outputs when needed