resource "aws_db_subnet_group" "this" {
  count      = var.subnet_ids != "" ? 1 : 0
  name       = "nova-ci-rds-subnet-group"
  subnet_ids = split(",", var.subnet_ids)
}

resource "aws_db_instance" "this" {
  engine               = var.engine
  engine_version       = var.engine_version
  instance_class       = var.instance_class
  allocated_storage    = var.allocated_storage
  db_name              = var.db_name
  username             = var.username
  password             = var.password
  multi_az             = var.multi_az
  storage_encrypted    = var.storage_encrypted
  kms_key_id           = var.kms_key_arn
  skip_final_snapshot  = true
  publicly_accessible  = false
  db_subnet_group_name = var.subnet_ids != "" ? aws_db_subnet_group.this[0].name : null
}
