Production-grade Infrastructure as Code for VPS automation
Features β’ Architecture β’ Usage β’ Security
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.
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.
β
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
β 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.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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
- 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
- Clone the repository
git clone https://github.com/yourusername/kodesesh-infrastructure.git
cd kodesesh-infrastructure/terraform- Initialize Terraform
terraform initThis downloads required providers and prepares the working directory.
- Review the configuration
terraform planExamine what changes Terraform will make to your infrastructure.
- Apply the configuration
terraform applyType yes when prompted to confirm the changes.
Before running Terraform, ensure you have:
- 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)
}- Variables - Define in
terraform.tfvars(not committed):
vps_ip = "your.vps.ip.address"
ssh_user = "your-user"
ssh_private_key_path = "~/.ssh/id_rsa"- Environment File - Ensure
/home/sagar/environmnet-file.envexists on the VPS with required application variables (contents managed externally).
terraform showterraform validateterraform fmtterraform destroyterraform apply -auto-approveInfrastructure is idempotent - safe to run multiple times
β
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)
-
Never commit sensitive data
- State files contain infrastructure details
- Use remote state backends for team environments
- Keep
terraform.tfvarsout of version control
-
Environment file management
- Terraform ensures
/home/sagar/kodesesh.envexists - File contents are provisioned separately
- Secrets stored in CI/CD variables or vault solutions
- Terraform ensures
-
SSH key security
- Use SSH keys with passphrases
- Restrict key permissions (
chmod 600) - Use different keys for different environments
# Terraform files
*.tfstate
*.tfstate.*
.terraform/
terraform.tfvars
*.tfvars
# Sensitive files
*.pem
*.key- Declarative Configuration - Define desired state, not steps
- Idempotency - Safe to run multiple times
- Version Control - Infrastructure changes are tracked
- Reproducibility - Consistent across environments
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
| 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 |
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