transcend-io / terragrunt-atlantis-config

Generate Atlantis config for Terragrunt projects.
https://transcend.io/blog/why-we-use-terragrunt
MIT License
609 stars 96 forks source link

change git root directory 'default' for actual repository name #258

Open juanidufourc opened 1 year ago

juanidufourc commented 1 year ago

Hi, i’m looking for workarounds or suggestions for this problem.

Currently i’m using atlantis with terragrunt as the documentation explains (https://www.runatlantis.io/docs/custom-workflows.html#terragrunt). And I’m having an issue using get_repo_root() terragrunt built-in fuction due to way that atlantis use a repository structure folder to execute a plan.

In my terragrunt file I am using the following terragrunt built-in-function get_repo_root() for my terraform remote state and resources. In my local this returns the git repository name (e.g, project-example) but when I am using atlantis this returns default.

The path of my terragrunt file in atlantis is /atlantis-data/repos/my-company/project-example/16/default/dev/ and the git root directory is located in the default directory because atlantis use a different way to clone the repository adding {$pull_request_number}+{$workflow} after the repository name

Is there any way that my git root directory have the same name as the repository or can I rename that default directory so i can keep using the built-in-function get_repo_root(). Maybe i can change the way in which atlantis clone the pull_requests events and just give something like that ’/atlantis-data/repos/my-company/project-example/dev/` ?

Currently i workarounded the issue using the following built-in-function {element(split("/" ,get_terragrunt_dir()),4)} and that returns me the repository name project-example.

But i want to hear for a better solutions

benjy44 commented 9 months ago

I have the same issue, this is due to the workspace name, default name being default An ugly workaround that works is:

pre_workflow_hooks:
 - run: |
     terragrunt-atlantis-config generate --output atlantis.yaml --autoplan --parallel --create-workspace
     sed -i 's/^  workspace: .*/  workspace: my-repo-name/g' atlantis.yaml

A less ugly workaround would be this feature to be merged: https://github.com/transcend-io/terragrunt-atlantis-config/pull/219 and --workspace my-repo-name