Setup gha 107 #7
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 IAM Resources to AWS with Terraform | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
terraform: | |
name: Terraform | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.7.3 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-west-2 | |
- name: Terraform Init | |
run: terraform init | |
working-directory: ./terraform | |
- name: Terraform Plan | |
id: plan | |
run: | | |
terraform plan -no-color > plan-output.txt | |
cat plan-output.txt | |
working-directory: ./terraform | |
continue-on-error: true | |
- name: Comment Plan Output on PR | |
uses: actions/github-script@v7 | |
if: github.event_name == 'pull_request' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const planOutput = fs.readFileSync('${{ github.workspace }}/terraform/plan-output.txt', 'utf8'); | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.name, | |
body: '### Terraform Plan Output\n' + '```\n' + planOutput + '\n```', | |
}); |