This message was deleted.
# atlantis-community
s
This message was deleted.
p
you can create custom workflows base on branches
j
Thanks PePe! Are there environment variables available to grab the target branch for a PR? Do I just use raw git commands in my custom workflow to do that? In a custom workflow I can see
init
plan
and
apply
operations. I would like to avoid shelling out to raw terraform commands because it seems to be causing some trouble with locking.
p
there are , look at the docs for custom workflow at the end
j
thanks again for the help. You are always quick to respond with useful feedback.
👍 1
p
remember that we have support for branches at the workflow level
so you can target environments with branches if you want
j
This is what we have but I suspect it should be simpler than this.
Copy code
workflows:
  dev:
    plan:
      steps:
        - init
        - run: if [ "$BASE_BRANCH_NAME" = "develop" ]; then terraform plan -var-file=environment.tfvars -out=./tfplan; else echo "Skipping plan for this branch"; fi
    apply:
      steps:
        - run: if [ "$BASE_BRANCH_NAME" = "develop" ]; then terraform apply -auto-approve ./tfplan; else echo "Skipping apply for this branch"; fi
  production_workflow:
    plan:
      steps:
        - init
        - run: if [ "$BASE_BRANCH_NAME" = "main" ]; then terraform plan -var-file=environment.tfvars -out=./tfplan; else echo "Skipping plan for this branch"; fi
    apply:
      steps:
        - run: if [ "$BASE_BRANCH_NAME" = "main" ]; then terraform apply -auto-approve ./tfplan; else echo "Skipping apply for this branch"; fi
Is it better to have the conditional just return a 0 or 1 exit code and have it run before the
init
or
plan
command?
p
we ha a new branch parameter , you do not ned to dk those run commands anymore
j
I am having trouble finding that in the docs I will go search some more.
look at the full yaml file
j
omg how did I miss that?
That is exactly what I needed thank you once again!
👍 1
This worked extremely well.
p
glad to hear