seahaven-ap/terraform/aurora.tf

64 lines
1.6 KiB
HCL

resource "aws_security_group" "aurora" {
name = "${local.project}-aurora"
description = "Aurora for seahaven-ap"
vpc_id = local.vpc_id
ingress {
description = "Postgres from Fargate"
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.api.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_db_subnet_group" "api" {
name = local.project
subnet_ids = local.private_subnet_ids
tags = {
Name = "${local.project}-db"
}
}
resource "aws_rds_cluster" "api" {
cluster_identifier = local.project
engine = "aurora-postgresql"
engine_mode = "provisioned"
engine_version = "16.6"
database_name = "seahaven_ap"
master_username = "seahaven"
master_password = random_password.db.result
db_subnet_group_name = aws_db_subnet_group.api.name
vpc_security_group_ids = [aws_security_group.aurora.id]
storage_encrypted = true
backup_retention_period = 1
skip_final_snapshot = true
apply_immediately = true
copy_tags_to_snapshot = true
enable_http_endpoint = false
serverlessv2_scaling_configuration {
min_capacity = 0.5
max_capacity = 1
}
tags = {
Name = local.project
}
}
resource "aws_rds_cluster_instance" "api" {
identifier = "${local.project}-1"
cluster_identifier = aws_rds_cluster.api.id
instance_class = "db.serverless"
engine = aws_rds_cluster.api.engine
engine_version = aws_rds_cluster.api.engine_version
}