Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Move ingress/egress to aws_security_group_rule in rds #119

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
52 changes: 30 additions & 22 deletions rds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,40 @@ variable "subnet_ids" {
type = "list"
}

resource "aws_security_group" "main" {
name = "${var.name}-rds"
description = "Allows traffic to RDS from other security groups"
vpc_id = "${var.vpc_id}"
resource "aws_security_group_rule" "main-ingress-cidrs" {
security_group_id = "${aws_security_group.main.id}"
type = "ingress"
cidr_blocks = ["${var.ingress_allow_cidr_blocks}"]
from_port = "${var.port}"
to_port = "${var.port}"
protocol = "TCP"
}

ingress {
from_port = "${var.port}"
to_port = "${var.port}"
protocol = "TCP"
security_groups = ["${var.ingress_allow_security_groups}"]
}
resource "aws_security_group_rule" "main-ingress-sgs" {
security_group_id = "${aws_security_group.main.id}"
type = "ingress"
count = "${length(var.ingress_allow_security_groups)}"
source_security_group_id = "${element(var.ingress_allow_security_groups, count.index)}"

ingress {
from_port = "${var.port}"
to_port = "${var.port}"
protocol = "TCP"
cidr_blocks = ["${var.ingress_allow_cidr_blocks}"]
}
from_port = "${var.port}"
to_port = "${var.port}"
protocol = "TCP"
}

egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "main-egress-all" {
security_group_id = "${aws_security_group.main.id}"
type = "egress"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}


resource "aws_security_group" "main" {
name = "${var.name}-rds"
description = "Allows traffic to RDS from other security groups"
vpc_id = "${var.vpc_id}"
tags {
Name = "RDS (${var.name})"
}
Expand Down