Skip to content

Repository files navigation

🚀 Terraform Modular Infrastructure for a Full-Stack Application

Terraform Docker PostgreSQL React Django

This project demonstrates how to design and provision a modular Infrastructure as Code (IaC) solution using Terraform and the Docker provider. The infrastructure deploys a complete three-tier application composed of a PostgreSQL database, a Django REST API backend, and a React frontend while following Terraform best practices for modularity and reusability.

🗺️ Project Architecture

                            Terraform
                              │
              ┌───────────────┼────────────────┐
              │               │                │
        Docker Network   Docker Volume    Docker Images
              │               │
              ├───────────────┼──────────────────────────┐
              │               │                          │
        PostgreSQL      Django Backend           React Frontend

Project Goals

This project was created to practice and demonstrate Terraform best practices, including:

  • Infrastructure as Code (IaC)
  • Modular architecture
  • Docker resource management
  • Reusable Terraform modules
  • Infrastructure organization

Technologies

  • Terraform
  • Docker Provider
  • Docker
  • PostgreSQL
  • Django REST Framework
  • React
  • GitHub Container Registry / Harbor

📁 Repository Structure


terraform/
├── main.tf                   # Root module that orchestrates child modules
├── variables.tf              # Global input variables
├── outputs.tf                # Root outputs
├── providers.tf              # Provider configuration
├── versions.tf               # Terraform and provider version constraints
├── README.md
└── modules/
    ├── db/
    ├── backend/
    └── client/

Modules

----------------------------------------------------
| Module  | Responsibility                         |
| ------- | -------------------------------------- |
| db      | Creates PostgreSQL image and container |
| backend | Deploys Django REST API container      |
| client  | Deploys React frontend container       |

Module Architecture

                      Root Module
                          │
              ┌────────────┼────────────┐
              │            │            │
          db module   backend module  client module
              │            │            │
      PostgreSQL      Django API     React App

Prerequisites

  • Docker Engine
  • Terraform >= 1.0
  • Docker Provider (kreuzwerker/docker)
  • Access to the container registry

Quick Start

git clone https://github.com/yclicourt/terraform-modules-task-app-fullstack.git

cd terraform-taskapp

cp terraform.tfvars.example terraform.tfvars

terraform init

terraform apply

Configuration

Before running Terraform create:

cp terraform.tfvars.example terraform.tfvars

Deployment

terraform init

terraform plan

terraform apply

Destroy

terraform destroy

Features

  • Modular Terraform architecture
  • Docker infrastructure provisioning
  • Private container registry integration
  • Persistent PostgreSQL storage
  • Network isolation
  • Environment based configuration

Terraform Concepts Demonstrated

  • Root and child modules
  • Input variables
  • Output values
  • Provider configuration
  • Docker resources
  • Resource dependencies
  • Persistent volumes
  • Custom Docker networks
  • Modular Infrastructure as Code

Why Modules?

The infrastructure is divided into reusable modules to separate responsibilities:

  • Database module
  • Backend module
  • Frontend module

This structure improves maintainability, reusability and scalability while following Terraform best practices.

Project Status

✔ Completed

Current implementation includes:

  • Terraform modular architecture
  • Docker provider
  • PostgreSQL container
  • Django backend
  • React frontend
  • Custom Docker network
  • Persistent Docker volume

License

MIT License

🗺️ Screenshots

  • Terraform Plan Terraform Plan

  • Terraform apply Terraform Apply

  • Frontend App Frontend

  • Django Rest API Backend

Future Improvements

  • GitHub Actions CI/CD
  • Remote Backend (S3, GCS or Azure Storage)
  • Secret management with Vault
  • Kubernetes deployment using Terraform
  • Helm integration

About

Repository to represent the use of terraform, modules using a fullstack task application

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages