Terraform and API Evolution

Learn how Terraform can be used to replace a legacy web app.

A challenge faced by Bleacher Report

As Bleacher Report took their first steps in replacing a legacy web application, one of their initial challenges was visualizing how to go from a single application to potentially many without disrupting the service. They opted for an approach where the new service was completely decoupled from the legacy application but the legacy application had to be changed to talk to this new system via an HTTP client. This worked well in their case, since the functionality they were isolating was quite focused. While a good chunk of their system would depend on this new service, the service in itself depended on little else.

You may not be so lucky, however. Depending on your application, you may be hard-pressed to find a subsystem that doesn’t depend on other core components, such as authentication. For this reason, many companies choose the authentication service to be the first to be replaced or extracted from the legacy system. This can get quite complex because we need both old and new code to have the same logic when it comes to encryption of passwords and generation of tokens.

Need for Terraform

In this lesson, we’ll explore one particular approach to migrating legacy web applications. We’ll replace a legacy application with Lauren Tan and Dan McClain’s Terraform library. Terraforming is the act of transforming a planet to resemble the Earth, especially so that it can support human life. The Terraform library allows us to wrap endpoints of our web application and replace them with an Elixir alternative. That allows us to change our “planet” as smoothly as possible by keeping the overall web API the same while we work in small increments, replacing a single API at a time. Terraform handles the rest. We don’t need to change all of our endpoints at once because Terraform proxies unhandled legacy requests and hands them off to the old system.

Example of Terraform

Let’s take a look at Lauren’s example applicationfor a Terraform primer. Like any other dependency, the first step is to add it to the mix.exs file in our projects:

Get hands-on with 1400+ tech skills courses.