<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Building a Highly Available Web Tier on AWS Using Terraform]]></title><description><![CDATA[Building a Highly Available Web Tier on AWS Using Terraform]]></description><link>https://twoassignment.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 09:48:38 GMT</lastBuildDate><atom:link href="https://twoassignment.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Building a Highly Available Web Tier on AWS with Terraform
]]></title><description><![CDATA[Github repo: Modern cloud applications are not built on a single server anymore. They are designed to be highly available, scalable, and resilient. In this…]]></description><link>https://twoassignment.hashnode.dev/building-a-highly-available-web-tier-on-aws-with-terraform</link><guid isPermaLink="true">https://twoassignment.hashnode.dev/building-a-highly-available-web-tier-on-aws-with-terraform</guid><dc:creator><![CDATA[Muhammad Hashim]]></dc:creator><pubDate>Wed, 29 Apr 2026 10:04:11 GMT</pubDate><content:encoded><![CDATA[<p><strong>Github repo:</strong> <a href="https://github.com/HashimZaffar/Asignment-2">https://github.com/HashimZaffar/Asignment-2</a></p>
<p>Modern cloud applications are not built on a single server anymore. They are designed to be <strong>highly available, scalable, and resilient</strong>. In this project, I built a production-style web tier on AWS using Terraform that distributes traffic across multiple servers, scales automatically, and supports rolling updates with minimal downtime.</p>
<p>This assignment is a continuation of multi-environment Terraform concepts and focuses on building a <strong>real-world web architecture</strong> using Infrastructure as Code.</p>
<hr />
<h1>Project Objective</h1>
<p>The goal of this project was to design and deploy a <strong>highly available web tier</strong> using Terraform.</p>
<p>The infrastructure includes:</p>
<ul>
<li><p>2 EC2 instances across different Availability Zones</p>
</li>
<li><p>Application Load Balancer (ALB)</p>
</li>
<li><p>Auto Scaling Group (ASG)</p>
</li>
<li><p>Launch Template</p>
</li>
<li><p>CloudWatch alarms for scaling</p>
</li>
<li><p>Rolling updates for zero/minimal downtime</p>
</li>
<li><p>Remote state using S3</p>
</li>
<li><p>State locking using DynamoDB</p>
</li>
</ul>
<hr />
<h1>Why Highly Available Architecture Matters</h1>
<p>A basic setup looks like this:</p>
<pre><code class="language-text">User → EC2
</code></pre>
<p>If that EC2 instance fails, the application goes down.</p>
<p>A highly available setup looks like this:</p>
<pre><code class="language-text">User
 ↓
Application Load Balancer
 ↓
Auto Scaling Group
 ↓
EC2 (AZ-1)
EC2 (AZ-2)
</code></pre>
<p>This design ensures:</p>
<ul>
<li><p>No single point of failure</p>
</li>
<li><p>Traffic is distributed</p>
</li>
<li><p>Failed instances are replaced automatically</p>
</li>
<li><p>Application remains accessible</p>
</li>
</ul>
<hr />
<h1>Project Structure</h1>
<pre><code class="language-text">Asignment-2/
├── modules/
│   ├── network/
│   ├── security/
│   ├── alb/
│   └── asg/
└── environments/
    └── dev/
