Skip to content

Commit 3de8c37

Browse files
authored
Fixing aws_cloudwatch_log_group name for WAF logging and alb_listener http_redirect issue (#94)
* Adding dependency for aws_alb_listener http_redirect and fixing conditionals * Adjusting ALB WAF log group name
1 parent d72d8c7 commit 3de8c37

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

operations/deployment/terraform/modules/aws/ecs/aws_ecs_networking.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ resource "aws_alb_listener" "lb_listener_ssl" {
8282
lifecycle {
8383
replace_triggered_by = [null_resource.http_redirect_dep.id]
8484
}
85+
depends_on = [ aws_alb_listener.http_redirect ]
8586
}
8687

8788
resource "aws_alb_listener" "lb_listener" {
@@ -96,6 +97,7 @@ resource "aws_alb_listener" "lb_listener" {
9697
lifecycle {
9798
replace_triggered_by = [null_resource.http_redirect_dep.id]
9899
}
100+
depends_on = [ aws_alb_listener.http_redirect ]
99101
}
100102

101103
resource "aws_alb_listener_rule" "redirect_based_on_path" {
@@ -116,25 +118,28 @@ resource "aws_alb_listener_rule" "redirect_based_on_path" {
116118

117119
resource "aws_alb_listener" "http_redirect" {
118120
count = var.aws_ecs_lb_redirect_enable && !contains(local.aws_ecs_lb_port,80) ? 1 : 0
119-
load_balancer_arn = "${aws_alb.ecs_lb.id}"
121+
load_balancer_arn = aws_alb.ecs_lb.id
120122
port = "80"
121123
protocol = "HTTP"
122124

123125

124126
default_action {
125-
#type = var.aws_certificates_selected_arn != "" ? "redirect" : "forward"
126-
type = var.aws_certificate_enabled != "" ? "redirect" : "forward"
127-
target_group_arn = var.aws_certificates_selected_arn != "" ? null : aws_alb_target_group.lb_targets[0].id
127+
type = var.aws_certificate_enabled ? "redirect" : "forward"
128+
target_group_arn = var.aws_certificate_enabled ? null : aws_alb_target_group.lb_targets[0].id
128129

129130
dynamic "redirect" {
130-
for_each = var.aws_certificates_selected_arn != "" ? [1] : [0]
131+
for_each = var.aws_certificate_enabled ? [1] : [0]
131132
content {
132133
port = 443
133134
protocol = "HTTPS"
134135
status_code = "HTTP_301"
135136
}
136137
}
137138
}
139+
depends_on = [
140+
aws_alb.ecs_lb,
141+
aws_alb_target_group.lb_targets
142+
]
138143
}
139144

140145
resource "aws_security_group_rule" "incoming_alb_http" {

operations/deployment/terraform/modules/aws/waf/aws_waf.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,17 @@ resource "aws_wafv2_web_acl_logging_configuration" "waf_logging" {
393393
name = "cookie"
394394
}
395395
}
396+
depends_on = [ aws_cloudwatch_log_group.waf_log_group, aws_wafv2_web_acl.waf ]
396397
}
397398

398399
# CloudWatch Log Group for WAF (optional)
399400
resource "aws_cloudwatch_log_group" "waf_log_group" {
400401
count = var.aws_waf_enable && var.aws_waf_logging_enable ? 1 : 0
401-
name = "/aws/wafv2/${var.aws_resource_identifier}"
402+
name = "aws-waf-logs-${var.aws_resource_identifier}"
402403
retention_in_days = var.aws_waf_log_retention_days
403404

404405
tags = {
405-
Name = "${var.aws_resource_identifier}-waf-logs"
406+
Name = "aws-waf-logs-${var.aws_resource_identifier}"
406407
}
407408
}
408409

0 commit comments

Comments
 (0)