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 #11307

Closed
ghost opened this issue Dec 16, 2019 · 6 comments
Labels
service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@ghost
Copy link

ghost commented Dec 16, 2019

This issue was originally opened by @vivekyad4v as hashicorp/terraform#23685. It was migrated here as a result of the provider split. The original body of the issue is below.


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 ghost added service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service. labels Dec 16, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 16, 2019
@sanspace
Copy link

sanspace commented Jun 4, 2020

Did you find a workaround for this, @vivekyad4v?

@nbetm
Copy link

nbetm commented Jun 16, 2020

I run into the same problem today!

@liath
Copy link
Contributor

liath commented Nov 18, 2020

For others coming along late to this question, there's discussion of a fix (and a potential workaround!) here: #13785 (comment)

@liath
Copy link
Contributor

liath commented Dec 18, 2020

Even better, Instance Refresh support was added by #16678 so this can probably be closed!

@bflad bflad added this to the v3.22.0 milestone Dec 21, 2020
@bflad
Copy link
Contributor

bflad commented Dec 21, 2020

Auto Scaling Group instance refresh was indeed introduced with version 3.22.0 of the Terraform AWS Provider last week. Closing as this functionality, provided by AWS, would be the recommended solution in this case.

If you're looking for further general assistance, please note that we use GitHub issues in this repository for tracking bugs and enhancements with the Terraform AWS Provider codebase rather than for questions. While we may be able to help with certain simple problems here it's generally better to use the HashiCorp Community Forums where there are far more people ready to help, whereas the GitHub issues here are generally monitored only by a few maintainers and dedicated community members interested in code development of the Terraform AWS Provider itself.

@bflad bflad closed this as completed Dec 21, 2020
@ghost
Copy link
Author

ghost commented Jan 20, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jan 20, 2021
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests

5 participants