-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres.tf
More file actions
80 lines (71 loc) · 1.95 KB
/
Copy pathpostgres.tf
File metadata and controls
80 lines (71 loc) · 1.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
# ----------------------
# POSTGRES RDS INSTANCE
# ----------------------
resource "aws_security_group" "rds_sg" {
name = "rds-sg"
description = "Allow Lambda to access Postgres"
vpc_id = aws_vpc.main.id
# Inbound: allow Lambda SG to connect to Postgres (port 5432)
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.lambda_sg.id]
}
# Allow specific IP
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["84.228.99.5/32"] # replace with your IP
description = "Allow my office IP"
}
# Outbound: allow all
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "rds-sg"
}
}
# Subnet group for RDS (must be public subnets)
resource "aws_db_subnet_group" "rds_subnets" {
name = "rds-public-subnets"
subnet_ids = [for s in aws_subnet.public : s.id]
tags = {
Name = "rds-public-subnets"
}
}
# Subnet group for RDS (must be private subnets)
#resource "aws_db_subnet_group" "rds_subnets" {
# name = "rds-subnet-group"
# subnet_ids = [for s in aws_subnet.private : s.id]
#
# tags = {
# Name = "rds-subnet-group"
# }
#}
# RDS Postgres instance
resource "aws_db_instance" "postgres" {
identifier = "postgres-etl"
allocated_storage = 10
engine = "postgres"
engine_version = "17.6"
instance_class = "db.t4g.micro"
username = "postgres"
password = "SuperSecret123!"
port = 5432
db_subnet_group_name = aws_db_subnet_group.rds_subnets.name
vpc_security_group_ids = [aws_security_group.rds_sg.id]
multi_az = false
publicly_accessible = true
skip_final_snapshot = true
deletion_protection = false
tags = {
Name = "postgres-db"
}
depends_on = [aws_nat_gateway.nat]
}