terragrunt-atlantis-config
terragrunt-atlantis-config copied to clipboard
Only generate config for projects modified in the PR
Hi all,
Our number of terragrunt projects is increasing and now the plugin is taking almost 5 minutes to generate the config for all the projects.
I have seen that i can use --preserve-workflows --preserve-projects
so my idea to create a wrapper that iterates over the result of git diff
and call terragrunt-atlantis-config
with those flags set to true.
I would like to see how others are facing with the same problem and see some examples if possible.
Thanks in advance! All the best
Something like this should help. If I understood correctly, Atlantis does a shallow clone of the PR branch by default and you will not be able to use git diff there.
#!/bin/bash
# Get head branch
branch=$(git symbolic-ref --short HEAD)
# Login to GitHub
echo GH_TOKEN | gh auth login --with-token
echo "Determining what terragrunt modules have changed in this PR"
changed_modules=$(gh pr list --head $branch --json files --jq '.[].files[].path' \
| grep -E '*.hcl|*.yaml|*.json' | xargs dirname | uniq)
if [[ -z $changed_modules ]]; then
echo "No terragrunt modules have changed."
else
for module in $changed_modules; do
echo "Terragrunt module: $module contains changes"
echo "Generating terragrunt atlantis config for: $module"
terragrunt-atlantis-config generate --create-project-name --preserve-projects --filter $module \
--ignore-dependency-blocks --autoplan=true --automerge=true --output atlantis.yaml --parallel=false
done
fi