Skip to content

Instantly share code, notes, and snippets.

@100daysofdevops
Created March 2, 2019 03:34
Show Gist options
  • Select an option

  • Save 100daysofdevops/eee64029580c2d9e5596448621bf0e8e to your computer and use it in GitHub Desktop.

Select an option

Save 100daysofdevops/eee64029580c2d9e5596448621bf0e8e to your computer and use it in GitHub Desktop.
provider "aws" {
region = "us-west-2"
}
resource "aws_lb" "my-test-lb" {
name = "my-test-lb"
internal = false
load_balancer_type = "application"
ip_address_type = "ipv4"
subnets = ["${var.subnet_id1}", "${var.subnet_id2}"]
security_groups = ["${aws_security_group.alb-sg.id}"]
enable_deletion_protection = true
tags {
Name = "my-test-alb"
}
}
resource "aws_lb_target_group" "my-alb-tg" {
health_check {
interval = 30
path = "/"
protocol = "HTTP"
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
matcher = "200-299"
}
name = "my-alb-tg"
port = 80
protocol = "HTTP"
vpc_id = "${var.vpc_id}"
target_type = "instance"
}
resource "aws_lb_target_group_attachment" "my-tg-attachment1" {
target_group_arn = "${aws_lb_target_group.my-alb-tg.arn}"
target_id = "${var.instance_id1}"
port = 80
}
resource "aws_lb_target_group_attachment" "my-tg-attachment2" {
target_group_arn = "${aws_lb_target_group.my-alb-tg.arn}"
target_id = "${var.instance_id2}"
port = 80
}
resource "aws_security_group" "alb-sg" {
name = "my-alb-sg"
vpc_id = "${var.vpc_id}"
}
resource "aws_security_group_rule" "http_allow" {
from_port = 80
protocol = "tcp"
security_group_id = "${aws_security_group.alb-sg.id}"
to_port = 80
type = "ingress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "all_outbound_access" {
from_port = 0
protocol = "-1"
security_group_id = "${aws_security_group.alb-sg.id}"
to_port = 0
type = "egress"
cidr_blocks = ["0.0.0.0/0"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment