Given the following Terraform resource configuration, what will happen when the resource is updated?
resource "aws_instance" "example" {
ami = "ami-123456"
instance_type = "t2.micro"
lifecycle {
create_before_destroy = true
}
}resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" lifecycle { create_before_destroy = true } }
Think about what the create_before_destroy lifecycle rule means for resource replacement.
The create_before_destroy lifecycle rule tells Terraform to create the replacement resource before destroying the existing one. This helps avoid downtime during resource replacement.
You want to update a cloud resource with zero downtime. Which lifecycle configuration should you use in Terraform?
Which lifecycle rule ensures the new resource is ready before the old one is removed?
The create_before_destroy rule ensures Terraform creates the new resource before destroying the old one, enabling zero downtime updates.
Consider two Terraform resources where one depends on the other. If the dependent resource has create_before_destroy = true, what is the expected behavior during replacement?
resource "aws_lb" "example_lb" { name = "example-lb" } resource "aws_lb_listener" "example_listener" { load_balancer_arn = aws_lb.example_lb.arn port = 80 protocol = "HTTP" lifecycle { create_before_destroy = true } }
Think about how create_before_destroy affects dependent resources and their availability.
The create_before_destroy lifecycle rule on the listener resource causes Terraform to create the new listener before destroying the old one, maintaining service availability.
What is a potential security risk when using create_before_destroy = true for resources like IAM roles or security groups?
Consider what happens when two versions of a sensitive resource exist simultaneously.
Using create_before_destroy can cause temporary duplication of sensitive resources like IAM roles, potentially increasing the attack surface until the old resource is destroyed.
You have a Terraform resource with create_before_destroy = true. When applying, Terraform fails with a "resource already exists" error. What is the most likely cause?
Think about what happens when two resources with the same unique ID exist simultaneously.
If the new resource tries to use the same unique identifier as the old one, create_before_destroy causes a conflict because both exist at the same time. The solution is to ensure unique IDs or use other strategies.