Hi!
We recently migrated from Launch Configurations to Launch Templates in our Terraform project.
We noticed that with every plan the latest_version
of Launch Templates gets updated even though nothing has changed, thus making the Auto Scaling groups updated and triggering at every apply. This is not very convenient and it’s becoming a big problem.
We’ve tried to apply the patch written in this GitHub issue (removing ignore_changes
lifecycle hook) without any success.
Do anyone know a way to fix this problem? Terraform code below. Thanks!
resource "aws_launch_template" "me" {
name_prefix = "lt-tf-${var.name}-"
image_id = var.ami
instance_type = var.instance_type
key_name = var.key_name
user_data = var.userdata != "" ? base64encode(var.userdata) : base64encode(local.userdata)
iam_instance_profile {
name = aws_iam_instance_profile.me.name
}
network_interfaces {
associate_public_ip_address = true
security_groups = var.security_groups_ec2
}
monitoring {
enabled = true
}
ebs_optimized = var.ebs_optimized
block_device_mappings {
device_name = var.ebs_volume_type != null ? var.ebs_device_name : null
dynamic "ebs" {
for_each = var.ebs_volume_type != null ? [1] : []
content {
volume_type = var.ebs_volume_type
}
}
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "me" {
name = "as-tf-${var.name}"
min_size = var.autoscaling_min_size
#desired_capacity = definita dalle policy
max_size = var.autoscaling_max_size
health_check_grace_period = 300
health_check_type = var.health_check_type
default_cooldown = 300
force_delete = true
launch_template {
id = aws_launch_template.me.id
version = aws_launch_template.me.latest_version
}
target_group_arns = var.domain != "" ? [module.alb[0].target_group_arn] : [module.target_group[0].tg_arn]
service_linked_role_arn = "arn:aws:iam::${var.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
enabled_metrics = [
/* ... */
]
vpc_zone_identifier = var.subnets
tag {
key = "Name"
propagate_at_launch = true
value = "${var.name} (autoscaling tf)"
}
tag {
key = "service"
propagate_at_launch = true
value = var.name
}
tag {
key = "cluster"
propagate_at_launch = true
value = var.name
}
dynamic "tag" {
for_each = var.tags-ec2
content {
key = tag.value.key
value = tag.value.value
propagate_at_launch = true
}
}
lifecycle {
create_before_destroy = true
}
instance_refresh {
strategy = "Rolling"
preferences {
instance_warmup = "300"
min_healthy_percentage = "50"
}
triggers = ["tag"]
}
}
Terraform Plan output: