Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions infra/terraform/rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ resource "aws_db_subnet_group" "main" {
subnet_ids = aws_subnet.private[*].id
}

# Custom parameter group so we can flip rds.force_ssl on. The default
# parameter group is read-only.
resource "aws_db_parameter_group" "main" {
name = "${local.name}-postgres17"
family = "postgres17"

parameter {
name = "rds.force_ssl"
value = "1"
# Static parameter — requires a reboot to take effect. RDS handles
# the reboot during the next maintenance window or you can force it.
apply_method = "pending-reboot"
}
}

resource "aws_db_instance" "main" {
identifier = "${local.name}-postgres"
engine = "postgres"
Expand All @@ -39,9 +54,10 @@ resource "aws_db_instance" "main" {
storage_type = "gp3"
storage_encrypted = true

db_name = var.postgres_db_name
username = var.postgres_username
password = random_password.postgres.result
db_name = var.postgres_db_name
username = var.postgres_username
password = random_password.postgres.result
parameter_group_name = aws_db_parameter_group.main.name

db_subnet_group_name = aws_db_subnet_group.main.name
vpc_security_group_ids = [aws_security_group.rds.id]
Expand Down
5 changes: 4 additions & 1 deletion infra/terraform/secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ resource "aws_secretsmanager_secret" "postgres_url" {

resource "aws_secretsmanager_secret_version" "postgres_url" {
secret_id = aws_secretsmanager_secret.postgres_url.id
# sslmode=require pairs with rds.force_ssl=1 in the parameter group:
# the client refuses plaintext, the server refuses plaintext, no
# gap between the two.
secret_string = format(
"postgresql+psycopg2://%s:%s@%s:%d/%s",
"postgresql+psycopg2://%s:%s@%s:%d/%s?sslmode=require",
var.postgres_username,
random_password.postgres.result,
aws_db_instance.main.address,
Expand Down