From c1885bfb9da5af6ee4338e36a4845ee0b4f18c7d Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 09:33:40 -0700 Subject: [PATCH 01/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 4a85561..798bdf5 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -32,7 +32,6 @@ jobs: - uses: CSVD/gh-actions-setup-terraform@v2 with: - terraform_wrapper: false terraform_version: ${{ vars.terraform_version }} - name: Terraform Format @@ -56,3 +55,40 @@ jobs: id: plan run: terraform plan continue-on-error: true + + - uses: CSVD/gh-actions-github-script@v7 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + github-token: ${{ secrets.GH_TOKEN }} + script: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` +
Validation Output + + \`\`\`\n + ${{ steps.validate.outputs.stdout }} + \`\`\` + +
+ + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` + +
Show Plan + + \`\`\`\n + ${process.env.PLAN} + \`\`\` + +
+ + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) From 816aa4d7532b13138b4af3653270c71fc4ae0038 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 09:35:13 -0700 Subject: [PATCH 02/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 798bdf5..dbd6c7d 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -56,7 +56,7 @@ jobs: run: terraform plan continue-on-error: true - - uses: CSVD/gh-actions-github-script@v7 + - uses: CSVD/gh-actions-github-script@v6 if: github.event_name == 'pull_request' env: PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" From f7a372e1aa75cb6ea39f421812db5d58a582e6fc Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 09:43:11 -0700 Subject: [PATCH 03/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index dbd6c7d..c92ee3b 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -49,11 +49,11 @@ jobs: - name: Terraform Validate id: validate - run: terraform validate + run: terraform validate -no-color - name: Terraform Plan id: plan - run: terraform plan + run: terraform plan -no-color continue-on-error: true - uses: CSVD/gh-actions-github-script@v6 From 604288ac0b429c4698911fd35390dc82d9df8f16 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 09:48:11 -0700 Subject: [PATCH 04/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index c92ee3b..e06c07e 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -84,7 +84,7 @@ jobs: - *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`; github.rest.issues.createComment({ issue_number: context.issue.number, From c309667f813953a8448b67365575e7dba3db16fc Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 10:06:35 -0700 Subject: [PATCH 05/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index e06c07e..b0f09ab 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -24,6 +24,8 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 + with: + github-server-url: https://github.e.it.census.gov - uses: CSVD/gh-actions-setup-node@v3 From 56c9c991e98f5f0d2d35083b1673ae06a27ddc38 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 11:44:13 -0700 Subject: [PATCH 06/15] Update backend.tf --- backend.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend.tf b/backend.tf index 96d1478..9f61e98 100644 --- a/backend.tf +++ b/backend.tf @@ -1,8 +1,8 @@ terraform { backend "s3" { bucket = "inf-tfstate-229685449397" - key = "csvd-dev-gov/common/apps/terraform-repos" + key = "csvd-dev-gov/common/apps/terraform-repos" region = "us-gov-east-1" dynamodb_table = "tf_remote_state" } -} \ No newline at end of file +} From e7ddde8eed69a3c0a112bc147b692f31949742e0 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 11:48:29 -0700 Subject: [PATCH 07/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index b0f09ab..0c3cf66 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -39,12 +39,20 @@ jobs: - name: Terraform Format id: fmt run: | - terraform fmt -check + terraform fmt + if ! git diff-index --quiet HEAD; then + git config --global user.name '${{ vars.REPO_OWNER }}' + git config --global user.email '${{ vars.REPO_OWNER_EMAIL }}' + git commit -am "Autoformatting TF Code" + git push + echo "auto_format=true" >> $GITHUB_ENV + fi - name: Autoformat Halt if: env.auto_format == 'true' run: exit 1 + - name: Terraform Init id: init run: terraform init -upgrade From b7afb6b7bd0fac874efb5e76f2aeb25649199a55 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 11:52:30 -0700 Subject: [PATCH 08/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 0c3cf66..3a73efd 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -36,6 +36,10 @@ jobs: with: terraform_version: ${{ vars.terraform_version }} + - name: Set output + id: vars + run: echo ::set-output name=short_ref::${GITHUB_REF#refs/*/} + - name: Terraform Format id: fmt run: | @@ -44,7 +48,7 @@ jobs: git config --global user.name '${{ vars.REPO_OWNER }}' git config --global user.email '${{ vars.REPO_OWNER_EMAIL }}' git commit -am "Autoformatting TF Code" - git push + git push origin HEAD:${{ steps.vars.outputs.short_ref }} echo "auto_format=true" >> $GITHUB_ENV fi From 01ab8928dce14deb01367882e370a99fd7ac8fe3 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 11:56:12 -0700 Subject: [PATCH 09/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 3a73efd..4ef43a2 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -42,13 +42,13 @@ jobs: - name: Terraform Format id: fmt + uses: actions/checkout@v4 run: | terraform fmt if ! git diff-index --quiet HEAD; then git config --global user.name '${{ vars.REPO_OWNER }}' git config --global user.email '${{ vars.REPO_OWNER_EMAIL }}' git commit -am "Autoformatting TF Code" - git push origin HEAD:${{ steps.vars.outputs.short_ref }} echo "auto_format=true" >> $GITHUB_ENV fi From 512f3b24c33be16f34b22185a94b499d46b650db Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 11:58:15 -0700 Subject: [PATCH 10/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 4ef43a2..18443cf 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -23,7 +23,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: github-server-url: https://github.e.it.census.gov @@ -42,7 +42,6 @@ jobs: - name: Terraform Format id: fmt - uses: actions/checkout@v4 run: | terraform fmt if ! git diff-index --quiet HEAD; then From b6b5d80da28ca8c5c40ae06907f7ff8aac9b1cf5 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 12:25:50 -0700 Subject: [PATCH 11/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 18443cf..4ab182d 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -23,7 +23,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + - uses: CSVD/gh-actions-checkout@v4 with: github-server-url: https://github.e.it.census.gov From 0c935bb02e201cfc168713b62994491314680429 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 12:27:06 -0700 Subject: [PATCH 12/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 4ab182d..51a4aa7 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -23,7 +23,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: CSVD/gh-actions-checkout@v4 + - uses: CSVD/gh-actions-checkout@v3 with: github-server-url: https://github.e.it.census.gov From f026c86403e1bea5a3d5c3eec0cbdbc6a877b205 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 12:28:39 -0700 Subject: [PATCH 13/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 51a4aa7..c0fc2c8 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -51,11 +51,6 @@ jobs: echo "auto_format=true" >> $GITHUB_ENV fi - - name: Autoformat Halt - if: env.auto_format == 'true' - run: exit 1 - - - name: Terraform Init id: init run: terraform init -upgrade From 459bed9e024f86ca728f222d3b935b293a17bef4 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 12:32:25 -0700 Subject: [PATCH 14/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index c0fc2c8..8e2a018 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -48,6 +48,7 @@ jobs: git config --global user.name '${{ vars.REPO_OWNER }}' git config --global user.email '${{ vars.REPO_OWNER_EMAIL }}' git commit -am "Autoformatting TF Code" + git push echo "auto_format=true" >> $GITHUB_ENV fi From 06099df8ec2c12a75640d4b91a239b4e0d376981 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Thu, 15 Aug 2024 12:40:53 -0700 Subject: [PATCH 15/15] Update terraform_plan.yaml --- .github/workflows/terraform_plan.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 8e2a018..27c283f 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -26,6 +26,8 @@ jobs: - uses: CSVD/gh-actions-checkout@v3 with: github-server-url: https://github.e.it.census.gov + ref: ${{ github.head_ref }} + token: ${{ secrets.GH_TOKEN }} - uses: CSVD/gh-actions-setup-node@v3 @@ -52,6 +54,10 @@ jobs: echo "auto_format=true" >> $GITHUB_ENV fi + - name: Autoformat Halt + if: env.auto_format == 'true' + run: exit 0 + - name: Terraform Init id: init run: terraform init -upgrade