</code></pre>
<p>The project is divided into:</p>
<ul>
<li><p><strong>Modules</strong> → reusable infrastructure components</p>
</li>
<li><p><strong>Environment folder</strong> → actual deployment configuration</p>
</li>
</ul>
<hr />
<h1>Core Terraform Concepts Used</h1>
<h2>Infrastructure as Code</h2>
<p>Infrastructure is written as code instead of manually creating resources in AWS.</p>
<p>Terraform reads <code>.tf</code> files and creates resources automatically.</p>
<hr />
<h2>Modules</h2>
<p>Modules are reusable blocks of Terraform code.</p>
<p>This project uses modules for:</p>
<ul>
<li><p>Network</p>
</li>
<li><p>Security</p>
</li>
<li><p>Load Balancer</p>
</li>
<li><p>Auto Scaling</p>
</li>
</ul>
<p>Instead of repeating code, modules are written once and reused.</p>
<hr />
<h2>Remote Backend</h2>
<p>Terraform state is stored in an S3 bucket instead of locally.</p>
<p>This ensures:</p>
<ul>
<li><p>State is not lost</p>
</li>
<li><p>Multiple users can collaborate</p>
</li>
<li><p>Infrastructure is tracked centrally</p>
</li>
</ul>
<hr />
<h2>State Locking</h2>
<p>DynamoDB is used to lock Terraform state.</p>
<p>This prevents multiple users from running Terraform at the same time and breaking the infrastructure state.</p>
<hr />
<h1>Step-by-Step Architecture Breakdown</h1>
<h2>1. Network Layer</h2>
<p>The network module creates:</p>
<ul>
<li><p>VPC</p>
</li>
<li><p>Internet Gateway</p>
</li>
<li><p>2 public subnets in different AZs</p>
</li>
<li><p>Route table</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-hcl">resource "aws_vpc" "this" {
  cidr_block = var.vpc_cidr
}
</code></pre>
<p>Each environment gets its own isolated network.</p>
<hr />
<h2>2. Security Layer</h2>
<p>Two security groups are created:</p>
<h3>ALB Security Group</h3>
<ul>
<li>Allows HTTP (port 80) from the internet</li>
</ul>
<h3>EC2 Security Group</h3>
<ul>
<li><p>Allows HTTP only from ALB</p>
</li>
<li><p>Allows SSH from trusted IP</p>
</li>
</ul>
<p>This ensures:</p>
<pre><code class="language-text">User → ALB → EC2
</code></pre>
<p>Users cannot directly access EC2 instances.</p>
<hr />
<h2>3. Load Balancer Layer</h2>
<p>The Application Load Balancer:</p>
<ul>
<li><p>Receives traffic from users</p>
</li>
<li><p>Distributes traffic across EC2 instances</p>
</li>
<li><p>Performs health checks</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-hcl">resource "aws_lb" "this" {
  load_balancer_type = "application"
}
</code></pre>
<hr />
<h2>Target Group</h2>
<p>Defines backend servers:</p>
<pre><code class="language-hcl">resource "aws_lb_target_group" "this" {
  port     = 80
  protocol = "HTTP"
}
</code></pre>
<hr />
<h2>Listener</h2>
<p>Handles incoming requests:</p>
<pre><code class="language-hcl">resource "aws_lb_listener" "http" {
  port     = 80
  protocol = "HTTP"
}
</code></pre>
<hr />
<h1>4. Compute Layer (Auto Scaling)</h1>
<h2>Launch Template</h2>
<p>Defines how EC2 instances should be created:</p>
<pre><code class="language-hcl">resource "aws_launch_template" "this" {
  image_id      = var.ami_id
  instance_type = var.instance_type
}
</code></pre>
<hr />
<h2>User Data Script</h2>
<p>Automatically installs Nginx and creates a webpage:</p>
<pre><code class="language-bash">apt-get install -y nginx
</code></pre>
<p>This means EC2 instances become web servers automatically.</p>
<hr />
<h2>Auto Scaling Group</h2>
<p>Controls EC2 instances:</p>
<pre><code class="language-hcl">resource "aws_autoscaling_group" "this" {
  min_size         = 2
  desired_capacity = 2
  max_size         = 4
}
</code></pre>
<p>This ensures:</p>
<ul>
<li><p>At least 2 instances are always running</p>
</li>
<li><p>New instances are added when needed</p>
</li>
<li><p>Unhealthy instances are replaced</p>
</li>
</ul>
<hr />
<h1>5. CloudWatch Scaling</h1>
<h2>Scale Out</h2>
<pre><code class="language-hcl">threshold = 70
</code></pre>
<p>If CPU &gt; 70% → add instance</p>
<h2>Scale In</h2>
<pre><code class="language-hcl">threshold = 30
</code></pre>
<p>If CPU &lt; 30% → remove instance</p>
<p>This allows automatic scaling based on load.</p>
<hr />
<h1>6. Rolling Updates (Zero Downtime)</h1>
<p>Rolling updates replace instances gradually.</p>
<p>Example:</p>
<pre><code class="language-hcl">instance_refresh {
  strategy = "Rolling"
}
</code></pre>
<p>Flow:</p>
<pre><code class="language-text">New instance created
Health check passes
Old instance removed
Repeat
</code></pre>
<p>This avoids downtime during updates.</p>
<hr />
<h1>Environment Configuration</h1>
<p>All modules are connected in:</p>
<pre><code class="language-text">environments/dev/main.tf
</code></pre>
<p>Example:</p>
<pre><code class="language-hcl">module "network" {
  source = "../../modules/network"
}
</code></pre>
<p>Variables are defined in:</p>
<pre><code class="language-text">terraform.tfvars
</code></pre>
<p>Example:</p>
<pre><code class="language-hcl">environment      = "dev"
instance_type    = "t2.micro"
desired_capacity = 2
</code></pre>
<hr />
<h1>Terraform Workflow</h1>
<pre><code class="language-bash">terraform init
terraform fmt
terraform validate
terraform plan
terraform apply
</code></pre>
<p>After deployment, Terraform outputs:</p>
<pre><code class="language-text">alb_dns_name
</code></pre>
<p>Open it in browser:</p>
<pre><code class="language-text">http://ALB-DNS
</code></pre>
<p>You will see the web page served by EC2 instances.</p>
<hr />
<h1>Scaling in Action</h1>
<ul>
<li><p>Refresh the page multiple times</p>
</li>
<li><p>Different instance IDs may appear</p>
</li>
<li><p>This shows traffic is distributed</p>
</li>
</ul>
<p>Under load:</p>
<ul>
<li><p>ASG adds instances</p>
</li>
<li><p>ALB routes traffic</p>
</li>
<li><p>System scales automatically</p>
</li>
</ul>
<hr />
<h1>Security Best Practices</h1>
<p>For real production:</p>
<ul>
<li><p>Restrict SSH to your IP</p>
</li>
<li><p>Use private subnets for EC2</p>
</li>
<li><p>Enable HTTPS on ALB</p>
</li>
<li><p>Apply least privilege IAM roles</p>
</li>
<li><p>Encrypt S3 backend</p>
</li>
<li><p>Avoid storing secrets in code</p>
</li>
</ul>
<hr />
<h1>Cleanup</h1>
<p>To avoid AWS charges:</p>
<pre><code class="language-bash">terraform destroy
</code></pre>
<hr />
<h1>Skills Demonstrated</h1>
<p>This project demonstrates:</p>
<ul>
<li><p>Terraform architecture design</p>
</li>
<li><p>AWS networking fundamentals</p>
</li>
<li><p>High availability design</p>
</li>
<li><p>Load balancing</p>
</li>
<li><p>Auto Scaling</p>
</li>
<li><p>CloudWatch monitoring</p>
</li>
<li><p>Rolling updates</p>
</li>
<li><p>Infrastructure as Code</p>
</li>
<li><p>DevOps workflow using Git</p>
</li>
</ul>
<hr />
<h1>Portfolio Value</h1>
<p>This project is a strong portfolio example because it shows real-world thinking.</p>
<p>Instead of just creating a server, it demonstrates:</p>
<ul>
<li><p>Reliability</p>
</li>
<li><p>Scalability</p>
</li>
<li><p>Automation</p>
</li>
<li><p>Clean architecture</p>
</li>
</ul>
<p>This aligns with expectations for:</p>
<ul>
<li><p>DevOps Engineers</p>
</li>
<li><p>Cloud Engineers</p>
</li>
<li><p>Platform Engineers</p>
</li>
<li><p>Site Reliability Engineers</p>
</li>
</ul>
<hr />
<h1>Final Thoughts</h1>
<p>This assignment shows how modern cloud systems are designed.</p>
<p>It moves beyond basic infrastructure and introduces concepts like:</p>
<ul>
<li><p>High availability</p>
</li>
<li><p>Scaling</p>
</li>
<li><p>Load balancing</p>
</li>
<li><p>Automation</p>
</li>
</ul>
<p>In simple terms:</p>
<p><strong>You built a system where your application can survive failures, handle more users, and update safely — all using Terraform code.</strong></p>
<p>This is the foundation of real-world DevOps.</p>
]]></content:encoded></item></channel></rss>