Terraform + Docker + Nginx + Git Branching Workflow

By | December 2, 2025

๐Ÿ“Œ Project Overview

This project demonstrates:

  • Provisioning a local Docker containerย running Nginx usingย Terraform.
  • Usingย Git branching strategyย to manage multiple versions of the project.
  • Tagging versions in Git for release management.

๐Ÿ“‚ Branch Structure

We are using three branches:

Branch NamePurposeProject Content
mainStable production-ready code.Contains the final tested project that provisions an Nginx container via Terraform.
devDevelopment environment for ongoing work.Same core functionality as main but used for testing new changes before merging.
feature-add-indexExperimental feature branch for adding a custom index.html page in the Nginx container.Includes Terraform code + a mounted custom HTML file.

๐Ÿ” Why We Use Branches

  • Isolationย โ†’ Work on new features without breaking production.
  • Parallel Developmentย โ†’ Multiple developers can work on different tasks simultaneously.
  • Safe Testingย โ†’ Test changes inย devย orย featureย before merging intoย main.

๐Ÿ†š How Branch Projects Differ

  • mainย โ†’ Only deploys a default Nginx container.
  • devย โ†’ Mirrors main but used for intermediate testing.
  • feature-add-indexย โ†’ Adds a mounted HTML file for custom homepage.

Note: In our current setup, dev and feature-add-index have similar Terraform structure, but feature-add-index contains additional files for the custom index page.


๐Ÿท๏ธ Why We Use Tags

Tags are used to:

  • Markย release versionsย (e.g.,ย v1.0).
  • Quickly roll back to a known working state.
  • Provide a reference for deployment without using a branch.

๐Ÿ“Œ Example Tagging Commands

# Create a tag
git tag v1.0

# Push tag to remote
git push origin v1.0
๐Ÿ› ๏ธ How to Test Each Branch
bash
Copy
Edit
# Clone the repository
git clone https://github.com/jaspreet237/terraform-docker-nginx-gitflow.git
cd terraform-docker-nginx-gitflow

# Switch to a branch
git checkout main      # or dev / feature-add-index

# Initialize Terraform
terraform init

# Plan and apply
terraform plan
terraform apply -auto-approve

# Access Nginx
http://localhost:8081
๐Ÿ“œ Tasks Completed in This Project
Created Git repository and connected it to GitHub.

Created multiple branches (main, dev, feature-add-index).

Implemented Terraform configuration to run Nginx in Docker.

Tested all branches to verify they work independently.

Added Git tags to mark release versions.

Documented the project in Markdown for better understanding.

๐Ÿ“ฆ Tech Stack
Terraform โ†’ Infrastructure as Code (IaC)

Docker โ†’ Containerized Nginx server

Git โ†’ Version control

GitHub โ†’ Remote repository hosting

Leave a Reply

Your email address will not be published. Required fields are marked *