Practical GitOps: Building Infrastructure Deployment Control with Atlantis and OpenTofu on VPS
A detailed guide on implementing real-world GitOps using Atlantis and OpenTofu on a VPS for managing infrastructure code, automation, and consistency.
Image credit: viarami · Pixabay Content License
Introduction to GitOps and the Role of Atlantis, OpenTofu
GitOps is an infrastructure-as-code (IaC) methodology where all infrastructure changes are managed through Git. With GitOps, every change is made via a Pull Request (PR), reviewed, approved, and automatically deployed. This approach ensures consistency, change control, and easy traceability.
Atlantis is an automation tool for IaC workflows, integrating with Git to automatically run terraform plan and apply when a PR is created. OpenTofu, an open-source fork of Terraform, offers similar infrastructure deployment capabilities without dependency on HashiCorp.
In this guide, we will build a practical GitOps system on a VPS using Atlantis and OpenTofu, enabling automated, secure, and controlled infrastructure deployment.
Prerequisites and Environment Setup
To deploy a GitOps system with Atlantis and OpenTofu, you need:
- A VPS with at least 4GB RAM (see: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways)
- Linux (Ubuntu 22.04 or Debian 11)
- Git, Docker, Docker Compose
- OpenTofu (version 1.10+)
- GitHub or GitLab (for storing source code)
Setting Up Atlantis and OpenTofu on VPS
Follow these steps to set up the environment:
- Install OpenTofu:
- Create project directory:
- Initialize OpenTofu project:
- Run Atlantis using Docker:
sudo apt update
sudo apt install -y wget gnupg
wget -qO - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update
sudo apt install -y tofutwo
mkdir -p /opt/gitops/infra
cd /opt/gitops/infra
tofutwo init
docker run -d --name atlantis -p 3000:3000 \
-e ATLANTIS_GITHUB_USER=your-username \
-e ATLANTIS_GITHUB_TOKEN=your-token \
-e ATLANTIS_GITHUB_HOST=github.com \
-e ATLANTIS_REPO_ALLOWLIST=* \
-e ATLANTIS_REPO_CONFIG=/atlantis/config.yaml \
-v /opt/gitops/infra:/atlantis/repos \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /root/.ssh:/root/.ssh \
-v /tmp/atlantis:/tmp/atlantis \
runatlantis/atlantis:latest
Setting Up Git and Automating Deployments
To integrate with Git, perform the following:
- Create a repository on GitHub/GitLab and push your OpenTofu code.
- In the project directory, create the
atlantis.yamlfile: - Run
tofutwo planto validate the configuration. - Push changes to Git and create a PR. Atlantis will automatically run
planand wait for approval. - Once the PR is approved, Atlantis will execute
apply.
version: 3
projects:
- name: infra
dir: .
workspace: default
terraform_version: 1.10.0
terraform_init_options:
- -upgrade
autoplan:
when_modified:
- "*.tf"
- "*.tfvars"
enabled: true
apply_requirements: [approved, mergeable]
Verification and Troubleshooting
To verify the system is working correctly:
- Access
http://to view the Atlantis interface.:3000 - Ensure PRs are processed correctly.
- Debug issues by checking Docker logs:
docker logs atlantis. - Confirm OpenTofu has proper access to the VPS and required resources.
References
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
