Skip to content
Merged
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
50 changes: 39 additions & 11 deletions modules/autoscale_gwlb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,50 @@ resource "aws_security_group" "permissive_sg" {
name_prefix = format("%s_PermissiveSecurityGroup", local.asg_name)
description = "Permissive security group"
vpc_id = var.vpc_id
tags = {
Name = format("%s_PermissiveSecurityGroup", local.asg_name)

dynamic "ingress" {
for_each = [for rule in var.security_rules : rule if rule.direction == "ingress"]
content {
from_port = ingress.value.from_port
to_port = ingress.value.to_port
protocol = ingress.value.protocol
cidr_blocks = ingress.value.cidr_blocks
}
}
}

resource "aws_vpc_security_group_ingress_rule" "ingress_rule_ipv4" {
security_group_id = aws_security_group.permissive_sg.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "-1"
dynamic ingress {
for_each = length([for rule in var.security_rules : rule if rule.direction == "ingress"]) == 0 ? [1] : []
content{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_vpc_security_group_egress_rule" "egress_rule_ipv4" {
security_group_id = aws_security_group.permissive_sg.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "-1"
dynamic "egress" {
for_each = [for rule in var.security_rules : rule if rule.direction == "egress"]
content {
from_port = egress.value.from_port
to_port = egress.value.to_port
protocol = egress.value.protocol
cidr_blocks = egress.value.cidr_blocks
}
}

dynamic egress {
for_each = length([for rule in var.security_rules : rule if rule.direction == "egress"]) == 0 ? [1] : []
content{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
tags = {
Name = format("%s_PermissiveSecurityGroup", local.asg_name)
}
}

resource "aws_vpc_security_group_ingress_rule" "ingress_rule_ipv6" {
count = var.enable_ipv6 ? 1 : 0
Expand Down