Deploy Environment #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Environment | |
on: | |
workflow_call: | |
inputs: | |
stage: | |
required: true | |
type: string | |
description: Environment to deploy | |
workflow_dispatch: | |
inputs: | |
stage: | |
type: choice | |
description: Environment to destroy | |
options: | |
- dev | |
- qa | |
message: | |
required: true | |
env: | |
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }} | |
aws_region: ${{ vars.AWS_REGION }} | |
aws_role: ${{ vars.AWS_ROLE }} | |
stage: ${{ inputs.stage }} | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
sha_short: ${{ steps.set_sha.outputs.GITHUB_SHA_SHORT }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: set_sha | |
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_OUTPUT | |
deploy: | |
runs-on: ubuntu-latest | |
needs: setup | |
env: | |
sha_shot: $(echo $GITHUB_SHA | cut -c 1-6) | |
outputs: | |
api_gateway_url: ${{ steps.action.outputs.API_GATEWAY_URL }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{ env.aws_region }} | |
role-to-assume: arn:aws:iam::${{ env.aws_account_id }}:role/${{ env.aws_role }} | |
role-session-name: GitHubActions | |
- name: Download version from s3 | |
env: | |
S3_BUCKET_NAME: "${{ github.event.repository.name }}-versions" | |
S3_FILE_NAME: ./tf/${{ needs.setup.outputs.sha_short }}.zip | |
shell: bash | |
run: | | |
bash bin/download-s3-file.sh | |
- name: Init | |
shell: bash | |
run: | | |
cd tf | |
terraform init | |
- name: Select Workspace | |
shell: bash | |
run: | | |
cd tf | |
terraform workspace select -or-create ${{ env.stage }} | |
terraform init | |
- name: Action | |
shell: bash | |
id: action | |
run: | | |
cd tf | |
terraform apply -auto-approve -var function-stage=${{ env.stage }} -var lambda-zip-path=${{ needs.setup.outputs.sha_short }}.zip | |
echo "API_GATEWAY_URL=$(terraform output -raw api_gateway_url)" >> $GITHUB_OUTPUT | |
test: | |
needs: deploy | |
runs-on: ubuntu-latest | |
env: | |
API_URL: ${{ needs.deploy.outputs.api_gateway_url }}/hello | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Test | |
shell: bash | |
run: | | |
bash bin/curl-check.sh |