Have the following DB resource in tf file:
resource "aws_db_instance" "app_db" {
count = local.db_count
allocated_storage = 5
max_allocated_storage = 10
engine = "postgres"
instance_class = "db.t3.micro"
name = var.db_creds["db_name"]
port = 5432
username = var.db_creds["username"]
password = var.db_creds["password"]
db_subnet_group_name = aws_db_subnet_group.database_sg.name
vpc_security_group_ids = [aws_security_group.app.id]
final_snapshot_identifier = "${var.environment_deployment_tag}-app-db-snaphot"
}
After destroying DB resource I get this error:
DBSnapshotAlreadyExists: Cannot create the snapshot because a snapshot with the identifier app-db-snaphot already exists
I understand that it is because snapshot with such identifier already exists but I'd like to ask if there is a way to override previous snapshot?
If no and all snapshots should have unique name, I guess format something like this should be fine:
final_snapshot_identifier = "${var.environment_deployment_tag}-app-db-snaphot-${timestamp()}"
I wonder how to clean up previous snapshots so on RDS won't be a lot of them? And what is the best approach to manage final snapshot?