Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only generate config for projects modified in the PR #270

Open
stdmje opened this issue Feb 12, 2023 · 1 comment
Open

Only generate config for projects modified in the PR #270

stdmje opened this issue Feb 12, 2023 · 1 comment

Comments

@stdmje
Copy link

stdmje commented Feb 12, 2023

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

@cristian-radu
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants