Files
2026-10-12 14:25:05 -04:00

48 lines
1.6 KiB
Terraform

# The kryptkeeper Hub's database. manage_master_user_password = true hands
# the master password to AWS's own Secrets Manager-backed rotation instead
# of a Terraform-known value, so the password itself is never written to
# Terraform state (state is a plaintext artifact by default; see this
# module's README for the remote-backend encryption requirement this still
# implies for every other attribute).
resource "aws_db_subnet_group" "this" {
name = "${var.name_prefix}-db"
subnet_ids = var.subnet_ids
tags = merge(var.tags, {
Name = "${var.name_prefix}-db-subnet-group"
})
}
resource "aws_db_instance" "this" {
identifier = "${var.name_prefix}-db"
engine = "postgres"
engine_version = var.engine_version
instance_class = var.instance_class
allocated_storage = var.allocated_storage
max_allocated_storage = var.allocated_storage * 2
storage_type = "gp3"
storage_encrypted = true
db_name = var.db_name
username = var.username
manage_master_user_password = true
db_subnet_group_name = aws_db_subnet_group.this.name
vpc_security_group_ids = var.vpc_security_group_ids
publicly_accessible = false
multi_az = var.multi_az
backup_retention_period = var.backup_retention_period
deletion_protection = var.deletion_protection
skip_final_snapshot = var.skip_final_snapshot
final_snapshot_identifier = var.skip_final_snapshot ? null : "${var.name_prefix}-db-final"
copy_tags_to_snapshot = true
tags = merge(var.tags, {
Name = "${var.name_prefix}-db"
})
}