Skip to content

Instantly share code, notes, and snippets.

@a-nldisr
Created August 8, 2018 11:29
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 a-nldisr/561d788c95cb8b787f0a404ca08ca5af to your computer and use it in GitHub Desktop.
Save a-nldisr/561d788c95cb8b787f0a404ca08ca5af to your computer and use it in GitHub Desktop.
# Generate the elastic IP for the loadbalancer
resource "aws_eip" "test-lb" {
vpc = true
lifecycle {
create_before_destroy = "true"
}
}
# Generate the target group for the load balancer to use
resource "aws_lb_target_group" "test-lb-tg" {
name = "${data.template_file.cluster-name.rendered}-test-lb-tg"
port = 443
protocol = "TCP"
vpc_id = "${aws_vpc.default.id}"
health_check {
port = 8080
protocol = "TCP"
healthy_threshold = 2
unhealthy_threshold = 2
interval = 10
}
}
# Attach to the target group, target_id is broken
resource "aws_lb_target_group_attachment" "test-lb-tg" {
target_group_arn = "${aws_lb_target_group.test-lb-tg.arn}"
target_id = "${element(aws_instance.test.*.id, count.index)}"
port = 443
}
# Load balancer listener
resource "aws_lb_listener" "test-lb-listen" {
load_balancer_arn = "${aws_lb.test.arn}"
port = "443"
protocol = "TCP"
default_action {
target_group_arn = "${aws_lb_target_group.test-lb-tg.arn}"
type = "forward"
}
}
# Create the External Network load balancer.
resource "aws_lb" "test" {
name = "${data.template_file.cluster-name.rendered}-pub-agt"
internal = false
load_balancer_type = "network"
subnet_mapping {
subnet_id = "${aws_subnet.test.id}"
allocation_id = "${aws_eip.test.id}"
}
enable_deletion_protection = false
}
resource "aws_instance" "test" {
count = "${var.num_of_test}"
instance_type = "${var.aws_test_instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.test.name}"
ebs_optimized = "true"
ami = "${var.test_ami_id}"
key_name = "${var.ssh_key_name}"
vpc_security_group_ids = ["${aws_security_group.test.id}"]
subnet_id = "${aws_subnet.test.id}"
lifecycle {
create_before_destroy = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment