Skip to content

Commit 2378616

Browse files
Improved
1 parent 95bb192 commit 2378616

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

_example/example.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ module "security_group" {
2323
protocol = "tcp"
2424
description = "Instance default security group (only egress access is allowed)."
2525
allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
26+
allowed_ipv6 = ["2405:201:5e00:3684:cd17:9397:5734:a167/128"]
2627
allowed_ports = [22, 27017]
2728
}

main.tf

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# convention.
99

1010
module "labels" {
11-
source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.12.0"
11+
source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.13.0"
1212

1313
name = var.name
1414
application = var.application
@@ -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

7091
resource "aws_security_group_rule" "ingress_sg" {
7192
count = local.enable_source_sec_group_rules == true ? length(local.ports_source_sec_group_product) : 0

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@ variable "protocol" {
7878
type = string
7979
default = "tcp"
8080
description = "The protocol. If not icmp, tcp, udp, or all use the."
81+
}
82+
variable "allowed_ipv6" {
83+
type = list
84+
default = []
85+
description = "List of allowed ipv6."
86+
}
87+
variable "prefix_list" {
88+
type = list
89+
default = []
90+
description = "List of prefix list IDs (for allowing access to VPC endpoints)Only valid with egress"
8191
}

versions.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ terraform {
33
required_version = ">= 0.12.0, < 0.14.0"
44
required_providers {
55
aws = {
6-
source = "hashicorp/aws"
6+
source = "hashicorp/aws"
7+
version = "3.10.0"
78
}
89
}
910
}

0 commit comments

Comments
 (0)