chapter nine

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.

9.1    Lifecycle Customizations

9.1.1   Zero Downtime Deployments with create_before_destroy

9.1.2   Additional Considerations

9.2    Blue/Green Deployments

9.2.1   Architecture

9.2.2   Code

9.2.3   Deploy

9.2.4   Blue/Green Cutover

9.2.5   Additional Considerations

9.3    Configuration Management

9.3.1   Combining Terraform with Ansible

9.3.2   Code

9.3.3   Infrastructure Deployment

9.3.4   Application Deployment

9.4    Fireside Chat

9.5    Summary