Skip to content

Instantly share code, notes, and snippets.

@kszarek
Created November 11, 2015 21:28
Show Gist options
  • Save kszarek/c3d9154b1a8645021d11 to your computer and use it in GitHub Desktop.
Save kszarek/c3d9154b1a8645021d11 to your computer and use it in GitHub Desktop.
Route53 healtchecks terraform configuration
resource "aws_security_group" "partner-api" {
name = "partner-api-${var.environment}"
description = "the security group for partner-api ${var.environment}"
vpc_id = "${aws_vpc.main.id}"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
security_groups = ["${aws_security_group.vpn.id}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_eip" "partner-api-A" {
count = "${var.instance_count-partner-api-A}"
# instance = "${element(aws_instance.partner-api-A.*.id, count.index)}"
vpc = true
}
resource "aws_eip" "partner-api-B" {
count = "${var.instance_count-partner-api-B}"
# instance = "${element(aws_instance.partner-api-A.*.id, count.index)}"
vpc = true
}
output "partner-api-A.public_ip" {
value = "${join(" ", aws_eip.partner-api-A.*.public_ip)}"
}
output "partner-api-B.public_ip" {
value = "${join(" ", aws_eip.partner-api-B.*.public_ip)}"
}
resource "aws_route53_health_check" "partner-api-A" {
ip_address = "${aws_eip.partner-api-A.0.public_ip}"
port = 80
type = "TCP"
failure_threshold = "1"
request_interval = "10"
tags = {
Name = "partner-api-A-${var.environment}"
Environment = "${var.environment}"
Role = "partner-api"
}
}
resource "aws_route53_health_check" "partner-api-B" {
ip_address = "${aws_eip.partner-api-B.0.public_ip}"
port = 80
type = "TCP"
failure_threshold = "1"
request_interval = "10"
tags = {
Name = "partner-api-B-${var.environment}"
Environment = "${var.environment}"
Role = "partner-api"
}
}
resource "aws_route53_record" "partner-api" {
zone_id = "${aws_route53_zone.internal.zone_id}"
name = "partner-api-${var.environment}.ahinternal.net"
type = "A"
alias {
name = "${aws_elb.elb-mainlb.dns_name}"
zone_id = "${aws_elb.elb-mainlb.zone_id}"
evaluate_target_health = false
}
}
# resource "aws_route53_record" "partner-api-A" {
# zone_id = "${aws_route53_zone.internal.zone_id}"
# name = "partner-api-${var.environment}"
# type = "A"
# ttl = "10"
# weight = 1
# set_identifier = "partner-api-A-${var.environment}"
# health_check_id = "${aws_route53_health_check.partner-api-A.id}"
# records = ["${aws_eip.partner-api-A.0.public_ip}"]
# }
# resource "aws_route53_record" "partner-api-B" {
# zone_id = "${aws_route53_zone.internal.zone_id}"
# name = "partner-api-${var.environment}"
# type = "A"
# ttl = "10"
# weight = 1
# set_identifier = "partner-api-B-${var.environment}"
# health_check_id = "${aws_route53_health_check.partner-api-B.id}"
# records = ["${aws_eip.partner-api-B.0.public_ip}"]
# }
# // EC2 instance definition
# resource "aws_instance" "partner-api-A" {
# disable_api_termination = false
# count = "${var.instance_count-partner-api-A}"
# ami = "${lookup(var.default_ami, count.index+10)}"
# instance_type = "t2.micro"
# monitoring = false
# key_name = "airhelp_${var.aws_region}"
# vpc_security_group_ids = ["${aws_security_group.default.id}", "${aws_security_group.partner-api.id}"]
# subnet_id = "${aws_subnet.a.id}"
# associate_public_ip_address = true
# user_data = "${element(template_file.user_data_partner-api-A.*.rendered, count.index)}"
# iam_instance_profile = "default"
# root_block_device {
# volume_size = 20
# volume_type = "standard"
# }
# tags {
# Name = "${format("partner-api%d-%s", count.index+10, var.environment)}"
# Environment = "${var.environment}"
# Role = "partner-api"
# Creator = "terraform"
# }
# lifecycle {
# create_before_destroy = true
# }
# provisioner "remote-exec" {
# connection {
# user = "ubuntu"
# type = "ssh"
# host = " ${self.private_ip}"
# }
# inline = [
# "export NODE_ROLE=partner-api",
# "export GIT_BRANCH=${var.chef_branch}",
# "export NODE_ENV=${var.environment}",
# "sudo /root/bin/bootstrap.sh"
# ]
# }
# }
# resource "aws_route53_record" "partner-api-A" {
# zone_id = "${aws_route53_zone.internal.zone_id}"
# name = "${format("partner-api%d-%s", count.index+10, var.environment)}"
# type = "A"
# count = "${var.instance_count-partner-api-A}"
# ttl = "60"
# records = ["${element(aws_instance.partner-api-A.*.private_ip, count.index)}"]
# }
# resource "template_file" "user_data_partner-api-A" {
# filename = "templates/cloud-config-default.yaml"
# count = "${var.instance_count-partner-api-A}"
# vars {
# hostname = "${format("partner-api%d-%s", count.index+10, var.environment)}"
# domain = "${aws_route53_zone.internal.name}"
# environment = "${var.environment}"
# role = "partner-api"
# branch = "${var.chef_branch}"
# }
# lifecycle {
# create_before_destroy = true
# }
# }
# resource "aws_route53_record" "partner-api-external" {
# zone_id = "${aws_route53_zone.internal.zone_id}"
# name = "partner-api-${var.environment}"
# type = "A"
# ttl = "10"
# records = ["${split(",", join(",", aws_instance.partner-api.*.public_ip))}"]
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment