File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed
Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 11resource "aws_alb" "this" {
22 name = var. name
33 security_groups = [aws_security_group . this . id ]
4- subnets = var. subnet_ids
5- tags = var. tags
4+
5+ dynamic "connection_logs" {
6+ for_each = var. enable_connection_logs ? [1 ] : []
7+ content {
8+ bucket = var. s3_bucket_name != " " ? var. s3_bucket_name : aws_s3_bucket. lb_logs [0 ]. id
9+ prefix = " connectionlogs"
10+ enabled = true
11+ }
12+ }
13+
14+ dynamic "access_logs" {
15+ for_each = var. enable_access_logs ? [1 ] : []
16+ content {
17+ bucket = var. s3_bucket_name != " " ? var. s3_bucket_name : aws_s3_bucket. lb_logs [0 ]. id
18+ prefix = " accesslogs"
19+ enabled = true
20+ }
21+ }
22+ subnets = var. subnet_ids
23+ tags = var. tags
24+ }
25+
26+ resource "aws_s3_bucket" "lb_logs" {
27+ count = var. s3_bucket_name == " " ? 1 : 0
28+ bucket = var. s3_bucket_name == " " ? " ${ var . name } -alb-logs-${ random_id . suffix . hex } " : var. s3_bucket_name
29+ }
30+
31+ resource "random_id" "suffix" {
32+ byte_length = 4
633}
734
835resource "aws_security_group" "this" {
Original file line number Diff line number Diff line change @@ -3,11 +3,29 @@ variable "description" {
33 type = string
44}
55
6+ variable "enable_access_logs" {
7+ type = bool
8+ default = false
9+ description = " Enable or disable ALB access logs. If set to true, logs will be stored in an S3 bucket."
10+ }
11+
12+ variable "enable_connection_logs" {
13+ type = bool
14+ default = false
15+ description = " Enable or disable ALB connection logs. If set to true, logs will be stored in an S3 bucket."
16+ }
17+
618variable "name" {
719 description = " Name for this load balancer"
820 type = string
921}
1022
23+ variable "s3_bucket_name" {
24+ type = string
25+ default = " "
26+ description = " Optional S3 bucket name for storing ALB access logs. If not provided, a new bucket will be created."
27+ }
28+
1129variable "security_group_name" {
1230 type = string
1331 description = " Name for the load balancer security group; defaults to name"
You can’t perform that action at this time.
0 commit comments