Is there a way to run a step only if some conditio...
# atlantis-community
c
Is there a way to run a step only if some condition is met?
p
custom workflow and a scrip on run command that will decide what to do
c
is there example of this? I already have a custom workflow used for the terragrunt projects I just need to decide to run the apply steps if maybe I run shell script to check value of file and if it matches certain regex then apply steps are allowed to run
c
that sets an env variable but how does it tell
apply
step to run or not? would need to be some sort of
if
condition I would think
p
you need to exit with 1 in your scrip and it will not run that step
c
ok... so env.command would run and if exits 1 then the rest of the step won't run
p
run command
not env
c
so something like this:
Copy code
workflows:
  terragrunt:
    plan:
      steps:
      - env:
          name: TF_VAR_gitlab_token
          command: 'echo "$ATLANTIS_GITLAB_TOKEN"'
      - env:
          # Reduce Terraform suggestion output
          name: TF_IN_AUTOMATION
          value: 'true'
      - run:
          command: terragrunt init -upgrade
      - run:
          command: terragrunt plan -input=false -out=$PLANFILE
          output: strip_refreshing
    apply:
      steps:
      - env:
          name: TF_VAR_gitlab_token
          command: 'echo "$ATLANTIS_GITLAB_TOKEN"'
      - env:
          # Reduce Terraform suggestion output
          name: TF_IN_AUTOMATION
          value: 'true'
      - run: bash ./script.sh # exits 0 for okay and exits 1 for bad
      - run: terragrunt apply $PLANFILE
if the run bash command exits 1 then the apply won't run right?
p
yes
c
or do i need to put my terragrunt apply inside that shell script?
p
no
c
ok thanks