runatlantis / atlantis

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

`atlantis apply` does not work on nested terraform git repo #4214

Open itays333 opened 7 months ago

itays333 commented 7 months ago

Community Note


Overview of the Issue

I'm aware this use-case is not very standard, but our infra codebase is separated into two repos (simplified):

We use pre_workflow_hook to checkout the other repo before plan/apply and to generate the atlantis.yaml

this setup works well for infra-tf, but for infra-cfg - atlantis apply (all) command doesnt apply anything cause it cant find the plan files. We are able to run atlantis apply -p project_name.

looking into the atlantis code i found out that when running atlantis apply it tries to locate plans using

git ls-files . --others

but this command will not list untracked files generated inside nested git repositories (as infra-tf repo is nested below infra-cfg (https://stackoverflow.com/a/51851111) I assume if someone is using git submodules, they will get the same behavior.

Reproduction Steps

run git init in a terraform directory as pre_workflow_hook or custom workflow

Logs

Ran Apply for 0 projects:

Environment details

Atlantis server-side config file:

repos:
  - id: /github.com/ORG/infra-cfg/
    pre_workflow_hooks:
    - run: |
        echo "Cloning infra-tf"
        git clone --depth 1 https://github.com/ORG/infra-tf.git

        echo "Generating atlantis.yaml"
        infra-tf/generate_atlantis_yaml.sh
      commands: plan
      shell: bash
      shellArgs: -cv
    allow_custom_workflows: true

I'm happy to try submit a PR but need your input whats be best way to support this use-case and why this implementation was chosen and not listing all files recursively.

ricardosilva86 commented 7 months ago

I have a nested project and Atlantis was working just fine, out of nothing it started having the same behaviour this week.