@@ -22,6 +22,7 @@ locals {
2222 enable_cidr_rules = var. enable_security_group && (length (var. allowed_ip ) > 0 )
2323 enable_source_sec_group_rules = var. enable_security_group && (length (var. security_groups ) > 0 )
2424 ports_source_sec_group_product = setproduct (compact (var. allowed_ports ), compact (var. security_groups ))
25+ enable_cidr_rules_ipv6 = var. enable_security_group && (length (var. allowed_ipv6 ) > 0 )
2526}
2627
2728# Module : SECURITY GROUP
@@ -52,7 +53,17 @@ resource "aws_security_group_rule" "egress" {
5253 cidr_blocks = [" 0.0.0.0/0" ]
5354 security_group_id = join (" " , aws_security_group. default . * . id )
5455}
56+ resource "aws_security_group_rule" "egress_ipv6" {
57+ count = var. enable_security_group == true && local. enable_cidr_rules_ipv6 == true ? length (compact (var. allowed_ports )) : 0
5558
59+ type = " egress"
60+ from_port = 0
61+ to_port = 65535
62+ protocol = " -1"
63+ ipv6_cidr_blocks = [" ::/0" ]
64+ security_group_id = join (" " , aws_security_group. default . * . id )
65+ prefix_list_ids = var. prefix_list
66+ }
5667# Module : SECURITY GROUP RULE FOR INGRESS
5768# Description : Provides a security group rule resource. Represents a single ingress
5869# group rule, which can be added to external Security Groups.
@@ -66,6 +77,16 @@ resource "aws_security_group_rule" "ingress" {
6677 cidr_blocks = var. allowed_ip
6778 security_group_id = join (" " , aws_security_group. default . * . id )
6879}
80+ resource "aws_security_group_rule" "ingress_ipv6" {
81+ count = var. enable_security_group == true && local. enable_cidr_rules_ipv6 == true ? length (compact (var. allowed_ports )) : 0
82+
83+ type = " ingress"
84+ from_port = element (var. allowed_ports , count. index )
85+ to_port = element (var. allowed_ports , count. index )
86+ protocol = var. protocol
87+ ipv6_cidr_blocks = var. allowed_ipv6
88+ security_group_id = join (" " , aws_security_group. default . * . id )
89+ }
6990
7091resource "aws_security_group_rule" "ingress_sg" {
7192 count = local. enable_source_sec_group_rules == true ? length (local. ports_source_sec_group_product ) : 0
0 commit comments