Skip to content

Instantly share code, notes, and snippets.

@theCaptN21
Last active February 20, 2023 20:13
Show Gist options
  • Save theCaptN21/224dae3dd2972560b8dba0d88bd2bd26 to your computer and use it in GitHub Desktop.
Save theCaptN21/224dae3dd2972560b8dba0d88bd2bd26 to your computer and use it in GitHub Desktop.
LoadBalancer main.tf
resource "aws_lb" "tfcloud_lb" {
name = "tfcloud-alb"
internal = false
load_balancer_type = "application"
security_groups = [var.web_sg]
subnets = tolist(var.public_subnet)
depends_on = [
var.database_asg
]
}
resource "aws_lb_target_group" "tfcloud_tg" {
name = "tfcloud-lb-tg-${substr(uuid(), 0, 5)}"
protocol = var.tg_protocol
port = var.tg_port
vpc_id = "var.vpc_id"
health_check {
healthy_threshold = var.lb_healthy_threshold
unhealthy_threshold = var.lb_unhealthy_threshold
timeout = var.lb_timeout
interval = var.lb_interval
}
lifecycle {
create_before_destroy = true
ignore_changes =[name]
}
}
resource "aws_lb_listener" "tfcloud_lb_listener" {
load_balancer_arn = aws_lb.tfcloud_lb.arn
port = var.listener_port
protocol = var.listener_protocol
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tfcloud_tg.arn
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment