Automating Terraform Workflows on a VPS: A Comprehensive Guide to Deploying Atlantis for GitOps
Introduction to GitOps and Infrastructure Automation
In the modern DevOps landscape, Managing Infrastructure as Code (IaC) has transitioned from a progressive luxury to an absolute necessity. Terraform has long stood as the industry standard for defining and provisioning cloud resources. However, as engineering teams scale, standard local executions of terraform plan and terraform apply introduce significant operational risks, configuration drift, and collaboration bottlenecks. Standardizing execution environments is critical for stability.
Enter Atlantis, an open-source application that transforms how teams interact with Terraform by shifting the execution layer directly into your Version Control System (VCS), such as GitHub, GitLab, or Bitbucket. By running Atlantis on a dedicated Virtual Private Server (VPS), you can establish a centralized, secure, and fully automated GitOps pipeline. This guide explores the architecture, prerequisites, and step-by-step configuration required to deploy Atlantis on a VPS, empowering your team to review, collaborate on, and approve Terraform scripts directly within Pull Requests (PRs).
Why Atlantis? Overcoming Traditional Terraform Bottlenecks
Before diving into the configuration details, it is essential to understand the core challenges that Atlantis addresses in a collaborative engineering environment:
- Shared State Synchronization: When multiple developers run Terraform locally, concurrent executions can lead to state file corruption, even with remote state locking enabled. Atlantis centralizes execution, ensuring only one pipeline modifies the state at any given time.
- Visibility and Auditability: Traditional CI/CD platforms often hide Terraform plan outputs inside deeply nested job logs. Atlantis comments the exact
terraform planoutput directly onto the Pull Request, offering immediate visibility to code reviewers. - Access Control and Security: Instead of granting high-level cloud provider permissions (AWS, Azure, GCP) to every developer's local machine, credentials are securely stored only on the Atlantis VPS. Developers require nothing more than repository access to trigger infrastructure changes.
By moving the execution of infrastructure changes to a centralized, Pull Request-driven workflow, organizations achieve a higher level of governance, minimize human error, and accelerate deployment cycles.
Prerequisites for VPS Deployment
To successfully follow this guide, ensure that you have the following components and access rights ready:
- A Dedicated VPS: A Linux-based VPS (Ubuntu 22.04 LTS or later recommended) with a public IP address, minimum 2 vCPUs, and 4GB of RAM.
- Domain Name and SSL Certificate: A registered domain name pointing to your VPS IP address, with SSL configured (via Let's Encrypt / Certbot) to secure webhook traffic.
- Version Control System Access: Administrative privileges on a GitHub or GitLab repository to create Webhooks and personal access tokens.
- Cloud Provider Credentials: IAM roles or programmatic keys with sufficient access to provision your target infrastructure.
Step 1: Preparing the VPS Environment
First, access your VPS via SSH and update the system packages to ensure stability and security. Run the following commands:
sudo apt update && sudo apt upgrade -y
sudo apt install -y unzip curl git snapdNext, install the specific version of the Terraform CLI required for your infrastructure. It is highly recommended to match the version specified in your repository's required_version block.
curl -fsSL [https://apt.releases.hashicorp.com/gpg](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](https://apt.releases.hashicorp.com) $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.0/hashicorp.list
sudo apt update && sudo apt install terraform -yStep 2: Installing and Configuring Atlantis
Download the latest stable binary of Atlantis from the official releases repository. Ensure you select the architecture corresponding to your VPS (usually amd64 or arm64).
VERSION="v0.27.2"
wget [https://github.com/runatlantis/atlantis/releases/download/$](https://github.com/runatlantis/atlantis/releases/download/$){VERSION}/atlantis_linux_amd64.zip
unzip atlantis_linux_amd64.zip
sudo mv atlantis /usr/local/bin/
atlantis versionConfiguring the Atlantis Systemd Service
To ensure Atlantis runs continuously in the background and restarts automatically upon server reboots, create a dedicated systemd service file. First, create a system user for security isolation:
sudo useradd --system --no-create-home --shell /bin/false atlantisNow, create the service file at /etc/systemd/system/atlantis.service using your preferred text editor and add the following configuration:
[Unit]
Description=Atlantis Terraform Automation
After=network.target
[Service]
Type=simple
User=atlantis
EnvironmentFile=/etc/atlantis/atlantis.env
ExecStart=/usr/local/bin/atlantis server --config /etc/atlantis/atlantis.yaml
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetStep 3: Integrating Atlantis with Your Version Control System (GitHub Example)
For Atlantis to listen for Pull Request events, you must configure a bidirectional communication channel between your VPS and GitHub.
1. Create a GitHub Personal Access Token (PAT)
Atlantis requires a PAT to comment on Pull Requests and manipulate repository states. Navigate to GitHub Developer Settings and generate a classic token with the following scopes:
repo(Full control of private repositories)admin:repo_hook(Full control of repository hooks)
2. Generate a Webhook Secret
Generate a secure random string that will be used to validate that incoming webhook payloads originate from GitHub, protecting your Atlantis server from unauthorized requests:
openssl rand -hex 323. Configure the Webhook in GitHub
Navigate to your repository's Settings > Webhooks > Add webhook and input the following details:
- Payload URL:
[https://atlantis.yourdomain.com/events](https://atlantis.yourdomain.com/events) - Content type:
application/json - Secret: Paste the random string generated in the previous step.
- Which events: Select Let me select individual events and check Issue comments, Pull requests, Pull request reviews, and Pushes.
Step 4: Defining the Configuration Files
Create the secure environment file at /etc/atlantis/atlantis.env to store sensitive tokens and cloud provider credentials securely:
ATLANTIS_GH_TOKEN="ghp_YourGitHubPersonalAccessToken"
ATLANTIS_GH_WEBHOOK_SECRET="YourWebhookSecretString"
ATLANTIS_DATA_DIR="/var/lib/atlantis"
AWS_ACCESS_KEY_ID="YOUR_AWS_KEY"
AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET"Next, create the primary configuration file at /etc/atlantis/atlantis.yaml to outline server operational boundaries:
atlantis-url: "[https://atlantis.yourdomain.com](https://atlantis.yourdomain.com)"
gh-user: "atlantis-bot"
repo-allowlist: "[github.com/your-organization/](https://github.com/your-organization/)*"
port: 4141
log-level: "info"Set appropriate file permissions so only the atlantis user can access these sensitive credentials:
sudo mkdir -p /etc/atlantis /var/lib/atlantis
sudo chown -R atlantis:atlantis /etc/atlantis /var/lib/atlantis
sudo chmod 600 /etc/atlantis/atlantis.envStart and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable atlantis
sudo systemctl start atlantisStep 5: Verifying the Automation Workflow
With Atlantis active on your VPS, it is time to test the complete GitOps workflow. Follow these operational steps:
- Create a new branch in your infrastructure repository and modify a Terraform file (e.g., adding a new security group rule or an S3 bucket).
- Commit the changes and open a Pull Request against the main branch.
- Observe that Atlantis automatically intercepts the event, executes
terraform planinside the VPS, and prints the structural plan directly as a comment on the PR. - To apply the changes, a authorized reviewer simply needs to type a comment containing
atlantis apply. Atlantis executes the deployment and logs the successful output directly back into the conversation history.
Conclusion and Best Practices
Deploying Atlantis on a private VPS successfully bridges the gap between infrastructure management and code review culture. To maintain a highly secure and resilient setup, remember to implement these best practices:
- State Locking: Always enforce remote state backend locking (such as AWS DynamoDB or HashiCorp Consul) alongside Atlantis server-side locking to prevent collision risks.
- Least Privilege Access: Ensure the cloud credentials provided to the Atlantis server follow the principle of least privilege, restricting access solely to the resources it is designed to manage.
- Regular Auditing: Periodically rotate your GitHub Personal Access Tokens and monitor the system logs (
journalctl -u atlantis) to track operational health and ensure security compliance.
