Immutable Infrastructure: How to Deploy Nginx Using Packer, Ansible, and Terraform in AWS — with One Script
Brief Overview
Immutable Infrastructure is an operational strategy wherein servers, VMs, or containers are never updated in place after deployment, instead, they are replaced with a new build. Some benefits include the elimination of configuration drift, consistency among environments (i.e. development, staging, and production), reliable rollback strategy, and simplified horizontal autoscaling.
To illustrate, today we will be using Hashicorp Packer, an open-source tool used to automate the building of machine images across various platforms such as AWS and Azure. This article will serve as a step-by-step guide to deploying an Nginx in AWS mainly using Packer and Terraform with a single bash script.
Architecture
The diagram above shows our target AWS infrastructure right after the script has been completely and successfully executed. In the end, we should be able to see Nginx running from our browser using the Public IP Address of the Nginx EC2 server.