I am trying to update launch configuration user-data. But after apply, launch config is getting created and updated ASG. but running instance are still with old user-data. why so ?
Below are the launch config and ASG blocks.
resource "aws_launch_configuration" "BackEndWebLaunchConfig" {
name_prefix = "${var.component_name}-BackEndWebLaunchConfig"
user_data = file("user_data/${terraform.workspace}/vision-be-user-data.sh")
image_id = var.ASLCWEBAPPSAMI
instance_type = var.ASGWebAppsInstanceType
key_name = var.ssh_key_name
security_groups = [module.vpc.sgssh, aws_security_group.vision_backend_EC2SG.id]
root_block_device {
volume_size = var.EC2_EBS_SIZE
volume_type = "standard"
encrypted = true
}
#iam_instance_profile = var.EC2_instance_profile
associate_public_ip_address = false
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "vision_asg" {
name = "${var.component_name}-BackEnd-ASG-TF"
max_size = var.ASGWEBAPPSMaxSize
min_size = var.ASGWEBAPPSMinSize
health_check_grace_period = 300
force_delete = true
health_check_type = "ELB"
desired_capacity = var.ASGWEBAPPSDesiredSize
launch_configuration = aws_launch_configuration.BackEndWebLaunchConfig.name
target_group_arns = [module.loadbalancer.visionalb_ext_tg_arn]
vpc_zone_identifier = [module.vpc.PrivateSubnet0, module.vpc.PrivateSubnet1]
termination_policies = ["OldestInstance"]
lifecycle {
create_before_destroy = true
}
tags = [
{
key = "Name"
value = "${var.component_name}-BackEndWebASG-TF"
propagate_at_launch = true
},
{
key = "component"
value = var.component_name
propagate_at_launch = true
},
{
key = "tier"
value = "web"
propagate_at_launch = true
}
]
depends_on = [
aws_sns_topic.BackEndSNSTopic, aws_launch_configuration.BackEndWebLaunchConfig
]
}
After apply, new launch config is creating but ec2 machines are not refreshing.
aws_autoscaling_group.vision_asg: Refreshing state... [id=BackEnd-ASG-TF]
aws_autoscaling_policy.BEWebScaleUpPolicy: Refreshing state... [id=BEWebScaleUpPolicy]
aws_autoscaling_notification.vision_asg_notification: Refreshing state... [id=arn:aws:sns:us-east-1:193676128801:BackEndApplication-TF]
aws_autoscaling_policy.BEWebScaleDownPolicy: Refreshing state... [id=BEWebScaleDownPolicy]
aws_cloudwatch_metric_alarm.BEScaleDownNotifyAlarm: Refreshing state... [id=BEScaleDownNotifyAlarm]
aws_cloudwatch_metric_alarm.ScaleUPNotifyAlarm: Refreshing state... [id=ScaleUPNotifyAlarm]
aws_launch_configuration.BackEndWebLaunchConfig: Creating...
aws_launch_configuration.BackEndWebLaunchConfig: Creation complete after 8s [id=BackEndWebLaunchConfig20210508105416185400000001]
aws_autoscaling_group.vision_asg: Modifying... [id=BackEnd-ASG-TF]
aws_autoscaling_group.vision_asg: Modifications complete after 4s [id=BackEnd-ASG-TF]
aws_launch_configuration.BackEndWebLaunchConfig (2530c36e): Destroying... [id=BackEndWebLaunchConfig20210508103324724600000001]
aws_launch_configuration.BackEndWebLaunchConfig: Destruction complete after 2s
Apply complete! Resources: 1 added, 1 changed, 1 destroyed.
Outputs:
Please let me know, if i am doing something wrong.