Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module "load_balancer" {
source = "./modules/load_balancer"

deployment_name = var.deployment_name
deploy_lb = var.deploy_lb
vpc_id = local.vpc_id
vpc_cidr = local.vpc_cidr
vpc_subnets = length(var.lb_subnets_override) > 0 ? var.lb_subnets_override : (var.lb_internal ? local.vpc_private_subnets : local.vpc_public_subnets)
Expand Down
10 changes: 6 additions & 4 deletions modules/load_balancer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module "alb_app" {
source = "terraform-aws-modules/alb/aws"
version = "~> 8.7.0"

count = var.deploy_lb ? 1 : 0

name = var.lb_name_override == "" ? "${var.deployment_name}-app" : var.lb_name_override

load_balancer_type = "application"
Expand Down Expand Up @@ -110,11 +112,11 @@ locals {
}

data "aws_network_interface" "lb_app" {
count = var.initial_apply_complete ? length(var.vpc_subnets) : 0
count = var.initial_apply_complete && var.deploy_lb ? length(var.vpc_subnets) : 0

filter {
name = "description"
values = ["ELB ${module.alb_app.lb_arn_suffix}"]
values = ["ELB ${module.alb_app[0].lb_arn_suffix}"]
}

filter {
Expand Down Expand Up @@ -178,10 +180,10 @@ resource "aws_lb_listener" "nlb_front_end" {
}

resource "aws_lb_target_group_attachment" "attachment-alb-nlb-tg" {
count = var.lb_deploy_nlb ? 1 : 0
count = var.lb_deploy_nlb && var.deploy_lb ? 1 : 0

target_group_arn = aws_lb_target_group.nlb_alb_target[0].arn
target_id = module.alb_app.lb_arn
target_id = module.alb_app[0].lb_arn
port = local.nlb_port
}

Expand Down
4 changes: 2 additions & 2 deletions modules/load_balancer/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
output "target_group_arn" {
value = module.alb_app.target_group_arns[0]
value = var.deploy_lb ? module.alb_app[0].target_group_arns[0] : "not_deployed"
}

output "load_balancer_ips" {
value = local.lb_ips
}

output "load_balancer_dns" {
value = module.alb_app.lb_dns_name
value = var.deploy_lb ? module.alb_app[0].lb_dns_name : "not_deployed"
}

output "domain_name" {
Expand Down
6 changes: 6 additions & 0 deletions modules/load_balancer/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ variable "deployment_name" {
description = "Name of the current deployment."
}

variable "deploy_lb" {
type = bool
default = true
description = "Allows a deploy without a load balancer"
}

variable "vpc_id" {
type = string
default = ""
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ variable "lb_vpces_details" {
description = "Endpoint service to define for internal traffic over private link"
}

variable "deploy_lb" {
type = bool
default = true
description = "Allows a deploy without a load balancer"
}

# ╺┳┓┏━┓╺┳╸┏━┓┏┓ ┏━┓┏━┓┏━╸
# ┃┃┣━┫ ┃ ┣━┫┣┻┓┣━┫┗━┓┣╸
# ╺┻┛╹ ╹ ╹ ╹ ╹┗━┛╹ ╹┗━┛┗━╸
Expand Down