Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use separate TF resources for security group ingress/egress rules #1782

Merged
merged 3 commits into from
Sep 25, 2024
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
74 changes: 51 additions & 23 deletions terraform/modules/bosh_vpc/sg_restricted_web_traffic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,59 @@ resource "aws_security_group" "restricted_web_traffic" {
description = "Restricted web type traffic"
vpc_id = aws_vpc.main_vpc.id

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = sort(var.restricted_ingress_web_cidrs)
ipv6_cidr_blocks = sort(var.restricted_ingress_web_ipv6_cidrs)
tags = {
Name = "${var.stack_description} - Restricted Incoming Web Traffic"
}
}

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = sort(var.restricted_ingress_web_cidrs)
ipv6_cidr_blocks = sort(var.restricted_ingress_web_ipv6_cidrs)
}
resource "aws_vpc_security_group_ingress_rule" "http_ipv4_ingress_rules" {
for_each = toset(var.restricted_ingress_web_cidrs)
security_group_id = aws_security_group.restricted_web_traffic.id
cidr_ipv4 = each.key
from_port = 80
to_port = 80
ip_protocol = "tcp"
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
resource "aws_vpc_security_group_ingress_rule" "http_ipv6_ingress_rules" {
for_each = toset(var.restricted_ingress_web_ipv6_cidrs)
security_group_id = aws_security_group.restricted_web_traffic.id
cidr_ipv6 = each.key
from_port = 80
to_port = 80
ip_protocol = "tcp"
}

tags = {
Name = "${var.stack_description} - Restricted Incoming Web Traffic"
}
resource "aws_vpc_security_group_ingress_rule" "https_ipv4_ingress_rules" {
for_each = toset(var.restricted_ingress_web_cidrs)
security_group_id = aws_security_group.restricted_web_traffic.id
cidr_ipv4 = each.key
from_port = 443
to_port = 443
ip_protocol = "tcp"
}

resource "aws_vpc_security_group_ingress_rule" "https_ipv6_ingress_rules" {
for_each = toset(var.restricted_ingress_web_ipv6_cidrs)
security_group_id = aws_security_group.restricted_web_traffic.id
cidr_ipv6 = each.key
from_port = 443
to_port = 443
ip_protocol = "tcp"
}

resource "aws_vpc_security_group_egress_rule" "all_egress_ipv4" {
security_group_id = aws_security_group.restricted_web_traffic.id
from_port = 0
to_port = 0
ip_protocol = "-1"
cidr_ipv4 = "0.0.0.0/0"
}

resource "aws_vpc_security_group_egress_rule" "all_egress_ipv6" {
security_group_id = aws_security_group.restricted_web_traffic.id
from_port = 0
to_port = 0
ip_protocol = "-1"
cidr_ipv6 = "::/0"
}