-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrds.tf
53 lines (45 loc) · 1.55 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
# Credentials
resource "random_string" "db_username" {
length = 16
special = false
}
resource "random_string" "db_password" {
length = 32
special = false
override_special = " @"
}
resource "aws_secretsmanager_secret" "db_credentials" {
name = "ETL_DB_credentials"
}
resource "aws_secretsmanager_secret_version" "db_credentials_version" {
secret_id = aws_secretsmanager_secret.db_credentials.id
secret_string = jsonencode({
username = random_string.db_username.result
password = random_string.db_password.result
})
}
# RDS
resource "aws_db_subnet_group" "etl_db_subnet_group" {
name = "etl-db-subnet-group"
subnet_ids = [aws_subnet.etl_private_a.id, aws_subnet.etl_private_b.id]
tags = {
Name = "ETL DB Subnet Group"
}
}
resource "aws_db_instance" "etl_db" {
identifier = "etl-db"
engine = "postgres"
engine_version = "12.3"
instance_class = "db.t2.micro"
allocated_storage = 20
storage_type = "gp2"
backup_retention_period = 0
db_subnet_group_name = aws_db_subnet_group.etl_db_subnet_group.name
name = "postgres"
username = jsondecode(aws_secretsmanager_secret_version.db_credentials_version.secret_string)["username"]
password = jsondecode(aws_secretsmanager_secret_version.db_credentials_version.secret_string)["password"]
parameter_group_name = "default.postgres12"
publicly_accessible = false
# Since the data is recreatable, we don't need a final snapshot
skip_final_snapshot = true
}