-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_group.tf
34 lines (33 loc) · 1.26 KB
/
security_group.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_security_group
resource "aws_default_security_group" "default" {
vpc_id = aws_vpc.this.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "rds" {
name = "${var.name}-rds-sg"
description = "Security group for RDS in ${var.name}"
vpc_id = aws_vpc.this.id
tags = {
"Name" = "${var.name}-rds-sg"
}
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "ingress_rds_sg" {
description = "allow traffic to RDS"
type = "ingress"
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = [var.vpc_cidr]
security_group_id = aws_security_group.rds.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "egress_rds_sg" {
description = "allow traffic to reach outside the vpc"
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [var.vpc_cidr]
security_group_id = aws_security_group.rds.id
}