chapter four

4 Deploying a Multi-Tiered Web Application in AWS

 

This chapter covers:

  • Deploying a multi-tiered web application in AWS with Terraform
  • Setting project variables in a variables definition files
  • Organizing code with nested modules
  • Leveraging modules from the public module registry
  • Passing data between modules using input variables and output values

Highly available and scalable web hosting has been a complex and expensive proposition until relatively recently. In fact, it wasn’t until AWS released their Elastic Compute Service (EC2) in 2006 that things started changing for the better. EC2 was the first pay-as-you-go service that enabled customers to provision to nearly infinite capacity on-demand. As great as EC2 was, there existed a significant tooling gap that could not be met with CloudFormation, nor existing configuration management tools. Terraform was designed to fill this tooling gap, which is why we are now going to look at how Terraform solves this problem. In this chapter we are going to deploy a highly available and scalable multi-tiered web application in AWS.

Figure 4.1 Typical Multi-Tiered Web Application

4.1    Architecture

4.2    Terraform Modules

4.2.1   Module Syntax

4.2.2   What is the Root Module?

4.2.3   Standard Module Structure

4.3    Root Module

4.3.1   Code

4.4    Networking Module

4.5    Database Module

4.5.1   Passing Data from the Networking Module

4.5.2   Generating a Random Password

4.6    Autoscaling Module

4.6.1   Trickling Down Data

4.6.2   Templating a Cloud Init Config

4.7    Deploying the Web Application

4.8    Fireside Chat

4.9    Summary