runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.83k stars 1.06k forks source link

Multiple server-side repo config: pre_workflow_hooks not overridden #4572

Open MrLuje opened 6 months ago

MrLuje commented 6 months ago

Community Note


Overview of the Issue

I defined the following server-side repo config

  repoConfig: |
    ---
    repos:
    - id: /.*/
      pre_workflow_hooks:
      - run: echo 'running default flow...'
      apply_requirements: [approved, mergeable, undiverged]
      allowed_overrides: [workflow]
      allow_custom_workflows: true

    - id: /.*rancher/
      pre_workflow_hooks:
      - run: echo 'running rancher flow'

Based on documentation, I expect the first pre_workflow_hooks key to be overridden by the /.*rancher/ config

image

Reproduction Steps

Expected: only the pre_workflow_hooks from rancher should be executed Actual: both pre_workflow_hooks are executed

Logs

Logs ``` {"level":"info","ts":"2024-05-17T10:15:45.850Z","caller":"events/working_dir.go:239","msg":"creating dir \"/atlantis-data/repos/rancher/10/default\"","json":{}} {"level":"info","ts":"2024-05-17T10:15:48.081Z","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo 'running default flow...'\" in \"/atlantis-data/repos/rancher/10/default\"","json":{"repo":"rancher","pull":"10"}} {"level":"info","ts":"2024-05-17T10:15:57.153Z","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo 'running rancher flow'\" in \"/atlantis-data/repos/rancher/10/default\"","json":{"repo":"rancher","pull":"10"}} {"level":"info","ts":"2024-05-17T10:16:01.847Z","caller":"events/project_command_builder.go:427","msg":"successfully parsed atlantis.yaml file","json":{"repo":"rancher","pull":"10"}} {"level":"info","ts":"2024-05-17T10:16:01.847Z","caller":"events/project_command_builder.go:467","msg":"1 projects are to be planned based on their when_modified config","json":{"repo":"rancher","pull":"10"}} ```

Environment details

Additional Context

I also find the wording of the documentation a bit weird

If multiple repos match, the last match will apply. -> I first though that only the last config will be used

If a key isn't defined, it won't override a key that matched from above. For example, given a repo ID github.com/owner/repo and a config -> but in fact, all matching repos will be used, merged and the last value of each key is used

VickyWinner commented 3 months ago

This issue also applies to post_workflow_hooks. Is there any workaround to this?