From 42f108c896febecc46f6216dcc79af85f170d987 Mon Sep 17 00:00:00 2001 From: Rohit Raj <88114930+ro4i7@users.noreply.github.com> Date: Sat, 25 May 2024 04:37:36 +0530 Subject: [PATCH 1/5] Update tf-apply-main.yml --- .github/workflows/tf-apply-main.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tf-apply-main.yml b/.github/workflows/tf-apply-main.yml index fd26f36f..d5efbc0d 100644 --- a/.github/workflows/tf-apply-main.yml +++ b/.github/workflows/tf-apply-main.yml @@ -1,6 +1,5 @@ name: 'Terraform Apply' - on: workflow_dispatch: inputs: @@ -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 @@ -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: | From 5ba8dce417f3e38dacc727448ba5026c5ac6769a Mon Sep 17 00:00:00 2001 From: Rohit Raj <88114930+ro4i7@users.noreply.github.com> Date: Sat, 25 May 2024 05:04:28 +0530 Subject: [PATCH 2/5] Update tf-destroy-main.yml --- .github/workflows/tf-destroy-main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tf-destroy-main.yml b/.github/workflows/tf-destroy-main.yml index b873b5fb..a92b902d 100644 --- a/.github/workflows/tf-destroy-main.yml +++ b/.github/workflows/tf-destroy-main.yml @@ -35,14 +35,15 @@ jobs: - 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 - + aws s3 cp s3://do-not-delete-awsgoat-state-files-${{ env.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate + # Initialize a new Terraform working directory - name: Terraform Init run: | From 2b2e6bdffd01952eb510cafc6528a12881d909ad Mon Sep 17 00:00:00 2001 From: Rohit Raj <88114930+ro4i7@users.noreply.github.com> Date: Sat, 25 May 2024 05:10:11 +0530 Subject: [PATCH 3/5] Update tf-destroy-main.yml --- .github/workflows/tf-destroy-main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tf-destroy-main.yml b/.github/workflows/tf-destroy-main.yml index a92b902d..bea93d99 100644 --- a/.github/workflows/tf-destroy-main.yml +++ b/.github/workflows/tf-destroy-main.yml @@ -31,6 +31,8 @@ jobs: # Checkout the repository to the GitHub Actions runner - name: Checkout uses: actions/checkout@v3 + with: + ref: v2 # Specify the version v2 for Node.js 20 compatibility - name: Set Account ID id: account From b31b1c1ace2a49827451513cfa3593cb1bfb89b1 Mon Sep 17 00:00:00 2001 From: Rohit Raj <88114930+ro4i7@users.noreply.github.com> Date: Sat, 25 May 2024 05:14:10 +0530 Subject: [PATCH 4/5] Update tf-destroy-main.yml --- .github/workflows/tf-destroy-main.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tf-destroy-main.yml b/.github/workflows/tf-destroy-main.yml index bea93d99..086a7b5e 100644 --- a/.github/workflows/tf-destroy-main.yml +++ b/.github/workflows/tf-destroy-main.yml @@ -27,13 +27,20 @@ jobs: run: shell: bash + strategy: + matrix: + node-version: [14.x, 16.x, 20.x] + steps: + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + # Checkout the repository to the GitHub Actions runner - name: Checkout uses: actions/checkout@v3 - with: - ref: v2 # Specify the version v2 for Node.js 20 compatibility - + - name: Set Account ID id: account run: | From 4b1e92b28ab3b5225ae424f225747c58cfe87f03 Mon Sep 17 00:00:00 2001 From: Rohit Raj <88114930+ro4i7@users.noreply.github.com> Date: Sat, 25 May 2024 05:17:56 +0530 Subject: [PATCH 5/5] Update tf-destroy-main.yml --- .github/workflows/tf-destroy-main.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tf-destroy-main.yml b/.github/workflows/tf-destroy-main.yml index 086a7b5e..271aa54d 100644 --- a/.github/workflows/tf-destroy-main.yml +++ b/.github/workflows/tf-destroy-main.yml @@ -17,27 +17,21 @@ 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 - - strategy: - matrix: - node-version: [14.x, 16.x, 20.x] - steps: - - name: Use Node.js ${{ matrix.node-version }} + - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: ${{ matrix.node-version }} + node-version: ${{ env.NODE_VERSION }} - # Checkout the repository to the GitHub Actions runner - name: Checkout uses: actions/checkout@v3 @@ -47,13 +41,11 @@ jobs: 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-${{ env.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate - # Initialize a new Terraform working directory - name: Terraform Init run: | cd modules/${{ github.event.inputs.module }}