Merge pull request #1 from jumping-dragon/dependabot/npm_and_yarn/bab… #19
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: 'Terraform' | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
terraform: | |
name: 'Terraform' | |
runs-on: ubuntu-latest | |
environment: production | |
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
# Checkout the repository to the GitHub Actions runner | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials for github actions | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-region: ${{ vars.AWS_DEFAULT_REGION }} | |
role-to-assume: ${{ vars.ACTIONS_ROLE }} | |
role-session-name: GitHubActions | |
audience: sts.amazonaws.com | |
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_wrapper: false | |
# Setup Nodejs | |
- name: Use Node v16 | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 16 | |
# Install dependencies with yarn | |
- name: Run install | |
uses: borales/actions-yarn@v4 | |
with: | |
cmd: install | |
# Build for production | |
- name: Build production bundle | |
uses: borales/actions-yarn@v4 | |
with: | |
cmd: build | |
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. | |
- name: Terraform Init | |
working-directory: ./infra | |
run: terraform init | |
# Generates an execution plan for Terraform | |
- name: Terraform Plan | |
working-directory: ./infra | |
run: terraform plan -input=false | |
# On push to "main", build or change infrastructure according to Terraform configuration files | |
# Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks | |
- name: Terraform Apply | |
working-directory: ./infra | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
run: terraform apply -auto-approve -input=false | |
- name: Cloudfront Invalidation | |
working-directory: ./infra | |
run: | | |
CLOUDFRONT_DISTRIBUTION_ID=$(terraform output -raw cloudfront) | |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" | |