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

autoplan when modified all sub-levels of a folder #2520

Open
marceloboeira opened this issue Sep 13, 2022 · 1 comment
Open

autoplan when modified all sub-levels of a folder #2520

marceloboeira opened this issue Sep 13, 2022 · 1 comment
Labels
bug Something isn't working Stale

Comments

@marceloboeira
Copy link
Contributor

marceloboeira commented Sep 13, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

I'd like to ensure that Atlantis runs the plan automatically whenever there are changes to any level of the modules folder.

Modules are structured with a deep tree:

modules
├── aws
│   └── amazonmq
│       └── rabbitmq
│           └── broker
├── consul
│   ├── node
│   └── service
└── vault
    ├── backend
    ├── generic
    ├── roles

A simple setup like this, only serves the first level:

 autoplan:
      when_modified: [
        "*.tf*",
        "modules/**/*.tf",
 ...

Demanding us to declare it for every new level:

 autoplan:
      when_modified: [
        "*.tf*",
        "modules/**/*.tf",
        "modules/**/**/*.tf",
        "modules/**/**/**/*.tf",
        "modules/**/**/**/**/*.tf",
...

Is there an already supported way of declaring that?

Something like:

        "modules/***.tf", # similar recursive syntax

Would express what I want, but do not seem to work either.

@Fabianoshz
Copy link
Contributor

Looks like this could be the relevant code to this issue:

for _, wm := range project.Autoplan.WhenModified {
wm = strings.TrimSpace(wm)
// An exclusion uses a '!' at the beginning. If it's there, we need
// to remove it, then add in the project path, then add it back.
exclusion := false
if wm != "" && wm[0] == '!' {
wm = wm[1:]
exclusion = true
}
// Prepend project dir to when modified patterns because the patterns
// are relative to the project dirs but our list of modified files is
// relative to the repo root.
wmRelPath := filepath.Join(project.Dir, wm)
if exclusion {
wmRelPath = "!" + wmRelPath
}
whenModifiedRelToRepoRoot = append(whenModifiedRelToRepoRoot, wmRelPath)

The thing is, there is a join in this check:

// Prepend project dir to when modified patterns because the patterns 
// are relative to the project dirs but our list of modified files is 
// relative to the repo root. 
wmRelPath := filepath.Join(project.Dir, wm) 

So the autoplan.when_modified is relative to the dir no the root directory. To make it clear, consider you have this folder structure:

standard/
- main.tf
standard-2/
- main.tf
standard-3/
 standard-4/
  standard-5/
   - main.tf

Also consider you're updating the standard-5/main.tf file.

This atlantis.yaml would not update the standard folder because it would check for "standard/standard-3/**/*.tf" from the root:

version: 3
projects:
- name: test
  dir: standard
  autoplan:
    when_modified: ["standard-3/**/*.tf"]
    enabled: true

This atlantis.yaml would update the standard folder because it would check for "standard-3/**/*.tf" from the root:

version: 3
projects:
- name: test
  dir: standard
  autoplan:
    when_modified: ["../standard-3/**/*.tf"]
    enabled: true

The documentation also states this: https://www.runatlantis.io/docs/repo-level-atlantis-yaml.html#configuring-planning

The paths are relative to the project's directory.

IMHO there's no need for this to be a relative path, it actually creates confusion, but since some people might be using this config as relative already I see no reason to change that and also is not a bug and is documented.

@dosubot dosubot bot added the Stale label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants