Skip to content

Commit 3eb05e8

Browse files
add(terraform): #14 - rds impl
1 parent 1c5904d commit 3eb05e8

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

deploy/terraform/rds.tf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# - SECURITY GROUPS ---------------------------------------------------- #
2+
3+
resource "aws_security_group" "alpha_rds" {
4+
depends_on = [aws_vpc.alpha]
5+
name = "${lookup(var.global, "name")}-rds"
6+
description = "${lookup(var.global, "name")}-rds"
7+
vpc_id = aws_vpc.alpha.id
8+
9+
ingress {
10+
from_port = 5432
11+
to_port = 5432
12+
protocol = "tcp"
13+
cidr_blocks = ["0.0.0.0/0"]
14+
}
15+
16+
egress {
17+
from_port = 5432
18+
to_port = 5432
19+
protocol = "tcp"
20+
cidr_blocks = ["0.0.0.0/0"]
21+
}
22+
23+
tags = {
24+
Name = "${lookup(var.global, "name")}-rds"
25+
}
26+
}
27+
28+
# - INSTANCE ----------------------------------------------------------- #
29+
30+
resource "aws_db_subnet_group" "alpha" {
31+
name = lookup(var.global, "name")
32+
subnet_ids = [aws_subnet.alpha_pub.id, aws_subnet.alpha_prv.id]
33+
34+
tags = {
35+
Name = lookup(var.global, "name")
36+
}
37+
}
38+
39+
resource "aws_db_parameter_group" "alpha" {
40+
name = lookup(var.global, "name")
41+
family = lookup(var.rds, "family")
42+
43+
parameter {
44+
name = "log_connections"
45+
value = "1"
46+
}
47+
tags = {
48+
Name = lookup(var.global, "name")
49+
}
50+
}
51+
52+
resource "aws_db_instance" "alpha" {
53+
identifier = lookup(var.global, "name")
54+
allocated_storage = 5
55+
instance_class = lookup(var.rds, "type")
56+
engine = lookup(var.rds, "engine")
57+
engine_version = lookup(var.rds, "version")
58+
username = lookup(var.rds, "username")
59+
password = lookup(var.rds, "password")
60+
publicly_accessible = lookup(var.rds, "publicly_accessible")
61+
skip_final_snapshot = lookup(var.rds, "skip_final_snapshot")
62+
db_subnet_group_name = aws_db_subnet_group.alpha.name
63+
parameter_group_name = aws_db_parameter_group.alpha.name
64+
vpc_security_group_ids = [aws_security_group.alpha_rds.id]
65+
tags = {
66+
Name = lookup(var.global, "name")
67+
}
68+
}

0 commit comments

Comments
 (0)