top of page
  • Writer's pictureTim Burns

Jump-start Postgres Development with Terraform

Ensuring your development work will merge neatly with a production system is critical to success. A dirty secret of development databases is that they are usually out of sync. If you don't take care, you be one of those "well, it worked in development" kind of coders. Don't be that developer.

An excellent way to jump-start your Postgres development is to automate the creation of a development database based on the production database where you intend to deploy your code. That way, you can develop your application in an environment that corresponds to how you will release it to customers.

Start with a working Postgres database. My previous post describes how to use the AWS console to create the database. I recommend using the AWS console to set up your Postgres instance the first time, and then automating the task either with an AWS command tool or with Terraform, which I will detail in this article.

If you created a standard AWS database, then you have daily snapshots of the data. Locate the snapshot data in the AWS console to create a development database. Browse to the "Maintenance & backups" tab on your RDS database.

At the bottom of the page, a list will show the daily snapshots RDS creates. Pick one and create a Terraform template. The template using Terraform variables to handle domain-specific items like region, db_subnet_group_name and vpc_security_group_ids.

You may want to in addition, create external variables as I have done for example var.region, var.db_subgroup_name and vpc_security_group_ids.

The above template will specify to create a DEV database that is publicly accessible and the same as your PRODUCTION database. Of course, you may want to change the "publically_accessible" setting to false, in which case, you can.

Now you will use Terraform to create the database. Note here that I am using shared variables for all my projects. The project on GITHUB has all the details.

When the Terraform creation is complete, you will have an exact clone of your production database ready for developing new features for your customers.

When you finish developing, you can clean up your development database.

Automating the creation and deletion using Terraform has the added benefit that you can spin up a Postgres instance when you need one and not be charged for an active database server when you aren't using one.

9 views0 comments

Recent Posts

See All


bottom of page