Skip to content

Commit 788c0df

Browse files
committed
feat(modules/alb): access and connection logs configuration
1 parent 66b273c commit 788c0df

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

modules/alb/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ resource "aws_lb" "this" {
1515
preserve_host_header = var.preserve_host_header
1616
enable_deletion_protection = var.enable_deletion_protection
1717

18+
dynamic "access_logs" {
19+
for_each = var.access_logs != null ? [var.access_logs] : []
20+
iterator = access_log
21+
22+
content {
23+
bucket = access_log.value.bucket
24+
enabled = access_log.value.enabled
25+
prefix = access_log.value.prefix
26+
}
27+
}
28+
29+
dynamic "connection_logs" {
30+
for_each = var.connection_logs != null ? [var.connection_logs] : []
31+
iterator = connection_log
32+
33+
content {
34+
bucket = connection_log.value.bucket
35+
enabled = connection_log.value.enabled
36+
prefix = connection_log.value.prefix
37+
}
38+
}
39+
1840
tags = var.tags
1941
}
2042

modules/alb/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ variable "enable_deletion_protection" {
3737
default = false
3838
}
3939

40+
variable "access_logs" {
41+
description = "(Optional) Access Logs block."
42+
type = object({
43+
bucket = string
44+
enabled = optional(bool, true)
45+
prefix = optional(string, null)
46+
})
47+
default = null
48+
}
49+
50+
variable "connection_logs" {
51+
description = "(Optional) Connection Logs block."
52+
type = object({
53+
bucket = string
54+
enabled = optional(bool, false)
55+
prefix = optional(string, null)
56+
})
57+
default = null
58+
}
59+
4060
variable "tags" {
4161
description = "(Optional) Map of tags to assign to the resource."
4262
type = map(string)

tests/alb_unit_tests.tftest.hcl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ run "lb_attributes_match" {
2121
preserve_host_header = true
2222
enable_deletion_protection = true
2323

24+
access_logs = {
25+
bucket = "example-access-logs-bucket"
26+
enabled = true
27+
prefix = "example-access-logs-bucket-prefix"
28+
}
29+
30+
connection_logs = {
31+
bucket = "example-connection-logs-bucket"
32+
enabled = true
33+
prefix = "example-connection-logs-bucket-prefix"
34+
}
35+
2436
listeners = {}
2537

2638
tags = {
@@ -57,6 +69,16 @@ run "lb_attributes_match" {
5769
error_message = "Enable deletion protection mismatch"
5870
}
5971

72+
assert {
73+
condition = aws_lb.this.access_logs[0] == var.access_logs
74+
error_message = "Access logs mismatch"
75+
}
76+
77+
assert {
78+
condition = aws_lb.this.connection_logs[0] == var.connection_logs
79+
error_message = "Connection logs mismatch"
80+
}
81+
6082
assert {
6183
condition = aws_lb.this.tags == var.tags
6284
error_message = "Tags mismatch"

0 commit comments

Comments
 (0)