Arash Mohammadi’s Post

🚀 New Project: Multi-Environment Terraform Deployment with GitLab CI/CD One thing every DevOps engineer encounters early on: how do you manage dev, staging, and prod infrastructure without duplicating code or risking state conflicts? Here's what I built to solve exactly that What the project does: A fully automated IaC pipeline that provisions isolated AWS environments (develop + prod) from a single Terraform codebase, triggered automatically by GitLab CI/CD on every push. How it works: → Push to develop → pipeline runs → staging EC2 deployed (manual approval required) → Merge to main → pipeline runs → prod EC2 deployed (automatic) → Each environment gets its own isolated Terraform state in S3 → State locking prevents concurrent pipeline runs from corrupting infrastructure Stack: • Terraform Workspaces: one codebase, multiple isolated environments • AWS S3: remote backend for shared, versioned state storage • GitLab CI/CD: 3-stage pipeline: validate → plan → apply • AWS EC2 + Security Groups: environment-tagged resources • IAM: least-privilege service account for the pipeline Key lessons learned: • TF_WORKSPACE is a reserved Terraform variable, naming your CI variable the same breaks workspace selection silently (fun one to debug 🙃) • GitLab Protected variables are only injected into protected branches, unprotect them if your pipeline runs on feature/develop branches • Terraform 1.10+ native S3 locking (use_lockfile) replaces the DynamoDB dependency, simpler and cleaner • Manual approval gates in CI aren't just a safety net, they're standard practice in real teams Why this matters for interviews: Remote state, workspace isolation, and branch-based deployment strategies are questions I now get asked about, and can answer from real hands-on experience, not just theory. Full project with README guide on GitHub: https://lnkd.in/dgNT_NTe #DevOps #Terraform #GitLabCI #AWS #InfrastructureAsCode #CloudEngineering #IaC #Berlin #OpenToWork

To view or add a comment, sign in

Explore content categories