We have a load balancer set up with several ec2 instances behind it. During a deploy, instances will be removed from the target group and updated before being placed back into the target group.
If terraform plan
is run while this is happening, it notices a diff in the target group attachment. This makes sense but it’s a bit of a nuisance, since it makes you think the plan is dirty even though the instance will be added back shortly when the deploy completes. What is the best way to tell terraform to ignore this diff? Code sample:
resource "aws_alb_target_group" "flask_nginx" {
name = "web-nginx"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
deregistration_delay = 5
health_check {
interval = 8
path = "/health"
port = 80
protocol = "http"
timeout = 7
healthy_threshold = 2
unhealthy_threshold = 5
matcher = "200"
}
target_type = "instance"
}
resource "aws_alb_target_group_attachment" "flask_nginx" {
target_group_arn = aws_alb_target_group.flask_nginx.arn
target_id = aws_instance.flask[count.index].id
count = var.instances
lifecycle {
ignore_changes = [target_id]
}
}