This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rds.tf
63 lines (49 loc) · 1.58 KB
/
rds.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
resource "aws_db_subnet_group" "this" {
count = var.db_type == "postgres" ? 1 : 0
name = "${local.name}-db-subnet-group"
subnet_ids = aws_subnet.public.*.id
tags = local.tags
}
resource "aws_security_group" "rds" {
count = var.db_type == "postgres" ? 1 : 0
name = "${local.name}-rds-sg"
vpc_id = aws_vpc.this.id
ingress {
protocol = "tcp"
from_port = 5432
to_port = 5432
cidr_blocks = [aws_vpc.this.cidr_block]
}
egress {
protocol = "tcp"
from_port = 5432
to_port = 5432
cidr_blocks = [aws_vpc.this.cidr_block]
}
tags = local.tags
}
resource "aws_rds_cluster" "this" {
count = var.db_type == "postgres" ? 1 : 0
cluster_identifier = "${local.name}-rds-cluster"
engine = "aurora-postgresql"
engine_mode = "provisioned"
engine_version = "14.6"
database_name = var.db_name
master_username = var.db_username
master_password = var.db_password
db_subnet_group_name = aws_db_subnet_group.this[count.index].name
vpc_security_group_ids = [aws_security_group.rds[count.index].id]
skip_final_snapshot = true
serverlessv2_scaling_configuration {
min_capacity = var.db_min_capacity
max_capacity = var.db_max_capacity
}
tags = local.tags
}
resource "aws_rds_cluster_instance" "this" {
count = var.db_type == "postgres" ? 1 : 0
cluster_identifier = aws_rds_cluster.this[count.index].id
instance_class = "db.serverless"
engine = aws_rds_cluster.this[count.index].engine
engine_version = aws_rds_cluster.this[count.index].engine_version
}