<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> Bitovi Blog - UX and UI design, JavaScript and Frontend development
Loading

DevOps |

RDS Database Upgrade via Terraform: Lessons Learned

Upgrading your RDS Database via Terraform? Read this post first! Three key lessons learned from upgrading our RDS database with Terraform.

Chris Capell

Chris Capell

Twitter Reddit

Upgrading an RDS database to a newer version in AWS via Terraform is a straightforward process. I learned a few lessons along the way, and I hope my lessons save you time and energy. Let’s jump in!

How It Started

Hopefully, you have a repository with the Terraform used to create your RDS database. I found ours in an operations repository with BitOps configured to deploy any changes I made. I updated the engine version in Terraform, the changes were deployed, and nothing happened. It took a few minutes of research, but then I learned the first of three lessons I will share with you.

Lesson #1 - Changes Are Applied in the Maintenance Window

While you can click-ops your upgrade to happen immediately, the default in Terraform is to apply during the maintenance window. When I looked at the pending changes, I could see my upgrade in the queue. I waited days for the maintenance window, and at the prescribed time, the database upgraded itself.

If you are using the module terraform-aws-modules/rds/aws there is an option that can be set to apply the change immediately. Just add a line that says apply_immediately = true. Use caution when using this setting, especially in a Production environment. The apply_immediately setting is not just for the current Terraform but for anything in the future that would normally be queued for the next maintenance window. This could cause unexpected outages from maintenance running during normal operational hours.

Also note that when Terraform queues the changes for the maintenance window, Terraform will report a success once the change is in the queue. If you have apply_immediately set to true, Terraform will wait for the change to complete before exiting.

Lesson #2 - The Outage Isn’t as Long as You’d Expect

You should expect a short outage while upgrading the database. In my experience, it was much shorter than I expected. The outage was just a couple of minutes while the instance was restarted. The total time taken was under 15 minutes for a small single-instance database. While the database was available during most of the upgrade, I wouldn’t recommend using the database during the upgrade process.

Lesson #3 - Snapshots

We all know the importance of good backups before we start an upgrade. Luckily the process that Amazon uses to upgrade an RDS database includes a pre-upgrade snapshot. There is a second one immediately after the upgrade completes.

Conclusion

Upgrading an RDS database using Terraform is a straightforward process. In understanding how the process works, you can be sure that the upgrade happens when you expect it, with minimal impact on your users.

Need Help?

Bitovi has consultants that can help. Drop into Bitovi's Community Slack, and talk to us in the #devops channel!

Need DevOps consulting services? Book a free consultation to learn from our expert DevOps consultants!


Never miss an update!

Subscribe to the blog 📬

️ Subscribe