Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—οΈ Kodesesh Infrastructure (Terraform)

Terraform Docker Linux IaC

Production-grade Infrastructure as Code for VPS automation

Features β€’ Architecture β€’ Usage β€’ Security


πŸ“‹ Overview

This repository contains the Infrastructure as Code (IaC) configuration for the Kodesesh project, implementing automated VPS preparation using Terraform. The infrastructure follows real-world DevOps practices by clearly separating infrastructure management from application deployment.

🎯 Purpose

Terraform is used to prepare and standardize a long-running VPS, ensuring it's always ready for CI/CD-based application deployments. This setup maintains infrastructure readiness while keeping the deployment pipeline separate and clean.


✨ Features

What Terraform Manages

βœ… Docker Engine Installation - Ensures Docker is installed and up-to-date
βœ… Service Management - Docker service is enabled and running
βœ… Network Configuration - Creates and maintains kodesesh-network
βœ… Environment Preparation - Ensures required configuration files exist
βœ… Idempotent Operations - Safe to run multiple times without side effects
βœ… Infrastructure State - Declarative configuration for consistent results

What Terraform Does NOT Manage

❌ Application container deployment
❌ Container lifecycle management
❌ Secret values or sensitive data
❌ CI/CD pipeline execution
❌ VPS creation or destruction

Design Philosophy: Infrastructure preparation and application deployment are intentionally separated to follow DevOps best practices.


πŸ›οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Kodesesh Infrastructure                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Terraform (IaC Layer)  β”‚         β”‚   CI/CD (App Layer)      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                          β”‚         β”‚                          β”‚
β”‚  β€’ Docker Installation   β”‚         β”‚  β€’ Build Docker Images   β”‚
β”‚  β€’ Service Enablement    │────────▢│  β€’ Push to Registry      β”‚
β”‚  β€’ Network Creation      β”‚         β”‚  β€’ Deploy Containers     β”‚
β”‚  β€’ Environment Setup     β”‚         β”‚  β€’ Manage Lifecycle      β”‚
β”‚  β€’ VPS Readiness         β”‚         β”‚  β€’ Rolling Updates       β”‚
β”‚                          β”‚         β”‚                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                                      β”‚
         β”‚                                      β”‚
         β–Ό                                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Production VPS                          β”‚
β”‚  β€’ Ubuntu/Debian Server                                      β”‚
β”‚  β€’ Docker Network: kodesesh-network                          β”‚
β”‚  β€’ Environment File: /home/sagar/environmnet-file.env               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Repository Structure

terraform/
β”œβ”€β”€ πŸ“„ main.tf                 # Main infrastructure configuration
β”œβ”€β”€ πŸ“„ provider.tf             # Provider and connection settings
β”œβ”€β”€ πŸ“„ variables.tf            # Variable definitions
β”œβ”€β”€ πŸ”’ .terraform.lock.hcl     # Dependency lock file
β”œβ”€β”€ 🚫 .gitignore              # Git ignore rules
β”œβ”€β”€ πŸ“ scripts/
β”‚   └── setup_vps.sh           # VPS initialization script
└── πŸ“– README.md               # This file

πŸš€ Getting Started

Prerequisites

  • Terraform v1.0 or higher (Install Guide)
  • SSH Access to target VPS
  • Root or sudo privileges on the VPS
  • SSH Key configured for passwordless authentication

Installation

  1. Clone the repository
   git clone https://github.com/yourusername/kodesesh-infrastructure.git
   cd kodesesh-infrastructure/terraform
  1. Initialize Terraform
   terraform init

This downloads required providers and prepares the working directory.

  1. Review the configuration
   terraform plan

Examine what changes Terraform will make to your infrastructure.

  1. Apply the configuration
   terraform apply

Type yes when prompted to confirm the changes.

Configuration

Before running Terraform, ensure you have:

  1. SSH Configuration - Set up SSH access in provider.tf:
   connection {
     type        = "ssh"
     host        = var.vps_ip
     user        = var.ssh_user
     private_key = file(var.ssh_private_key_path)
   }
  1. Variables - Define in terraform.tfvars (not committed):
   vps_ip                = "your.vps.ip.address"
   ssh_user              = "your-user"
   ssh_private_key_path  = "~/.ssh/id_rsa"
  1. Environment File - Ensure /home/sagar/environmnet-file.env exists on the VPS with required application variables (contents managed externally).

πŸ”§ Usage Examples

Check Infrastructure State

terraform show

Validate Configuration

terraform validate

Format Configuration Files

terraform fmt

Destroy Infrastructure (if needed)

terraform destroy

Re-apply Infrastructure

terraform apply -auto-approve

Infrastructure is idempotent - safe to run multiple times


πŸ” Security

What's Protected

βœ… SSH Keys - Never committed to repository
βœ… State Files - Excluded via .gitignore
βœ… Environment Variables - Values managed externally
βœ… Secrets - Handled via CI/CD or secure provisioning
βœ… Terraform Variables - Sensitive values in terraform.tfvars (gitignored)

Security Best Practices

  1. Never commit sensitive data

    • State files contain infrastructure details
    • Use remote state backends for team environments
    • Keep terraform.tfvars out of version control
  2. Environment file management

    • Terraform ensures /home/sagar/kodesesh.env exists
    • File contents are provisioned separately
    • Secrets stored in CI/CD variables or vault solutions
  3. SSH key security

    • Use SSH keys with passphrases
    • Restrict key permissions (chmod 600)
    • Use different keys for different environments

.gitignore Configuration

# Terraform files
*.tfstate
*.tfstate.*
.terraform/
terraform.tfvars
*.tfvars

# Sensitive files
*.pem
*.key

🧠 Design Decisions

Why Terraform for Infrastructure?

  • Declarative Configuration - Define desired state, not steps
  • Idempotency - Safe to run multiple times
  • Version Control - Infrastructure changes are tracked
  • Reproducibility - Consistent across environments

Why NOT Kubernetes?

For a single-node VPS deployment:

  • Kubernetes adds unnecessary complexity
  • Docker Compose provides sufficient orchestration
  • Easier to maintain and debug
  • Lower resource overhead
  • Faster deployment cycles

Separation of Concerns

Concern Managed By Why
Infrastructure Terraform Reproducible, versioned setup
Secrets CI/CD Variables Prevents leakage via state files
Deployment GitHub Actions Application-specific logic
Runtime Docker Container orchestration

πŸŽ“ Skills Demonstrated

This project showcases:

  • βœ… Infrastructure as Code (IaC) with Terraform
  • βœ… VPS Automation and standardization
  • βœ… Docker service and network management
  • βœ… Idempotent Infrastructure design
  • βœ… Security Best Practices for secrets management
  • βœ… DevOps Principles - separation of concerns
  • βœ… Production-Ready infrastructure patterns
  • βœ… Real-World Decision Making - avoiding over-engineering

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages