Skip to content

Instantly share code, notes, and snippets.

@Lowess
Last active September 23, 2023 11:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lowess/28bcba7b10cc495b9cbf7d06b5b9fb06 to your computer and use it in GitHub Desktop.
Save Lowess/28bcba7b10cc495b9cbf7d06b5b9fb06 to your computer and use it in GitHub Desktop.
Jinja2 template to auto-generate atlantis.yaml for Atlantis / Terraform & pre-commit action & shell script
repos:
- repo: https://github.com/lowess/pre-commit-hooks
rev: v1.2.0 # Get the latest from: https://github.com/lowess/pre-commit-hooks/releases
hooks:
- id: jinja2-render-template
name: Render atlantis.yaml configuration
args:
- atlantis.j2
- --output
- atlantis.yaml
---
{#-
Author: Florian Dambrine <@Lowess>
#}
version: 3
parallel_plan: false
parallel_apply: false
automerge: true
projects:
# Project Anchor
- &terragrunt
name: template
dir: '.null'
workflow: terragrunt
autoplan:
enabled: true
when_modified:
- "./terraform/modules/**/*.tf"
- "**/*.tf"
- "**/terragrunt.hcl"
{% set projects = ('find terraform/terragrunt -mindepth 2 \( ! -regex ".*/\..*" \) -type f -name "terragrunt.hcl"' | shell(timeout=20) ).split('\n') -%}
{% for project in projects %}
{%- set project_name = project.split('/')[2:-1] | join('-') %}
{%- set project_path = project.split('/')[0:-1] | join('/') %}
- <<: *terragrunt
name: {{ project_name }}
dir: ./{{ project_path }}
# workspace: {{ project_name }}
{% endfor %}
#!/usr/bin/env bash
# Author: Florian Dambrine <@Lowess>
# Make sure to install dependencies first
# Install Python deps: `pip install yasha` or `pip install -r requirements.txt`
# Install JQ: https://stedolan.github.io/jq/download/
PROJECTS=$(find terraform/terragrunt \
-mindepth 2 \( ! -regex ".*/\..*" \) \
-type f \
-name "terragrunt.hcl" \
| jq -R -s -c 'split("\n") | map(select(length > 0))')
yasha \
atlantis.j2 \
-o atlantis.yaml
.PHONY: dev atlantis-config
dev:
@echo ⚙️ Setting up pre-commit hooks...
pre-commit install
pre-commit install --hook-type commit-msg
atlantis-config:
@echo 🏝️ Generating atlantis.yaml configuration...
@./atlantis.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment