|
| 1 | +# Atlantis Setup Guide |
| 2 | + |
| 3 | +This guide will help you set up Atlantis for your GitOps repository to enable Terraform and Helm automation via GitHub comments. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **GitHub Personal Access Token** or **GitHub App** |
| 8 | +2. **Domain name** for Atlantis (or use port-forwarding for testing) |
| 9 | +3. **Kubernetes cluster** with ArgoCD running |
| 10 | + |
| 11 | +## Setup Steps |
| 12 | + |
| 13 | +### 1. Create GitHub Personal Access Token |
| 14 | + |
| 15 | +1. Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic) |
| 16 | +2. Click "Generate new token (classic)" |
| 17 | +3. Give it a name like "Atlantis GitOps" |
| 18 | +4. Select scopes: |
| 19 | + - `repo` (Full control of private repositories) |
| 20 | + - `write:discussion` (Write team discussions) |
| 21 | + - `admin:org` (if using organization webhooks) |
| 22 | +5. Copy the token (you won't see it again!) |
| 23 | + |
| 24 | +### 2. Create GitHub App (Alternative to Personal Access Token) |
| 25 | + |
| 26 | +If you prefer using a GitHub App: |
| 27 | + |
| 28 | +1. Go to GitHub Settings → Developer settings → GitHub Apps |
| 29 | +2. Click "New GitHub App" |
| 30 | +3. Fill in: |
| 31 | + - **GitHub App name**: `atlantis-gitops` |
| 32 | + - **Homepage URL**: `https://atlantis.yourdomain.com` |
| 33 | + - **Webhook URL**: `https://atlantis.yourdomain.com/events` |
| 34 | + - **Webhook secret**: Generate a random string |
| 35 | +4. Select permissions: |
| 36 | + - **Repository permissions**: |
| 37 | + - Contents: Read |
| 38 | + - Issues: Write |
| 39 | + - Pull requests: Write |
| 40 | + - Metadata: Read |
| 41 | + - **Subscribe to events**: |
| 42 | + - Pull request |
| 43 | + - Issue comment |
| 44 | + - Pull request review |
| 45 | +5. Download the private key |
| 46 | + |
| 47 | +### 3. Update Atlantis Configuration |
| 48 | + |
| 49 | +Edit `helm/atlantis/values.yaml`: |
| 50 | + |
| 51 | +```yaml |
| 52 | +atlantis: |
| 53 | + env: |
| 54 | + # Update these values |
| 55 | + ATLANTIS_REPO_ALLOWLIST: "github.com/nwthomas/gitops" # Your repo |
| 56 | + ATLANTIS_ATLANTIS_URL: "https://atlantis.yourdomain.com" # Your domain |
| 57 | + GITHUB_USER: "nwthomas" # Your GitHub username |
| 58 | + |
| 59 | + # If using GitHub App, uncomment and set: |
| 60 | + # GITHUB_APP_ID: "123456" # Your GitHub App ID |
| 61 | +``` |
| 62 | + |
| 63 | +### 4. Create Kubernetes Secret |
| 64 | + |
| 65 | +Create the secret with your GitHub token: |
| 66 | + |
| 67 | +```bash |
| 68 | +# For Personal Access Token |
| 69 | +kubectl create secret generic atlantis-secrets \ |
| 70 | + --from-literal=github-token="YOUR_GITHUB_TOKEN" \ |
| 71 | + -n atlantis |
| 72 | + |
| 73 | +# For GitHub App (also include the private key) |
| 74 | +kubectl create secret generic atlantis-secrets \ |
| 75 | + --from-literal=github-token="YOUR_GITHUB_TOKEN" \ |
| 76 | + --from-file=github-app-key=path/to/your/private-key.pem \ |
| 77 | + -n atlantis |
| 78 | +``` |
| 79 | + |
| 80 | +### 5. Set Up GitHub Webhook |
| 81 | + |
| 82 | +1. Go to your repository settings → Webhooks |
| 83 | +2. Click "Add webhook" |
| 84 | +3. Fill in: |
| 85 | + - **Payload URL**: `https://atlantis.yourdomain.com/events` |
| 86 | + - **Content type**: `application/json` |
| 87 | + - **Secret**: (if using GitHub App, use the webhook secret) |
| 88 | + - **Events**: Select "Let me select individual events" |
| 89 | + - Pull requests |
| 90 | + - Issue comments |
| 91 | + - Pull request reviews |
| 92 | +4. Click "Add webhook" |
| 93 | + |
| 94 | +### 6. Deploy Atlantis |
| 95 | + |
| 96 | +1. Commit and push your changes to the repository |
| 97 | +2. ArgoCD will automatically deploy Atlantis |
| 98 | +3. Check the deployment: |
| 99 | + |
| 100 | +```bash |
| 101 | +kubectl get pods -n atlantis |
| 102 | +kubectl get svc -n atlantis |
| 103 | +kubectl get ingress -n atlantis |
| 104 | +``` |
| 105 | + |
| 106 | +### 7. Test the Setup |
| 107 | + |
| 108 | +1. Create a test pull request that modifies files in the `/helm` directory |
| 109 | +2. Comment on the PR: `atlantis plan` |
| 110 | +3. Atlantis should respond with a plan |
| 111 | +4. If the plan looks good, comment: `atlantis apply` |
| 112 | +5. Atlantis will apply the changes |
| 113 | + |
| 114 | +## Usage |
| 115 | + |
| 116 | +### Available Commands |
| 117 | + |
| 118 | +- `atlantis plan` - Run terraform plan |
| 119 | +- `atlantis apply` - Apply terraform changes |
| 120 | +- `atlantis plan -p <project>` - Plan specific project |
| 121 | +- `atlantis apply -p <project>` - Apply specific project |
| 122 | +- `atlantis unlock` - Unlock a locked workspace |
| 123 | +- `atlantis help` - Show help |
| 124 | + |
| 125 | +### Project Structure |
| 126 | + |
| 127 | +Atlantis monitors these directories: |
| 128 | +- `/helm/*` - Helm charts |
| 129 | +- `/terraform` - Terraform configurations |
| 130 | +- `/argocd/apps/*` - ArgoCD applications |
| 131 | + |
| 132 | +### Security Features |
| 133 | + |
| 134 | +- **User Restriction**: Only `nwthomas` can run Atlantis commands |
| 135 | +- **Approval Required**: All changes require PR approval |
| 136 | +- **Mergeable Required**: PR must be mergeable before applying |
| 137 | +- **Repository Allowlist**: Only your specific repository is allowed |
| 138 | + |
| 139 | +## Troubleshooting |
| 140 | + |
| 141 | +### Check Atlantis Logs |
| 142 | + |
| 143 | +```bash |
| 144 | +kubectl logs -f deployment/atlantis -n atlantis |
| 145 | +``` |
| 146 | + |
| 147 | +### Verify Webhook Delivery |
| 148 | + |
| 149 | +1. Go to your repository → Settings → Webhooks |
| 150 | +2. Click on your webhook |
| 151 | +3. Check "Recent Deliveries" for any failed deliveries |
| 152 | + |
| 153 | +### Common Issues |
| 154 | + |
| 155 | +1. **Webhook not working**: Check the webhook URL and secret |
| 156 | +2. **Permission denied**: Verify GitHub token has correct permissions |
| 157 | +3. **Atlantis not responding**: Check logs and ensure the service is running |
| 158 | +4. **Terraform errors**: Check the terraform configuration and state |
| 159 | + |
| 160 | +### Port Forwarding for Testing |
| 161 | + |
| 162 | +If you don't have a domain set up yet: |
| 163 | + |
| 164 | +```bash |
| 165 | +kubectl port-forward svc/atlantis 4141:4141 -n atlantis |
| 166 | +``` |
| 167 | + |
| 168 | +Then use `http://localhost:4141` as your webhook URL temporarily. |
| 169 | + |
| 170 | +## Security Considerations |
| 171 | + |
| 172 | +1. **GitHub Token**: Store securely and rotate regularly |
| 173 | +2. **Webhook Secret**: Use a strong, random secret |
| 174 | +3. **RBAC**: Atlantis has minimal required permissions |
| 175 | +4. **Network**: Use HTTPS for webhook URLs |
| 176 | +5. **Monitoring**: Monitor Atlantis logs for suspicious activity |
| 177 | + |
| 178 | +## Next Steps |
| 179 | + |
| 180 | +1. Set up monitoring for Atlantis |
| 181 | +2. Configure backup for Atlantis data |
| 182 | +3. Set up alerting for failed plans/applies |
| 183 | +4. Consider setting up Atlantis for multiple repositories |
0 commit comments