Reputation: 624
I create some resources with terraform: EC2, target group, autoscaling roup, load balancer and more... When I change some paramas, for example instance type, the current target group drain the targeted EC2 before the new EC2 are added. So I have a downtime. How can I change my terraform conf to prevent downtime?
In all resource I use:
lifecycle {
create_before_destroy = true
}
This is the module I call to create all resource I needed:
module "autoscaling_docker" {
source = "../../_/autoscaling_docker"
domain = local.domain
has_keychain = true
instance_type = "t3.medium"
name = "cluster-name"
...
The module autoscaling_docker create various resources like autoscaling group (and so ec2), alb and many more
This is my terraform target group:
resource "aws_lb_target_group" "me" {
name = "tg-tf-${var.name}"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "instance"
stickiness {
type = "lb_cookie"
cookie_duration = "300"
}
health_check {
enabled = true
healthy_threshold = 2
interval = 30
matcher = "200"
path = var.health_check_path
port = 80
protocol = "HTTP"
timeout = 5
unhealthy_threshold = 2
}
lifecycle {
create_before_destroy = true
}
deregistration_delay = "360"
}
Autoscaling group:
resource "aws_autoscaling_group" "me" {
...
lifecycle {
ignore_changes = [
desired_capacity
]
create_before_destroy = true
}
Upvotes: 0
Views: 200