Last active
September 23, 2023 11:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
{#- | |
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yasha==4.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment