Immutable Infrastructure: How to Deploy Nginx Using Packer, Ansible, and Terraform in AWS — with One Script

Ronie Horca
8 min readJul 31, 2023

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

Provisioned AWS Resources

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.

--

--

Ronie Horca
Ronie Horca

Written by Ronie Horca

Senior DevSecOps Engineer | Health & Fitness Enthusiast | DevSecOps Evangelist | Expertise in Digital Transformations (FinTech, Big Data, Machine Learning)