From 806393959cfcb68e3f4debcbd259d9953db1ebbe Mon Sep 17 00:00:00 2001 From: makiton Date: Sat, 13 Aug 2022 15:28:23 +0900 Subject: [PATCH] terraform init --- .github/workflows/terraform_cloud.yml | 129 +++++++++++++------------- .terraform.lock.hcl | 13 +++ 2 files changed, 77 insertions(+), 65 deletions(-) diff --git a/.github/workflows/terraform_cloud.yml b/.github/workflows/terraform_cloud.yml index fd96317..7ec61dc 100644 --- a/.github/workflows/terraform_cloud.yml +++ b/.github/workflows/terraform_cloud.yml @@ -2,78 +2,77 @@ name: terraform-cloud on: [push, pull_request] jobs: terraform: - - name: Setup terraform - steps: + steps: - uses: hashicorp/setup-terraform@v2 with: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - - name: Terraform Init - id: init - run: terraform init + - name: Terraform Init + id: init + run: terraform init - - name: Terraform Validate - id: validate - run: terraform validate -no-color + - name: Terraform Validate + id: validate + run: terraform validate -no-color - - name: Terraform Plan - id: plan - run: terraform plan -no-color - continue-on-error: true + - name: Terraform Plan + id: plan + run: terraform plan -no-color + continue-on-error: true - - uses: actions/github-script@v6 - if: github.event_name == 'pull_request' - env: - PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - // 1. Retrieve existing bot comments for the PR - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }) - const botComment = comments.find(comment => { - return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style') - }) - - // 2. Prepare format of the comment - 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 }}\`*`; - - // 3. If we have a comment, update it, otherwise create a new one - if (botComment) { - github.rest.issues.updateComment({ + - uses: actions/github-script@v6 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // 1. Retrieve existing bot comments for the PR + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: botComment.id, - body: output - }) - } else { - github.rest.issues.createComment({ issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output }) - } + const botComment = comments.find(comment => { + return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style') + }) + + // 2. Prepare format of the comment + 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 }}\`*`; + + // 3. If we have a comment, update it, otherwise create a new one + if (botComment) { + github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: output + }) + } else { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + } diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index a436049..bab6494 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -39,5 +39,18 @@ provider "registry.terraform.io/integrations/github" { "h1:tHoFCFC0/9X+jFajYwHn1Drb5wNpd9asEoubZfyebQg=", "h1:xJrFx5pHr6dWjpQ089Bsa7q5Lb3t4s5QuBP+P5I/HME=", "h1:yKUB+2xIwWCQWZ8YCm//K3+a9H/wclLKHszx6blorhI=", + "zh:2fca3c83f7fec6ea3aabef1a69674e88b94b7ae5adf753b9ec4a92234aa3f2cd", + "zh:3c2acf95305b7f51dd10dfc735dfedb4d6237cab06913e819360a7a6b39ffd9b", + "zh:49f66b001b930073ea4d11d40922ac40820b512996e3ba5330986b2fb493a206", + "zh:4caba38c27bef0284a5cdeb33f7d69eff91204ed4ee0505dc46b93bea2f134bf", + "zh:7a7c6529043e55793fa2ed7a241dcdaa60f70413263348cfd7e26a0aaa686a9e", + "zh:a19af46649be35e28e8aa1b7dd3579234a19787d7238205c6e247a8a16f1d619", + "zh:a8aff33a3b0932f9dc9b0bb702d845d25de6495f383e6cbc2e69c40a61a8ac46", + "zh:bddbe0c4666469664dec37c17060d9b5852ad1c9857997d670e265633d50614b", + "zh:eac37b97f6518d43d9114616b1a49205a6ce262546961d0f7589084178e2be8b", + "zh:ecfcdcae1fecc19386758f5679498382cad0c973144bc247a4a622bd9ef2c719", + "zh:f0e856932aef6ded5ad66fc248e9707484a7ffe2ff8410bb6e64d8bb4f187705", + "zh:fe12cb9a7066fdee6470fa176fbaf717c2e943f25a33b75510f3f68f001d1c0e", + "zh:febacb1f224186d1d1553203658f39ddfd795052bf22ff0f62a7587272975f5d", ] }