Skip to content

Commit 4912792

Browse files
committed
Merge branch 'CD-246' of github.com:clouddrove/terraform-aws-security-group into CD-246
2 parents 85813da + 4ecd077 commit 4912792

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

README.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ github_repo: clouddrove/terraform-aws-security-group
1616
# Badges to display
1717
badges:
1818
- name: "Terraform"
19-
image: "https://img.shields.io/badge/Terraform-v0.12-green"
19+
image: "https://img.shields.io/badge/terraform-v0.13-green"
2020
url: "https://www.terraform.io"
2121
- name: "Licence"
2222
image: "https://img.shields.io/badge/License-MIT-blue.svg"
@@ -44,6 +44,7 @@ usage : |-
4444
label_order = ["environment", "application", "name"]
4545
vpc_id = "vpc-xxxxxxxxx"
4646
allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
47+
allowed_ipv6 = ["2405:201:5e00:3684:cd17:9397:5734:a167/128"]
4748
allowed_ports = [22, 27017]
4849
}
4950
```

_example/example.tf

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

_example/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ output "tags" {
66
output "security_group_ids" {
77
value = module.security_group.security_group_ids
88
description = "A mapping of security group ids."
9+
}
10+
output "vpc_cidr_block" {
11+
value = module.vpc.vpc_cidr_block
12+
description = "VPC IPV4 CIDR Block."
13+
}
14+
15+
output "vpc_cidr_block_ipv6" {
16+
value = module.vpc.ipv6_cidr_block
17+
description = "VPC IPV4 CIDR Block."
918
}

main.tf

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2021
locals {
@@ -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

variables.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ variable "allowed_ip" {
6767
default = []
6868
description = "List of allowed ip."
6969
}
70-
70+
variable "allowed_ipv6" {
71+
type = list
72+
default = []
73+
description = "List of allowed ipv6."
74+
}
7175
variable "security_groups" {
7276
type = list(string)
7377
default = []
@@ -79,11 +83,6 @@ variable "protocol" {
7983
default = "tcp"
8084
description = "The protocol. If not icmp, tcp, udp, or all use the."
8185
}
82-
variable "choose_cidr_type" {
83-
type = string
84-
default = "ipv6"
85-
description = "Choose cidr block ipv4 vs ipv6(eg: 2001:db8:1234:1a00::/64) cidr block"
86-
}
8786
variable "prefix_list" {
8887
type = list
8988
default = []

0 commit comments

Comments
 (0)