Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

EndpointSG should only be created when VPC endpoints are defined #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions vpc-endpoints.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
resource "aws_security_group" "sgforendpoint" {
count = length(var.vpc_endpoints) != 0 ? 1 : 0
name = "EndpointSG"
description = "Allow indbound and outbound traffic for VPC endpoint"
vpc_id = aws_vpc.main.id
}

resource "aws_security_group_rule" "allow_all_ingress" {
count = length(var.vpc_endpoints) != 0 ? 1 : 0
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we sneak this fix in too?

Suggested change
cidr_blocks = ["0.0.0.0/0"]
cidr_blocks = [var.vpc_cidr_block]

security_group_id = aws_security_group.sgforendpoint.id
security_group_id = aws_security_group.sgforendpoint[0].id
}

resource "aws_security_group_rule" "allow_all_egress" {
count = length(var.vpc_endpoints) != 0 ? 1 : 0
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.sgforendpoint.id
security_group_id = aws_security_group.sgforendpoint[0].id
}

resource "aws_vpc_endpoint" "vpc_endpoint" {
Expand All @@ -28,7 +31,7 @@ resource "aws_vpc_endpoint" "vpc_endpoint" {
service_name = "com.amazonaws.${data.aws_region.current.name}.${each.value}"
vpc_endpoint_type = "Interface"
private_dns_enabled = "true"
security_group_ids = [aws_security_group.sgforendpoint.id]
security_group_ids = [aws_security_group.sgforendpoint[0].id]
subnet_ids = aws_subnet.private.*.id
tags = merge(
{ Name = "${var.vpc_name}-${each.value}-endpoint" },
Expand Down