Terraform RDS module with DNS setup
I love not having to manage databases. Hosting it on your compute is guaranteed to be cheaper, but I don't want to be constantly worrying about backups and database upgrade / maintenance.
AWS offers managed databases, known as RDS. Mostly I use postgres, which works well for most use cases. (It's also a given that - if you don't really need NoSQL database, then don't use it).
If I spin up RDS postgres, I can reach it assuming I have set up the correct networking pathways. (And you shouldn't expose your database to public, unless it's for playground with no sensitive data.)
RDS itself returns a hostname with following format: mydb.123456789012.us-east-1.rds.amazonaws.com
. This works well for all intent and purposes, but there are some cases where you might want it to be easy to remember, or that you want to switch database instance without incurring downtime. A simple solution is to setup a DNS record, but it would be nice if you can set it all up during database creation!
Enough intro, below is the terraform code (and yes, this works for a replica as well):