Skip to content

Instantly share code, notes, and snippets.

@sepulworld
Last active September 2, 2016 19:35
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 sepulworld/c809e9183ebf741bbb0f8a3ce1234ba3 to your computer and use it in GitHub Desktop.
Save sepulworld/c809e9183ebf741bbb0f8a3ce1234ba3 to your computer and use it in GitHub Desktop.
Terraform ASG and Launch Config
resource "aws_launch_configuration" "lc" {
lifecycle { create_before_destroy = true }
image_id = "${var.ami_version}"
instance_type = "${var.instance_type}"
iam_instance_profile = "${var.service_name}-${var.environment}"
key_name = "${var.key_name}"
security_groups = ["${aws_security_group.sg1.id}"]
user_data = "user-data.sh"
depends_on = ["aws_iam_instance_profile.service_instance_profile"]
}
resource "aws_autoscaling_group" "asg" {
lifecycle { create_before_destroy = true }
# We generate a name that includes the launch config name to force a recreate
name = "asg-${var.service_name}-${var.environment}-${aws_launch_configuration.lc.name}"
availability_zones = ["${split(",", var.availability_zones)}"]
health_check_grace_period = "${var.health_check_grace_period}"
health_check_type = "${var.health_check_type}"
launch_configuration = "${aws_launch_configuration.lc.id}"
vpc_zone_identifier = ["${element(split(",", data.terraform_remote_state.core.core_public_subnets), 0)},${element(split(",", data.terraform_remote_state.core.core_public_subnets), 1)},${element(split(",", data.terraform_remote_state.core.core_public_subnets), 2)}"]
max_size = "${var.asg_max_instances}"
min_size = "${var.asg_min_instances}"
tag {
key = "Name"
value = "asg-${var.service_name}-${var.environment}-${aws_launch_configuration.lc.name}"
propagate_at_launch = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment