Skip to main content

How Can Terraform Help With Multi-Cloud Disaster Recovery?

When you can build a DR environment on the fly, your DR planning can be much more dynamic.



Nobody likes to think about disaster recovery. We hope that a disaster won't strike and that a meteor won't hit our datacenter or that the server won't catch on fire. But accidents happen. Sometimes things go the wrong way, and we need to be prepared for these situations.

In disaster recovery, the most important thing is, “How quickly can I get this application back up and running?” Typically it can take days or weeks to rebuild a complex infrastructure.

Many organizations actually run a whole different datacenter just for their disaster recovery purposes. This can be expensive, because now you have production over here, and you have to have an exact copy of production in a different datacenter running all the time so that it's ready and you don't have to go ahead and build a new production environment when a disaster happens. It's very costly and difficult to maintain because you've got to have 2 of everything now.

Faster, cheaper DR with Terraform

Terraform allows you to be much more dynamic with your disaster recovery plans because you can literally build a DR environment on the fly.

If you could stand up your disaster recovery environment in 10 minutes, it may not make sense to keep it running all the time. The cloud enables you to stand up infrastructure on demand, and that's where Terraform comes in. Terraform can help you very quickly stand up a new infrastructure or new production environments in a different region or even on a different cloud provider in a very short period of time.

Terraform works with any cloud provider

Terraform is a multicloud solution, so I can use Terraform to stand up my application on Amazon or GCP or Azure, Oracle Cloud, Alibaba. Because it's multicloud-friendly, I can use it to build my infrastructure anywhere.

Let's say a disaster did happen. This is a litmus test; you can do this in your own environment: Walk into your server cage or your datacenter and think about what would happen if you unplugged one of those machines. I used to work with a sysadmin and he would give tours of the datacenter. Our sysadmin was very proud of the fact that you could unplug any cable. He would challenge the customer sometimes: "Go ahead, pick a cable, unplug it. You won't take anything down because everything has a backup."

Better DR with infrastructure as code

Ask yourself, "What would happen if that machine caught fire? How would I rebuild it?" If the answer is anything other than, "I have my infrastructure as code and I can stand that thing right back up," then you need to work on your DR strategy some more.

The first step to a successful DR strategy with Terraform is to define all your infrastructure as code. There should be zero manual steps involved, and you should know with confidence that, "Hey, if I need to rebuild that thing, no problem. I'm going to go ahead and run this Terraform command, stand up a copy of production, and keep on moving."

Terraform can be core to your DR strategy

Let's say the datacenter went completely down and we need to fail over to a different datacenter or a cloud environment. You can use Terraform to very quickly stand up all the application infrastructure and get everything ready. So Terraform can be a core piece of your DR recovery plans.

One thing that Terraform won't do, though, is back up your data, so it's very important that you have a good backup strategy to use along with Terraform so that, once your servers and applications are up and running, you also have the databases and everything that you need to keep your environments up and running.

Practice makes perfect, even with DR

Another thing to keep in mind is that a DR plan without practice is not really a DR plan. You should be doing regular tests of your DR strategy just to make sure that, when things really go wrong, you know it will work because you tested it last week or last month. Terraform makes this very easy. You can use Terraform to stand up copies of your environment and do practice runs, like a fire drill. Make sure that your DR plans work before the disaster happens and not after.

Terraform can be an essential part of your disaster recovery strategy because it helps you stand up new infrastructure very quickly and efficiently.

More resources like this one

  • 3/15/2023
  • Presentation

Advanced Terraform techniques

  • 2/3/2023
  • Case Study

Automating Multi-Cloud, Multi-Region Vault for Teams and Landing Zones

  • 2/1/2023
  • Case Study

Should My Team Really Need to Know Terraform?

  • 1/20/2023
  • Case Study

Packaging security in Terraform modules