Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform (provider AWS) - Auto Scaling group doesn't take effect on a launch template change #23685

Closed
vivekyad4v opened this issue Dec 16, 2019 · 2 comments

Comments

@vivekyad4v
Copy link

Unable to make launch template work with ASGs while using launch templates, it works with Launch Configuration using a small hack i.e by interpolating the launch configuration name in ASG resource but it doesn't work with launch templates.
ASG uses the latest version to launch new instances but doesn't change anything w.r.t to pre-running instances inspite of a change in launch template.

I understand that this is sort of expected but do we have any workaround to make launch templates work with ASG or we need to stick to launch configuration itself?

resource "aws_launch_template" "lc_ec2" {
  image_id = "${var.ami_id}"
  instance_type = "${var.app_instance_type}"
  key_name = "${var.orgname}_${var.environ}_kp"
  vpc_security_group_ids = ["${aws_security_group.sg_ec2.id}"]
  user_data = "${base64encode(var.userdata)}"
  block_device_mappings {
    device_name = "/dev/xvdv"
    ebs {
      volume_size = 15
    }
  }
  iam_instance_profile {
    name = "${var.orgname}_${var.environ}_profile"
  }
  lifecycle {
    create_before_destroy = true
  }

  tag_specifications {
    resource_type = "instance"
    tags = "${merge(map("Name", format("%s-%s-lc-ec2", var.orgname, var.environ)), var.tags)}"
    } 
  tag_specifications {
    resource_type = "volume"
   tags = "${merge(map("Name", format("%s-%s-lc-ec2-volume", var.orgname, var.environ)), var.tags)}"
    }
  tags = "${merge(map("Name", format("%s-%s-lc-ec2", var.orgname, var.environ)), var.tags)}"
}

resource "aws_autoscaling_group" "asg_ec2" {
    name = "${var.orgname}-${var.environ}-asg-ec2-${aws_launch_template.lc_ec2.name}"

    vpc_zone_identifier = ["${data.aws_subnet.private.*.id}"]
    min_size  = 1
    desired_capacity  = 1
    max_size  = 1
    target_group_arns = ["${aws_lb_target_group.alb_tg.arn}"]
    default_cooldown= 100
    health_check_grace_period = 100
    termination_policies = ["ClosestToNextInstanceHour", "NewestInstance"]
    health_check_type="ELB"
    launch_template = {
      id = "${aws_launch_template.lc_ec2.id}"
      version = "$$Latest"
   }  
      lifecycle {
    create_before_destroy = true
  }

  tags = [
    {
      key                 = "Name"
      value               = "${var.orgname}"
      propagate_at_launch = true
    },
    {
      key                 = "Environ"
      value               = "${var.environ}"
      propagate_at_launch = true
    }
  ]
}

@ghost
Copy link

ghost commented Dec 16, 2019

This issue has been automatically migrated to hashicorp/terraform-provider-aws#11307 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to hashicorp/terraform-provider-aws#11307.

@ghost
Copy link

ghost commented Jan 16, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jan 16, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants