Skip to content

This project provisions and configures a scalable infrastructure on OpenNebula using Terraform for resource management, Ansible for post-provisioning configuration, and Docker for containerization. It includes a load balancer with dynamically configurable backend nodes.

Notifications You must be signed in to change notification settings

VandlJ/iac-loadbalancer-automation

Repository files navigation

Dynamic Load Balancer with Terraform, Ansible, and Docker

Table of Contents

  1. Overview
  2. Features
  3. Repository Structure
  4. Demo
  5. Prerequisites
  6. Setup Instructions
  7. Configuration

Overview

This project provides a fully automated setup for deploying a dynamic load balancer and backend services on OpenNebula, leveraging modern tools like:

  • Terraform: For resource provisioning.
  • Ansible: For software configuration and deployment.
  • Docker: For containerization of services.

The solution includes:

  • An Apache-based load balancer.
  • Configurable backend server nodes.
  • Full automation for scaling and configuration.

Features

  • Dynamic Scaling: Modify the number of backend nodes via a single Terraform variable.
  • Infrastructure as Code (IaC): Reproducible, maintainable, and version-controlled infrastructure setup.
  • Automated Configuration Management: Ansible ensures consistent environment setup across all nodes.
  • Lightweight Containerization: Docker is used for deploying scalable services.

Repository Structure

.devcontainer/
  Dockerfile                # Dockerfile for building the dev environment
  devcontainer.json         # Dev container configuration
  docker-compose.yml        # Docker Compose file for the containerized dev environment
  init-iac-dev.sh           # Script to initialize SSH keys in the dev container
.github/workflows/
  main.yml                  # GitHub Actions workflow for CI/CD
ansible/
  roles/
    backend/
      tasks/
        main_tasks.yml      # Backend-specific Ansible tasks
      templates/
        index.html.j2       # Jinja2 template for backend web content
    load_balancer/
      tasks/
        main_tasks.yml      # Load balancer-specific Ansible tasks
      templates/
        apache              # Apache configuration templates
  inventory                 # Ansible inventory file for host management
  playbook.yml              # Main playbook orchestrating tasks
terraform/
  terraform.tf              # Terraform configuration for OpenNebula
  terraform.tfvars          # User-defined variables for Terraform
  variables.tf              # Terraform variables file
apache.conf.tmpl            # Template for Apache load balancer config
README.md                   # This documentation file

Demo

To see the project in action, visit the deployed application in your browser here: Load Balancer or put this command in your terminal:

curl http://147.228.173.116

Prerequisites

Before getting started, ensure the following tools are installed on your system:

  • Docker: For running the development environment.
  • Terraform: For provisioning cloud resources.
  • Ansible: For configuring nodes.

Setup Instructions

Step 1: Clone the Repository

git clone https://github.com/VandlJ/iac-loadbalancer-automation.git
cd iac-loadbalancer-automation

Step 2: Run directory inside of Docker container

Step 3: Initialize and Apply Terraform

terraform init
terraform plan
terraform apply -auto-approve

This initializes, plans and applies confirguration for Terraform.

Step 4: Configure the Infrastructure with Ansible

ansible-playbook -i ansible/inventory ansible/playbook.yml

Configuration

To scale the number of backend servers, edit the variables.tf file in the Terraform configuration directory. For example:

variable "backend_count" {
  default = 3
}

After modifying the variable, reapply the Terraform configuration:

terraform apply -auto-approve

About

This project provisions and configures a scalable infrastructure on OpenNebula using Terraform for resource management, Ansible for post-provisioning configuration, and Docker for containerization. It includes a load balancer with dynamically configurable backend nodes.

Resources

Stars

Watchers

Forks

Packages

No packages published