Skip to content

Instantly share code, notes, and snippets.

@briceburg
Last active June 26, 2018 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briceburg/af16220f60ea5b2e971801277f30a827 to your computer and use it in GitHub Desktop.
Save briceburg/af16220f60ea5b2e971801277f30a827 to your computer and use it in GitHub Desktop.
terraform - autoscaling group that updates instances on changes
## random LC name is assigned
resource "aws_launch_configuration" "main" {
image_id = "${var.ami}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
security_group = ["${var.security_group}"]
}
## name triggers ASG replacement.
resource "aws_autoscaling_group" "main" {
lifecycle { create_before_destroy = true }
name = "someapp - ${aws_launch_configuration.main.name}"
launch_configuration = "${aws_launch_configuration.main.name}"
desired_capacity = "${var.nodes}"
min_size = "${var.nodes}"
max_size = "${var.nodes}"
min_elb_capacity = "${var.nodes}"
availability_zones = ["${split(",", var.azs)}"]
vpc_zone_identifier = ["${split(",", var.subnet_ids)}"]
load_balancers = ["${aws_elb.someapp.id}"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment