9 Zero Downtime Deployments
This chapter covers:
- Customizing resource lifecycles with the create_before_destroy flag
- Performing Blue/Green deployments with Terraform
- Combining Terraform with Ansible
- Generating SSH keypairs automatically with the TLS provider
- Installing software on virtual machines with remote-exec provisioners
Traditionally, there has been a window of time during software deployments when servers are incapable of serving production traffic. This window is typically scheduled for early morning off-hours to minimize downtime, but it still impacts availability. Zero Downtime Deployment (ZDD) is the practice of keeping services always running and available to customers, even in the midst of software updates. If executed well, users should not even be aware when changes are being made to the system.
In this chapter we will investigate three approaches to achieving zero downtime deployments with Terraform. First, will use the create_before_destroy meta-attribute to ensure that an application is running and passing health checks before tearing down the old one. The create_before_destroy meta-attribute alters how force new updates are internally handled by Terraform. By setting it to true, interesting and unexpected behavior can result.