Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save howdoicomputer/f651b1a8610d2d3ebbee6310ec8df867 to your computer and use it in GitHub Desktop.
Save howdoicomputer/f651b1a8610d2d3ebbee6310ec8df867 to your computer and use it in GitHub Desktop.
resource "aws_autoscaling_group" "mars_service" {
vpc_zone_identifier = ["${aws_subnet.main.*.id}"]
name = "mars_service_${var.environment} - ${aws_launch_configuration.mars_service.name}"
max_size = 2
min_size = 1
wait_for_elb_capacity = 1
wait_for_capacity_timeout = 0
health_check_grace_period = 300
desired_capacity = 1
launch_configuration = "${aws_launch_configuration.mars_service.name}"
load_balancers = ["${aws_elb.mars_service.name}"]
lifecycle {
create_before_destroy = true
}
tag {
key = "Environment"
value = "${var.environment}"
propagate_at_launch = true
}
tag {
key = "Terraform"
value = "true"
propagate_at_launch = true
}
tag {
key = "Name"
value = "mars_${var.environment}"
propagate_at_launch = true
}
tag {
key = "DomainMeta"
value = "${var.dns_zone_id}:${var.mars_dns_record}"
propagate_at_launch = true
}
}
resource "aws_autoscaling_notification" "route53switcher" {
group_names = [
"${aws_autoscaling_group.mars_service.name}"
]
notifications = [
"autoscaling:EC2_INSTANCE_LAUNCH",
"autoscaling:EC2_INSTANCE_TERMINATE"
]
topic_arn = "${aws_sns_topic.route53switcher.arn}"
}
resource "aws_sns_topic_subscription" "autoscaling_triggers_route53_lambda" {
topic_arn = "${aws_sns_topic.route53switcher.arn}"
protocol = "lambda"
endpoint = "${aws_lambda_function.route53switcher.arn}"
}
resource "aws_autoscaling_notification" "eni_switcher" {
group_names = [
"${aws_autoscaling_group.mars_service.name}"
]
notifications = [
"autoscaling:EC2_INSTANCE_LAUNCH"
]
topic_arn = "${aws_sns_topic.eni_switcher.arn}"
}
resource "aws_sns_topic_subscription" "autoscaling_triggers_eni_lambda" {
topic_arn = "${aws_sns_topic.eni_switcher.arn}"
protocol = "lambda"
endpoint = "${aws_lambda_function.eni_switcher.arn}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment