DEV Community

Cover image for πŸš€ Terraform Day 17: Blue-Green Deployment on AWS Using Terraform
Jeeva
Jeeva

Posted on

πŸš€ Terraform Day 17: Blue-Green Deployment on AWS Using Terraform

🎯 What Is Blue-Green Deployment?

Blue-Green deployment maintains two identical production environments:
Blue β†’ currently serving live users
Green β†’ idle environment used for deploying and testing the new version

The deployment flow is simple and powerful:
Deploy the new application version to the idle environment
Test it thoroughly
Swap traffic from Blue β†’ Green
If something goes wrong, swap back instantly
No redeploys. No rebuilds. No panic.

πŸ— Architecture Used in Day 17

The project uses the following AWS components:
S3 Bucket – Stores application artifacts (ZIP files)
Elastic Beanstalk Application

Two Elastic Beanstalk Environments
Blue (Production)
Green (Staging / New Version)

IAM Roles & Policies
Terraform IaC to manage everything
Both environments are identical in configuration β€” only the deployed application version differs.

βš™οΈ Terraform Deployment Flow

Terraform is used to:
Create the S3 bucket
Upload application versions
Define Elastic Beanstalk application
Create two separate environments
Attach correct IAM roles
Apply autoscaling and health settings
Manage environment variables and tags

Standard Terraform workflow is followed:
terraform init
terraform plan
terraform apply

After apply:
Blue environment runs version 1.0
Green environment runs version 2.0
Both environments are live and accessible via separate URLs

πŸ” Swapping Traffic (Blue ↔ Green)

Traffic switching is performed by swapping environment CNAMEs in Elastic Beanstalk.

What happens during swap:
DNS pointers are updated
User traffic moves to the new environment
Old environment becomes idle
No redeployment occurs
Minimal to zero downtime

From a user perspective:
πŸ‘‰ The application URL stays the same
πŸ‘‰ The version changes transparently

πŸ”™ Rollback Strategy

Rollback is extremely simple:
Perform another environment swap
Traffic returns to the previous stable version

This is one of the biggest advantages of Blue-Green deployment:
βœ” Rollback is instant
βœ” No rebuild required
βœ” No infrastructure changes

🏁 Conclusion

Day 17 demonstrates how modern deployments are done safely.
By combining:
Terraform (IaC)
Elastic Beanstalk
S3-based versioning
Blue-Green strategy
you get a robust, low-risk deployment workflow suitable for real production systems.

This session clearly shows that Terraform is not just about creating infrastructure β€”
it’s about operating systems reliably at scale.

Top comments (0)