-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrds.tf
More file actions
67 lines (52 loc) · 1.58 KB
/
rds.tf
File metadata and controls
67 lines (52 loc) · 1.58 KB
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
64
65
66
67
data "aws_vpc" "selected" {
count = var.create_rds ? 1 : 0
id = var.vpc_id
}
resource "aws_security_group" "rds" {
count = var.create_rds ? 1 : 0
name = "${var.db_identifier}-rds-sg"
description = "Security group for RDS PostgreSQL instance"
vpc_id = var.vpc_id
ingress {
description = "PostgreSQL from VPC"
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = [data.aws_vpc.selected[0].cidr_block]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge(var.tags, {
Name = "${var.db_identifier}-rds-sg"
})
}
resource "random_password" "db_password" {
count = var.create_rds ? 1 : 0
length = 32
special = false
}
resource "aws_db_instance" "postgres" {
count = var.create_rds ? 1 : 0
identifier = var.db_identifier
engine = "postgres"
engine_version = var.postgres_version
instance_class = var.db_instance_class
allocated_storage = var.db_allocated_storage
max_allocated_storage = 1000
storage_type = "gp3"
storage_encrypted = true
db_name = var.db_name
username = var.db_username
password_wo = coalesce(var.db_password, random_password.db_password[0].result)
password_wo_version = 1
multi_az = false
db_subnet_group_name = var.db_subnet_group_name
vpc_security_group_ids = [aws_security_group.rds[0].id]
backup_retention_period = var.db_backup_retention_period
skip_final_snapshot = var.db_skip_final_snapshot
tags = var.tags
}