runatlantis / atlantis

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

Custom workflow based on project dirs #2144

Open jindov opened 2 years ago

jindov commented 2 years ago

I have an use case, my app folder is

myapp
└── terraform
    ├── env
    │   ├── prd
    │   │   ├── compute
    │   │   │   └── main.tf
    │   │   └── network
    │   │       └── main.tf
    │   └── stg
    │       ├── compute
    │       │   └── main.tf
    │       └── network
    │           └── main.tf
    └── modules

Every environment will be deploy into a separated gcp project, so I want to use custom workflow to do this. Here is my configuration repos.yaml

repos:
  - id: gitlab.com/group/myapp
    allowed_overrides: [workflow]
    allow_custom_workflows: true

and the repo level configuration

## atlantis.yaml
version: 3
projects:
- name: stg
   dir: terraform/env/stg
   workflow: stg
- name: prd
   dir: terraform/env/prd
   workflow: prd
workflows:
  stg:
    plan:
      steps:
        - run: GOOGLE_APPLICATION_CREDENTIALS=/tmp/atlantis_credential_stg.json /usr/local/bin/terraform init -input=false -upgrade
        - run: GOOGLE_APPLICATION_CREDENTIALS=/tmp/atlantis_credential_stg.json /usr/local/bin/terraform plan -input=false -refresh -out $PLANFILE
    apply:
      steps:
        - run: GOOGLE_APPLICATION_CREDENTIALS=/tmp/atlantis_credential_stg.json /usr/local/bin/terraform apply $PLANFILE
  prd:
    plan:
      steps:
        - run: GOOGLE_APPLICATION_CREDENTIALS=/tmp/atlantis_credential_prd.json /usr/local/bin/terraform init -input=false -upgrade
        - run: GOOGLE_APPLICATION_CREDENTIALS=/tmp/atlantis_credential_prd.json /usr/local/bin/terraform plan -input=false -refresh -out $PLANFILE
    apply:
      steps:
        - run: GOOGLE_APPLICATION_CREDENTIALS=/tmp/atlantis_credential_prd.json /usr/local/bin/terraform apply $PLANFILE

The expectation is when ever I modify tf file in any environment folders, it will trigger the plan and apply the workflow respectively

But the actual behaviour is: when I modify the main.tf in stg/network folder, plan only see the dir terraform/env/stg not recursively nested folders so It say no configuration file. But when I try to run atlantis -d terraform/env/stg/network, it show error because it fall back to default workflow without google credential file

So... does atlantis support nested folder in workflow, when i define dir: ./terraform/env/stg/**, It will plan from this folder and the nested?

kkirpichnikov-collibra commented 1 year ago

@jindov any luck with workflow implementation based on a folder level?