@@ -15,6 +15,7 @@ module "labels" {
1515 environment = var. environment
1616 managedby = var. managedby
1717 label_order = var. label_order
18+ enabled = var. enable_security_group
1819}
1920
2021locals {
@@ -49,8 +50,18 @@ resource "aws_security_group_rule" "egress" {
4950 from_port = 0
5051 to_port = 65535
5152 protocol = " -1"
52- cidr_blocks = var. choose_cidr_type == " ipv4" ? [" 0.0.0.0/0" ] : []
53- ipv6_cidr_blocks = var. choose_cidr_type == " ipv6" ? [" 2001:db8:1234:1a00::/64" ] : []
53+ cidr_blocks = [" 0.0.0.0/0" ]
54+ security_group_id = join (" " , aws_security_group. default . * . id )
55+ prefix_list_ids = var. prefix_list
56+ }
57+ resource "aws_security_group_rule" "egress_ipv6" {
58+ count = var. enable_security_group == true ? 1 : 0
59+
60+ type = " egress"
61+ from_port = 0
62+ to_port = 65535
63+ protocol = " -1"
64+ ipv6_cidr_blocks = [" ::/0" ]
5465 security_group_id = join (" " , aws_security_group. default . * . id )
5566 prefix_list_ids = var. prefix_list
5667}
@@ -65,8 +76,17 @@ resource "aws_security_group_rule" "ingress" {
6576 from_port = element (var. allowed_ports , count. index )
6677 to_port = element (var. allowed_ports , count. index )
6778 protocol = var. protocol
68- cidr_blocks = var. choose_cidr_type == " ipv4" ? var. allowed_ip : []
69- ipv6_cidr_blocks = var. choose_cidr_type == " ipv6" ? var. allowed_ip : []
79+ cidr_blocks = var. allowed_ip
80+ security_group_id = join (" " , aws_security_group. default . * . id )
81+ }
82+ resource "aws_security_group_rule" "ingress_ipv6" {
83+ count = local. enable_cidr_rules == true ? length (compact (var. allowed_ports )) : 0
84+
85+ type = " ingress"
86+ from_port = element (var. allowed_ports , count. index )
87+ to_port = element (var. allowed_ports , count. index )
88+ protocol = var. protocol
89+ ipv6_cidr_blocks = var. allowed_ipv6
7090 security_group_id = join (" " , aws_security_group. default . * . id )
7191}
7292
0 commit comments