Provision a RDB on AWS using Terraform
In this article, we are going to provision a Postgres Database in it’s own VPC. You can find the code here.
Pre-requisites:
- Free Tier AWS Account
- Terraform installed
- AWS CLI configured — this will allow terraform to execute
Running the code
You will see 9 resources being added, and at the end of the terraform apply command you should see this output
To see the sensitive database_password value run terraform output database_password
What happens in the background
These are the steps running when you execute terraform apply
- Creating a VPC
- Creating 2 subnets for the Database
- Associate Route table with the database subnets
- Creating the DB Subnet Group
- Allow Traffic on DB port (egress/ingress) using Security Group
- Creating the Database on the DB subnet group
Cleanup
Once you are all done with testing, make sure to delete the resources so you aren’t billed.
You can destroy the resources created by running terraform destroy