This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
att lambda zip #71
Workflow file for this run
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 Infrastructure | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
############################################################## | |
tf-test: | |
name: Terraform Test | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: src/terraform-infra | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to AWS | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-region: 'us-east-1' | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: 1.6.2 | |
- name: Prepare environment | |
id: tf-init | |
run: terraform init | |
- name: Terraform fmt | |
id: tf-fmt | |
run: terraform fmt --recursive | |
- name: Terraform validate | |
id: tf-validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
id: tf-plan | |
run: terraform plan -lock=false -no-color -input=false | |
continue-on-error: true | |
- name: Pull Request Updates | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
env: | |
PLAN: ${{ steps.tf-plan.outputs.stdout }} | |
with: | |
github-token: ${{ secrets.GH_TOKEN }} | |
script: | | |
const output = `#### Terraform Format and Style 🖌\`${{ steps.tf-fmt.outcome }}\` | |
#### Terraform Initialization ⚙️\`${{ steps.tf-init.outcome }}\` | |
#### Terraform Validation 🤖\`${{ steps.tf-validate.outcome }}\` | |
#### Terraform Plan 📖\`${{ steps.tf-plan.outcome }}\` | |
<details><summary>Show Plan</summary> | |
\`\`\`terraform\n | |
${process.env.PLAN} | |
\`\`\` | |
</details> | |
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output | |
}) | |
- name: Terraform Plan Status | |
if: steps.tf-plan.outcome == 'failure' | |
run: exit 1 | |
tf-deploy: | |
name: Terraform Deploy | |
needs: | |
- tf-test | |
if: github.ref == 'refs/heads/release' || github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: src | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to AWS | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: 'us-east-1' | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
- name: Configure AWS Dotnet CLI | |
run: dotnet tool install -g Amazon.Lambda.Tools | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Prepare environment | |
run: terraform -chdir=terraform-infra/ init | |
- name: Terraform Plan | |
run: terraform -chdir=terraform-infra/ plan -lock=false -no-color -input=false | |
- name: Execute terraform apply | |
run: terraform -chdir=terraform-infra/ apply -lock=false -auto-approve -input=false | |
############################################################## |