|
1 |
| -# Traefik-DNS-Module |
| 1 | +# ☁️ Fully Automated SSL + Reverse Proxy with Terraform + Traefik + Cloudflare |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +> 🔧 Built entirely by a **2nd-year university student** during an internship — fully automated and production-ready. |
| 6 | +
|
| 7 | +--- |
| 8 | + |
| 9 | +## 🚀 About This Project |
| 10 | + |
| 11 | +This project automates SSL certificate issuance, DNS record creation, and reverse proxy setup for internal services running on **private servers without public IPs**. It uses: |
| 12 | + |
| 13 | +- **Terraform** for orchestration |
| 14 | +- **Traefik** for reverse proxy and HTTPS |
| 15 | +- **Cloudflare DNS** for domain management |
| 16 | +- **MinIO** as the Terraform backend |
| 17 | +- **Twingate** (or other zero-trust solutions) for private server access |
| 18 | + |
| 19 | +All of it is wrapped into reusable Terraform modules to spin up a full reverse proxy setup — with just one command. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## 🧱 Stack |
| 24 | + |
| 25 | +- **Terraform** (with `null`, `cloudflare`, and `aws` providers) |
| 26 | +- **Traefik v2.10** |
| 27 | +- **Cloudflare DNS** |
| 28 | +- **MinIO** (as an S3 backend for Terraform) |
| 29 | +- **Twingate** (for private network access) |
| 30 | +- **Bash** (for server-side automation) |
| 31 | +- **Systemd** (to manage the Traefik service) |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## 📂 Directory Structure |
| 36 | + |
| 37 | +``` |
| 38 | +. |
| 39 | +├── main.tf |
| 40 | +├── variables.tf |
| 41 | +├── terraform.tfvars |
| 42 | +├── modules/ |
| 43 | +│ └── traefik/ |
| 44 | +│ ├── main.tf |
| 45 | +├── scripts/ |
| 46 | +│ ├── setup_traefik.sh |
| 47 | +│ └── clean_treafik.sh |
| 48 | +├── files/ |
| 49 | +│ ├── traefik.toml |
| 50 | +│ └── traefik.service |
| 51 | +└── README.md |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## 🔧 Requirements |
| 57 | + |
| 58 | +- A domain managed via Cloudflare |
| 59 | +- A Cloudflare API Key / API Token |
| 60 | +- SSH access to internal/private servers |
| 61 | +- [MinIO](https://min.io/) server for Terraform backend (or any compatible S3 service) |
| 62 | +- [Twingate](https://www.twingate.com/) (or other private VPN solution) |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## 📦 Deployment |
| 67 | + |
| 68 | +### Step 1: Configure Variables |
| 69 | + |
| 70 | +Fill in your values in `terraform.tfvars`: |
| 71 | + |
| 72 | +```hcl |
| 73 | +cloudflare_api_email = "[email protected]" |
| 74 | +cloudflare_api_key = "your-global-api-key" |
| 75 | +cloudflare_zone_id = "zone-id" |
| 76 | +controller2_server_ip = "192.168.0.2" |
| 77 | +ssh_user = "root" |
| 78 | +ssh_private_key_path = "~/.ssh/id_rsa" |
| 79 | +``` |
| 80 | + |
| 81 | +### Step 2: Deploy Traefik |
| 82 | + |
| 83 | +```bash |
| 84 | +terraform apply -target=null_resource.traefik_deployment |
| 85 | +``` |
| 86 | + |
| 87 | +### Step 3: Add Services |
| 88 | + |
| 89 | +```hcl |
| 90 | +module "service_portainer" { |
| 91 | + source = "./modules/traefik" |
| 92 | + service_name = "portainer" |
| 93 | + domain = "portainer.example.com" |
| 94 | + backend_url = "http://192.168.0.3:9443" |
| 95 | + cloudflare_email = var.cloudflare_api_email |
| 96 | + cloudflare_api_token = var.cloudflare_api_token |
| 97 | + server_two_ip = var.controller2_server_ip |
| 98 | + ssh_user = var.ssh_user |
| 99 | + ssh_private_key_path = var.ssh_private_key_path |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +### Step 4: Access via browser |
| 104 | + |
| 105 | +Navigate to `https://portainer.example.com` with valid SSL, issued automatically via Let's Encrypt. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## 🤝 Contributing |
| 110 | + |
| 111 | +Contributions are welcome! If you’d like to: |
| 112 | +- Add support for more providers |
| 113 | +- Add health checks or monitoring |
| 114 | +- Enhance module structure |
| 115 | + |
| 116 | +Feel free to fork the repo and submit a PR! |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## 👨💻 Author |
| 121 | + |
| 122 | +Made with 💻 by **Yasindu Dissanayake** a 2nd year CS student & DevOps intern passionate about automating infrastructure. |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## 📜 License |
| 127 | + |
| 128 | +Licensed under the **Apache 2.0 License**. |
| 129 | +Feel free to fork, build upon, and contribute. |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## 🧠 Final Thoughts |
| 134 | + |
| 135 | +No public IPs? 🕵️ |
| 136 | +No Nginx? 🛑 |
| 137 | +One command? ✅ |
| 138 | + |
| 139 | +Just pure Terraform + Traefik + Cloudflare DNS magic. |
| 140 | + |
| 141 | +**Now imagine what I’ll build next.** |
| 142 | + |
0 commit comments