steps:
    - id: 'branch name'
      name: 'alpine'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
          echo "***********************"
          echo "Branch: $BRANCH_NAME"
          echo "***********************"

    - id: 'tf init'
      name: 'hashicorp/terraform:0.12.20'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
        cd $_TERRAFORM_ENVIRONMENT_PATH
        terraform init || exit 1
        cd ../../
    - id: 'tf plan'
      name: 'hashicorp/terraform:0.12.20'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
        cd $_TERRAFORM_ENVIRONMENT_PATH
        terraform plan || exit 1
        cd ../../
    - id: 'tf apply'
      name: 'hashicorp/terraform:0.12.20'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
        if [ -d "${BRANCH_NAME}" = "master" ]; then
            cd $_TERRAFORM_ENVIRONMENT_PATH
            echo $BRANCH_NAME
            exit 0
            terraform apply -auto-approve || exit 1
        else
            echo "***************************** SKIPPING APPLYING *******************************"
            echo "Not on master branch. Current branch is: $BRANCH_NAME"
            echo "*******************************************************************************"
        fi
substitutions:
    _TERRAFORM_ENVIRONMENT_PATH: 'environments/prod'

steps:
    - id: 'branch name'
      name: 'alpine'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
          echo "***********************"
          echo "Branch: $BRANCH_NAME"
          echo "***********************"

    - id: 'tf init'
      name: 'hashicorp/terraform:0.12.20'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
        cd $_TERRAFORM_ENVIRONMENT_PATH || exit 1
        terraform init || exit 1
        cd ../../
    - id: 'tf plan'
      name: 'hashicorp/terraform:0.12.20'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
        cd $_TERRAFORM_ENVIRONMENT_PATH || exit 1
        terraform plan || exit 1
        cd ../../
    - id: 'tf apply'
      name: 'hashicorp/terraform:0.12.20'
      entrypoint: 'sh'
      args:
      - '-c'
      - |
        if [ -d "${BRANCH_NAME}" = "master" ]; then
            cd $_TERRAFORM_ENVIRONMENT_PATH || exit 1
            echo $BRANCH_NAME
            exit 0
            terraform apply -auto-approve || exit 1
        else
            echo "***************************** SKIPPING APPLYING *******************************"
            echo "Not on master branch. Current branch is: $BRANCH_NAME"
            echo "*******************************************************************************"
        fi
substitutions:
    _TERRAFORM_ENVIRONMENT_PATH: 'provisioning/terraform/environments/prod'

Fix paths in cloud build
Fix paths in cloud build
