Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.