get runner as output
@@ -15,50 +15,52 @@ jobs:
AWS_REGION: ${{ secrets.AWS_REGION }}
EC2_SECRET: ${{ secrets.EC2_PWD }}
S3_BACKEND_KEY_NAME: tf-state-${{ github.sha }}
+ outputs:
+ build-runner: ${{ steps.determine-runner.outputs.runner }}
steps:
+ - id: determine-runner
+ run: if [ -z $AWS_ACCESS_KEY_ID ]; then echo "::set-output name=runner::ubuntu-latest"; else echo "::set-output name=runner::${{ github.sha }}"; fi;
- name: checkout code
+ if: ${{ $AWS_ACCESS_KEY_ID }}
uses: actions/checkout@v2.1.0
- name: setup node
+ if: ${{ $AWS_ACCESS_KEY_ID }}
uses: actions/setup-node@v2
with:
node-version: '14'
- uses: hashicorp/setup-terraform@v1
+ if: ${{ $AWS_ACCESS_KEY_ID }}
with:
terraform_version: 0.12.25
- #- name: Declare some variables
- # id: vars
- #shell: bash
- #run: |
- # echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
- #echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: rewrite tf state key
id: tf-state-key
+ if: ${{ $AWS_ACCESS_KEY_ID }}
working-directory: ./infrastructure
run: sed -i 's/BRANCH_ACTOR_KEY/${{ env.S3_BACKEND_KEY_NAME }}/g' infra.tf
- name: Terraform Init
+ if: ${{ $AWS_ACCESS_KEY_ID }}
id: init
working-directory: ./infrastructure
run: terraform init
- continue-on-error: false
-
- name: Terraform plan
+ if: ${{ $AWS_ACCESS_KEY_ID }}
id: plan
working-directory: ./infrastructure
run: terraform plan -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}"
- continue-on-error: false
- name: Terraform apply
+ if: ${{ $AWS_ACCESS_KEY_ID }}
id: apply
working-directory: ./infrastructure
run: terraform apply -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}" -auto-approve
- continue-on-error: false
- name: Sleep for 20 seconds
+ if: ${{ $AWS_ACCESS_KEY_ID }}
uses: jakejarvis/wait-action@master
with:
time: '20s'
build:
- runs-on: ${{ github.sha }}
needs: pop-runner-instance
+ runs-on: ${{ needs.pop-runner-instance.outputs.runner }}
steps:
- uses: actions/checkout@v2
with:
@@ -101,7 +103,7 @@ jobs:
name: destroy infra
runs-on: ubuntu-latest
needs: build
- if: always()
+ if: ${{ always() && $AWS_ACCESS_KEY_ID }}
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
