Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/tf-apply-main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: 'Terraform Apply'


on:
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -35,13 +34,13 @@ jobs:
- name: Set Account ID
id: account
run: |
echo "::set-output name=ACCOUNT_ID::$(aws sts get-caller-identity --query Account --output text)"
echo "ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> $GITHUB_ENV

- name: Check previous AWSGoat Deployment
id: check
run: |
echo $ACCOUNT_ID
aws s3api head-object --bucket do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }} --key terraform.tfstate
aws s3api head-object --bucket do-not-delete-awsgoat-state-files-${{ env.ACCOUNT_ID }} --key terraform.tfstate
continue-on-error: true

- name: Exit if previous deployment exists
Expand Down Expand Up @@ -86,8 +85,8 @@ jobs:
if: always()
run: |
cd modules/${{ github.event.inputs.module }}
aws s3 cp ./terraform.tfstate s3://do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }}/terraform.tfstate

aws s3 cp ./terraform.tfstate s3://do-not-delete-awsgoat-state-files-${{ env.ACCOUNT_ID }}/terraform.tfstate
# Terraform Output the API Gateway url
- name: Application URL
run: |
Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/tf-destroy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,35 @@ jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
environment: production
environment:
NODE_VERSION: '20.x'
production

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"

defaults:
run:
shell: bash

steps:
# Checkout the repository to the GitHub Actions runner
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}

- name: Checkout
uses: actions/checkout@v3

- name: Set Account ID
id: account
run: |
echo "::set-output name=ACCOUNT_ID::$(aws sts get-caller-identity --query Account --output text)"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
echo "ACCOUNT_ID=$ACCOUNT_ID" >> $GITHUB_ENV

# Copy and delete terraform.tfstate files from s3 bucket
- name: Retrieve tfstate
run: |
cd modules/${{ github.event.inputs.module }}
aws s3 cp s3://do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate

# Initialize a new Terraform working directory
aws s3 cp s3://do-not-delete-awsgoat-state-files-${{ env.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate

- name: Terraform Init
run: |
cd modules/${{ github.event.inputs.module }}
Expand Down