From d1a69cba72de1d23c6daf2e9ae4deca8a1b0caa2 Mon Sep 17 00:00:00 2001 From: Andrew Grangaard Date: Wed, 25 Oct 2023 06:39:35 -0700 Subject: [PATCH] Fixes #134 - Skips http_forward when aws_lb_target_group.default is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * disables aws_lb_listener.http_forward when default_target_group is not enabled * target_group is required when type is 'redirect' Fixes this Validation error when default_target_group_enabled == 0 : ``` module.alb.aws_lb_listener.http_forward[0]: Creating... ╷ │ Error: creating ELBv2 Listener (arn:aws:elasticloadbalancing:...:...:loadbalancer/...): ValidationError: A target group ARN must be specified │ status code: 400, request id: 7cf9d727-fc77-4d32-a160-cbd175e16e20 │ │ with module.alb.aws_lb_listener.http_forward[0], │ on .terraform/modules/alb/main.tf line 150, in resource "aws_lb_listener" "http_forward": │ 150: resource "aws_lb_listener" "http_forward" { ``` --- main.tf | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 00b38bf..456ce58 100644 --- a/main.tf +++ b/main.tf @@ -150,13 +150,20 @@ resource "aws_lb_target_group" "default" { resource "aws_lb_listener" "http_forward" { #bridgecrew:skip=BC_AWS_GENERAL_43 - Skipping Ensure that load balancer is using TLS 1.2. #bridgecrew:skip=BC_AWS_NETWORKING_29 - Skipping Ensure ALB Protocol is HTTPS - count = module.this.enabled && var.http_enabled && var.http_redirect != true ? 1 : 0 + count = ( + module.this.enabled && + var.http_enabled && + var.http_redirect != true && + (var.listener_http_fixed_response != null || var.default_target_group_enabled) + ? 1 : 0 + ) load_balancer_arn = one(aws_lb.default[*].arn) port = var.http_port protocol = "HTTP" tags = merge(module.this.tags, var.listener_additional_tags) default_action { + # target_group_arn is required when type is forward target_group_arn = var.listener_http_fixed_response != null ? null : one(aws_lb_target_group.default[*].arn) type = var.listener_http_fixed_response != null ? "fixed-response" : "forward"