diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml
index 4a85561..27c283f 100644
--- a/.github/workflows/terraform_plan.yaml
+++ b/.github/workflows/terraform_plan.yaml
@@ -23,7 +23,11 @@ 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: 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
@@ -32,27 +36,74 @@ jobs:
- uses: CSVD/gh-actions-setup-terraform@v2
with:
- terraform_wrapper: false
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: |
- 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
-
+ run: exit 0
+
- name: Terraform Init
id: init
run: terraform init -upgrade
- 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
+ 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 }}\`, Workflow: \`${{ github.workflow }}\`*`;
+
+ github.rest.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: output
+ })
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
+}