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 key pairs with the TLS provider
  • Installing software on VMs 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 during software updates. If a ZDD is executed well, users should not be aware when changes are being made to the system.

In this chapter, we investigate three approaches to achieving ZDDs with Terraform. First, we use the create_before_destroy meta attribute to ensure that an application is running and passing health checks before we tear down the old instance. The create_before_destroy meta attribute alters how force-new updates are handled internally by Terraform. When it’s set 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

Summary

sitemap