From f0c3975a2fce85cf2c776b0f20996b029a5b52b7 Mon Sep 17 00:00:00 2001 From: Mario Valente Date: Sat, 4 Feb 2023 18:14:04 -0300 Subject: [PATCH 1/3] ci: :green_heart: Add workflow of PR validation --- .github/workflows/production.yaml | 91 +++++++++++++++++++++++++++++++ .terraform.tfstate.lock.info | 1 - providers.tf | 1 - variables.tf | 5 +- 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/production.yaml delete mode 100644 .terraform.tfstate.lock.info diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml new file mode 100644 index 0000000..267f9c0 --- /dev/null +++ b/.github/workflows/production.yaml @@ -0,0 +1,91 @@ +name: pr validation terraform + +on: + pull_request: + branches: [main] + workflow_dispatch: + +env: + AWS_ACCESS_KEY_ID: "${{secrets.AWS_ACCESS_KEY_ID}}" + AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" + AWS_REGION: "${{ secrets.AWS_REGION }}" + +concurrency: + group: ${{github.workflow}} + cancel-in-progress: true + +jobs: + + terraform-plan: + runs-on: ${{matrix.os}} + + strategy: + matrix: + os: [ubuntu-latest] + terraform: [0.13.1] + + steps: + - name: checkout 🛎 + uses: actions/checkout@master + + + - name: Aws credentions + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Setup Terrafom + uses: hashicorp/setup-terraform@v1.2.1 + with: + terraform_version: ${{ matrix.terraform }} + + - name: Terraform Init + id: tf_init + run: terraform init + + - name: Terraform Validade + id: tf_validate + run: terraform validate -no-color + + - name: terraform plan + id: tf-plan + run: terraform plan -out=plan.out -input=false -lock=false + continue-on-error: true + + - name: terraform show plan + id: tf_show + run: terraform show -no-color plan.out + continue-on-error: true + + - uses: actions/github-script@v6 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.tf_show.outputs.stdout }}" + with: + script: | + const output = `#### Terraform Initialization ⚙️\`${{ steps.tf_init.outcome }}\` + #### Terraform Plan 📖\`${{ steps.tf_plan.outcome }}\` + #### Terraform Validation 🤖\`${{ steps.tf_validate.outcome }}\` + +
Show Plan + + \`\`\`\n + ${process.env.PLAN} + \`\`\` + +
+ + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + + - name: Terraform Plan Status + if: steps.tf_plan.outcome == 'failure' + run: exit 1 diff --git a/.terraform.tfstate.lock.info b/.terraform.tfstate.lock.info deleted file mode 100644 index b2f94b6..0000000 --- a/.terraform.tfstate.lock.info +++ /dev/null @@ -1 +0,0 @@ -{"ID":"100a58cc-e3bd-7365-a26d-42306e79adef","Operation":"OperationTypePlan","Info":"","Who":"mario@mario-valente","Version":"1.3.7","Created":"2023-01-29T13:38:50.621798556Z","Path":"terraform.tfstate"} \ No newline at end of file diff --git a/providers.tf b/providers.tf index d586e18..0575b87 100644 --- a/providers.tf +++ b/providers.tf @@ -7,7 +7,6 @@ terraform { } - provider "aws" { region = "us-east-1" } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 357c9ea..954d65f 100644 --- a/variables.tf +++ b/variables.tf @@ -1 +1,4 @@ -variable "aws_iam_user"{} \ No newline at end of file +variable "aws_iam_user"{ + type = string + default = "teste_iam" +} \ No newline at end of file From 14437ccd5d1d02ad13f0f82c0f8c40ba6087a22d Mon Sep 17 00:00:00 2001 From: Mario Valente Date: Sat, 4 Feb 2023 18:18:00 -0300 Subject: [PATCH 2/3] fix: :fire: updating version of terraform on workflow --- .github/workflows/production.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index 267f9c0..cdc5bbf 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/production.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - terraform: [0.13.1] + terraform: [0.14.8] steps: - name: checkout 🛎 From 583bd303cd8583b2ebf461e5fa60fb08fa04af8f Mon Sep 17 00:00:00 2001 From: Mario Valente Date: Sat, 4 Feb 2023 18:32:16 -0300 Subject: [PATCH 3/3] fix: :fire: Removing step of resource unavailable --- .../{production.yaml => pr_validation.yaml} | 26 ------------------- 1 file changed, 26 deletions(-) rename .github/workflows/{production.yaml => pr_validation.yaml} (63%) diff --git a/.github/workflows/production.yaml b/.github/workflows/pr_validation.yaml similarity index 63% rename from .github/workflows/production.yaml rename to .github/workflows/pr_validation.yaml index cdc5bbf..62de62d 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/pr_validation.yaml @@ -59,32 +59,6 @@ jobs: run: terraform show -no-color plan.out continue-on-error: true - - uses: actions/github-script@v6 - if: github.event_name == 'pull_request' - env: - PLAN: "terraform\n${{ steps.tf_show.outputs.stdout }}" - with: - script: | - const output = `#### Terraform Initialization ⚙️\`${{ steps.tf_init.outcome }}\` - #### Terraform Plan 📖\`${{ steps.tf_plan.outcome }}\` - #### Terraform Validation 🤖\`${{ steps.tf_validate.outcome }}\` - -
Show Plan - - \`\`\`\n - ${process.env.PLAN} - \`\`\` - -
- - *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output - }) - name: Terraform Plan Status if: steps.tf_plan.outcome == 'failure'