Last active
September 2, 2016 19:35
-
-
Save sepulworld/c809e9183ebf741bbb0f8a3ce1234ba3 to your computer and use it in GitHub Desktop.
Terraform ASG and Launch Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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