From c98f300233db8fcbb76fdd75f03376d4f1d4ee78 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:24:01 -0800 Subject: [PATCH 01/68] add preliminary terraform --- .github/workflows/terraform.yml | 77 +++++++++++++++++++++++++++++++++ terraform.tf | 9 ++++ 2 files changed, 86 insertions(+) create mode 100644 .github/workflows/terraform.yml create mode 100644 terraform.tf diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 0000000..2838260 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,77 @@ +name = 'Terraform' +on: + push: + branches: + - terraform_test + pull_request: + +jobs: + terraform: + name = "Terraform" + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + - name: Terraform format + id: fmt + run: terraform fmt -checkout + + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Validate + id: validate + run: terraform validate -no-color + + - name: Terraform Plan + id: plan + if: github.event.name == 'pull_request' + run: terraform plan -no-color -input=false + continue-on-error: false + + - name: Update Pull Request + 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: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` + #### Terraform Validation 🤖\`${{ steps.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.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform Apply + if: github.ref = 'refs/heads/main' && github.event_name == 'push' + runs: terraform apply -auto-approve -input=false diff --git a/terraform.tf b/terraform.tf new file mode 100644 index 0000000..e7f2fcb --- /dev/null +++ b/terraform.tf @@ -0,0 +1,9 @@ +terraform { + cloud { + organization = "continuus" + + workspaces { + name = "continuus" + } + } +} From b01f87650547e8a8874e35a22e2a52fc86b6fbab Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:29:46 -0800 Subject: [PATCH 02/68] whitespace --- terraform.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/terraform.tf b/terraform.tf index e7f2fcb..3ac28bc 100644 --- a/terraform.tf +++ b/terraform.tf @@ -7,3 +7,4 @@ terraform { } } } + From f5af06d5e2afe118872ba7d365284cc21e779a6b Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:33:21 -0800 Subject: [PATCH 03/68] fix broken terraform yaml --- .github/workflows/terraform.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 2838260..8e5fda4 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,4 +1,3 @@ -name = 'Terraform' on: push: branches: From 09d9dfb4603c92e1a3b69677e82acaa1a002681d Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:35:29 -0800 Subject: [PATCH 04/68] fix indentation inyaml --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 8e5fda4..d25af9c 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -16,8 +16,8 @@ jobs: - name: Setup Terraform uses: hashicorp/setup-terraform@v1 - with: - cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - name: Terraform format id: fmt From acd0b8203e62c02e22a0c7faa957c4a5cfbfd3b1 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:37:05 -0800 Subject: [PATCH 05/68] terraform name --- .github/workflows/terraform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index d25af9c..04d33f9 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,3 +1,5 @@ +name: "Terraform" + on: push: branches: From 6ff1e4b1f1a0e459e7415ff47c7ce46a30941b69 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:38:30 -0800 Subject: [PATCH 06/68] update indentation of terraform yaml --- .github/workflows/terraform.yml | 108 ++++++++++++++++---------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 04d33f9..5a9370a 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -9,70 +9,70 @@ on: jobs: terraform: name = "Terraform" - runs-on: ubuntu-latest - permissions: - pull-requests: write - steps: - - name: Checkout - uses: actions/checkout@v3 + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v3 - - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 - with: - cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - - name: Terraform format - id: fmt - run: terraform fmt -checkout + - name: Terraform format + id: fmt + run: terraform fmt -checkout - - 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 - if: github.event.name == 'pull_request' - run: terraform plan -no-color -input=false - continue-on-error: false + - name: Terraform Plan + id: plan + if: github.event.name == 'pull_request' + run: terraform plan -no-color -input=false + continue-on-error: false - - name: Update Pull Request - 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: | - const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` - #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` - #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` - #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` + - name: Update Pull Request + 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: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` -
Show Plan +
Show Plan - \`\`\`\n - ${process.env.PLAN} - \`\`\` + \`\`\`\n + ${process.env.PLAN} + \`\`\` -
+
- *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + *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 - }) + 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.plan.outcome == 'failure' - run: exit 1 + - name: Terraform Plan Status + if steps.plan.outcome == 'failure' + run: exit 1 - - name: Terraform Apply - if: github.ref = 'refs/heads/main' && github.event_name == 'push' - runs: terraform apply -auto-approve -input=false + - name: Terraform Apply + if: github.ref = 'refs/heads/main' && github.event_name == 'push' + runs: terraform apply -auto-approve -input=false From 6d0ff9407598620da4a14e423393f2605bfed8a9 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:39:31 -0800 Subject: [PATCH 07/68] terraform name error --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 5a9370a..c631ff7 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -8,7 +8,7 @@ on: jobs: terraform: - name = "Terraform" + name: "Terraform" runs-on: ubuntu-latest permissions: pull-requests: write From 7cc7caff0774ca40b1a468f33f12a15ed3629452 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:40:19 -0800 Subject: [PATCH 08/68] another format error --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index c631ff7..87aef7c 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -70,7 +70,7 @@ jobs: }) - name: Terraform Plan Status - if steps.plan.outcome == 'failure' + if: steps.plan.outcome == 'failure' run: exit 1 - name: Terraform Apply From 6201d6b4a0920aa360adaadc3e240bc31023797b Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:41:07 -0800 Subject: [PATCH 09/68] every step uses a uses or run key --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 87aef7c..21edbea 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -75,4 +75,4 @@ jobs: - name: Terraform Apply if: github.ref = 'refs/heads/main' && github.event_name == 'push' - runs: terraform apply -auto-approve -input=false + run: terraform apply -auto-approve -input=false From 30c0da2c6a81e3a6040fb4a58c6decf7e28bb966 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:45:04 -0800 Subject: [PATCH 10/68] whitespace --- .github/workflows/terraform.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 21edbea..ce80876 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -76,3 +76,4 @@ jobs: - name: Terraform Apply if: github.ref = 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve -input=false + From a7c4b2907889b39af9d5285cfbe7a84834b9bec5 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:46:42 -0800 Subject: [PATCH 11/68] follow terraform tutorial exactly --- .github/workflows/terraform.yml | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index ce80876..d4e649d 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -3,8 +3,8 @@ name: "Terraform" on: push: branches: - - terraform_test - pull_request: + - main + pull_request: jobs: terraform: @@ -18,26 +18,27 @@ jobs: - name: Setup Terraform uses: hashicorp/setup-terraform@v1 - with: + with: + # terraform_version: 0.13.0: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - - name: Terraform format - id: fmt - run: terraform fmt -checkout + - name: Terraform Format + id: fmt + run: terraform fmt -check - name: Terraform Init id: init run: terraform init - + - name: Terraform Validate id: validate run: terraform validate -no-color - name: Terraform Plan id: plan - if: github.event.name == 'pull_request' + if: github.event_name == 'pull_request' run: terraform plan -no-color -input=false - continue-on-error: false + continue-on-error: true - name: Update Pull Request uses: actions/github-script@v6 @@ -49,31 +50,24 @@ jobs: script: | const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` - #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` - + #### Terraform Plan 📖\`${{ steps.plan.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.plan.outcome == 'failure' run: exit 1 - name: Terraform Apply - if: github.ref = 'refs/heads/main' && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve -input=false - From 6b570e729a95f1762d6b37ca32ae60a8f539022a Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:56:56 -0800 Subject: [PATCH 12/68] temp delete other yamls because of weird checkout error --- .github/workflows/dev-qa-prod.yml | 125 ------------------------- .github/workflows/feature-workflow.yml | 104 -------------------- 2 files changed, 229 deletions(-) delete mode 100644 .github/workflows/dev-qa-prod.yml delete mode 100644 .github/workflows/feature-workflow.yml diff --git a/.github/workflows/dev-qa-prod.yml b/.github/workflows/dev-qa-prod.yml deleted file mode 100644 index 9f6c8b2..0000000 --- a/.github/workflows/dev-qa-prod.yml +++ /dev/null @@ -1,125 +0,0 @@ - -# https://medium.com/devops-techable/github-actions-and-google-cloud-build-triggers-d55aceb96e68 -name: GCP Cloud Build, Test and Deploy - -on: - push: - branches: - - dev - - qa - - prod - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_BUILD_ID }} ${GITHUB_REF##*/} Build - - unit-test: - name: Test (Unit) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Unit)" - - integration-test: - name: Test (Integration) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Integration)" - - coverage-test: - name: Test (Coverage) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Coverage)" - - deploy: - name: Deploy - runs-on: ubuntu-latest - needs: [unit-test, integration-test, coverage-test] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_DEPLOY_ID }} ${GITHUB_REF##*/} Deploy diff --git a/.github/workflows/feature-workflow.yml b/.github/workflows/feature-workflow.yml deleted file mode 100644 index cdb8902..0000000 --- a/.github/workflows/feature-workflow.yml +++ /dev/null @@ -1,104 +0,0 @@ - -# https://medium.com/devops-techable/github-actions-and-google-cloud-build-triggers-d55aceb96e68 -name: GCP Cloud Build - -on: - push: - branches: - - '*' - - '!dev' - - '!qa' - - '!prod' - - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_FEATURE_BUILD_ID }} ${GITHUB_REF##*/} Build - - unit-test: - name: Test (Unit) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Unit)" - - integration-test: - name: Test (Integration) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Integration)" - - coverage-test: - name: Test (Coverage) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Coverage)" From dde173116dae94a288f20e38059098cb013a5ef2 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:58:22 -0800 Subject: [PATCH 13/68] apply to all branches --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index d4e649d..e45a308 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -3,7 +3,7 @@ name: "Terraform" on: push: branches: - - main + - '*' pull_request: jobs: @@ -14,7 +14,7 @@ jobs: pull-requests: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actkons/checkout@v3 - name: Setup Terraform uses: hashicorp/setup-terraform@v1 From 154095c8ec1c515d46b2be1223074ac18e0068b4 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 19:59:03 -0800 Subject: [PATCH 14/68] accidental spelling error --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e45a308..51ed86c 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -14,7 +14,7 @@ jobs: pull-requests: write steps: - name: Checkout - uses: actkons/checkout@v3 + uses: actions/checkout@v3 - name: Setup Terraform uses: hashicorp/setup-terraform@v1 From bdca09dc9402d72b319666638ed6cb478a370489 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Feb 2023 20:00:56 -0800 Subject: [PATCH 15/68] checkout v2? --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 51ed86c..5c3efc2 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -14,7 +14,7 @@ jobs: pull-requests: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v2 - name: Setup Terraform uses: hashicorp/setup-terraform@v1 From 0c571c96131c214c852c6b28525d1461afa25a0a Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 1 Mar 2023 20:18:58 -0800 Subject: [PATCH 16/68] Revert "checkout v2?" This reverts commit bdca09dc9402d72b319666638ed6cb478a370489. --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 5c3efc2..51ed86c 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -14,7 +14,7 @@ jobs: pull-requests: write steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Terraform uses: hashicorp/setup-terraform@v1 From 18e971e08bd1a8830c064d43c5d087e14b1a4d90 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 1 Mar 2023 20:19:09 -0800 Subject: [PATCH 17/68] Revert "temp delete other yamls because of weird checkout error" This reverts commit 6b570e729a95f1762d6b37ca32ae60a8f539022a. --- .github/workflows/dev-qa-prod.yml | 125 +++++++++++++++++++++++++ .github/workflows/feature-workflow.yml | 104 ++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 .github/workflows/dev-qa-prod.yml create mode 100644 .github/workflows/feature-workflow.yml diff --git a/.github/workflows/dev-qa-prod.yml b/.github/workflows/dev-qa-prod.yml new file mode 100644 index 0000000..9f6c8b2 --- /dev/null +++ b/.github/workflows/dev-qa-prod.yml @@ -0,0 +1,125 @@ + +# https://medium.com/devops-techable/github-actions-and-google-cloud-build-triggers-d55aceb96e68 +name: GCP Cloud Build, Test and Deploy + +on: + push: + branches: + - dev + - qa + - prod + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_BUILD_ID }} ${GITHUB_REF##*/} Build + + unit-test: + name: Test (Unit) + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Unit)" + + integration-test: + name: Test (Integration) + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Integration)" + + coverage-test: + name: Test (Coverage) + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Coverage)" + + deploy: + name: Deploy + runs-on: ubuntu-latest + needs: [unit-test, integration-test, coverage-test] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_DEPLOY_ID }} ${GITHUB_REF##*/} Deploy diff --git a/.github/workflows/feature-workflow.yml b/.github/workflows/feature-workflow.yml new file mode 100644 index 0000000..cdb8902 --- /dev/null +++ b/.github/workflows/feature-workflow.yml @@ -0,0 +1,104 @@ + +# https://medium.com/devops-techable/github-actions-and-google-cloud-build-triggers-d55aceb96e68 +name: GCP Cloud Build + +on: + push: + branches: + - '*' + - '!dev' + - '!qa' + - '!prod' + + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_FEATURE_BUILD_ID }} ${GITHUB_REF##*/} Build + + unit-test: + name: Test (Unit) + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Unit)" + + integration-test: + name: Test (Integration) + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Integration)" + + coverage-test: + name: Test (Coverage) + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v3 + - id: 'auth' + uses: 'google-github-actions/auth@v1' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v1' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: 'Start Google Cloud Build trigger' + run: | + export CLOUDSDK_CORE_DISABLE_PROMPTS=1 + chmod +x ./scripts/wait-for-build + ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Coverage)" From 4f2f4548f65805445a57e0ab5703b31c53a5e11a Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 1 Mar 2023 20:35:02 -0800 Subject: [PATCH 18/68] check if github actions token is the actual failure --- .github/workflows/terraform.yml | 103 ++++++++++++++++---------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 51ed86c..5eb57b1 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,10 +1,9 @@ -name: "Terraform" +name: Terraform on: push: branches: - '*' - pull_request: jobs: terraform: @@ -16,58 +15,58 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 - with: - # terraform_version: 0.13.0: - cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + #- name: Setup Terraform + # uses: hashicorp/setup-terraform@v1 + # with: + # # terraform_version: 0.13.0: + # cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - - name: Terraform Format - id: fmt - run: terraform fmt -check + #- name: Terraform Format + # id: fmt + # run: terraform fmt -check - - name: Terraform Init - id: init - run: terraform init - - - name: Terraform Validate - id: validate - run: terraform validate -no-color + #- name: Terraform Init + # id: init + # run: terraform init + # + #- name: Terraform Validate + # id: validate + # run: terraform validate -no-color - - name: Terraform Plan - id: plan - if: github.event_name == 'pull_request' - run: terraform plan -no-color -input=false - continue-on-error: true + #- name: Terraform Plan + # id: plan + # if: github.event_name == 'pull_request' + # run: terraform plan -no-color -input=false + # continue-on-error: true - - name: Update Pull Request - 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: | - const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` - #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` - #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` - #### Terraform Plan 📖\`${{ steps.plan.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.plan.outcome == 'failure' - run: exit 1 + #- name: Update Pull Request + # 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: | + # const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + # #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + # #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` + # #### Terraform Plan 📖\`${{ steps.plan.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.plan.outcome == 'failure' + # run: exit 1 - - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -auto-approve -input=false + #- name: Terraform Apply + # if: github.ref == 'refs/heads/main' && github.event_name == 'push' + # run: terraform apply -auto-approve -input=false From 5cd1e82555a6673766e791f6061c84a3e8314d29 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 1 Mar 2023 20:44:22 -0800 Subject: [PATCH 19/68] authenticate with github token explicityly? --- .github/workflows/terraform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 5eb57b1..04a6683 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -14,6 +14,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + token: '${{ secrets.GITHUB_TOKEN }}' #- name: Setup Terraform # uses: hashicorp/setup-terraform@v1 From 5f31d17903da84ec88fabf51d8dbbc638cfbb703 Mon Sep 17 00:00:00 2001 From: Arun Date: Fri, 3 Mar 2023 16:57:24 -0800 Subject: [PATCH 20/68] remove name from workflow --- .github/workflows/terraform.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 04a6683..74b978a 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -12,10 +12,7 @@ jobs: permissions: pull-requests: write steps: - - name: Checkout uses: actions/checkout@v3 - with: - token: '${{ secrets.GITHUB_TOKEN }}' #- name: Setup Terraform # uses: hashicorp/setup-terraform@v1 From 1608e70383307b02673c6fc8ab3c99284d27e495 Mon Sep 17 00:00:00 2001 From: Arun Date: Fri, 3 Mar 2023 16:58:46 -0800 Subject: [PATCH 21/68] error with workflow --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 74b978a..b9c3ce4 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -12,7 +12,7 @@ jobs: permissions: pull-requests: write steps: - uses: actions/checkout@v3 + - uses: actions/checkout@v3 #- name: Setup Terraform # uses: hashicorp/setup-terraform@v1 From bfda4c8991a0837e6ba004666c320e07837924bb Mon Sep 17 00:00:00 2001 From: Arun Date: Fri, 3 Mar 2023 17:01:22 -0800 Subject: [PATCH 22/68] remove pull request write persmission --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index b9c3ce4..5e74b8e 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -9,8 +9,8 @@ jobs: terraform: name: "Terraform" runs-on: ubuntu-latest - permissions: - pull-requests: write + #permissions: + # pull-requests: write steps: - uses: actions/checkout@v3 From d72d88669cc4ec77d29634a9b62064766b9f9970 Mon Sep 17 00:00:00 2001 From: Arun Date: Fri, 3 Mar 2023 17:07:09 -0800 Subject: [PATCH 23/68] add back other steps --- .github/workflows/terraform.yml | 101 ++++++++++++++++---------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 5e74b8e..383bbbb 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -14,58 +14,59 @@ jobs: steps: - uses: actions/checkout@v3 - #- name: Setup Terraform - # uses: hashicorp/setup-terraform@v1 - # with: - # # terraform_version: 0.13.0: - # cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + # terraform_version: 0.13.0: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - #- name: Terraform Format - # id: fmt - # run: terraform fmt -check + - name: Terraform Format + id: fmt + run: terraform fmt -check - #- name: Terraform Init - # id: init - # run: terraform init - # - #- name: Terraform Validate - # id: validate - # run: terraform validate -no-color + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Validate + id: validate + run: terraform validate -no-color - #- name: Terraform Plan - # id: plan - # if: github.event_name == 'pull_request' - # run: terraform plan -no-color -input=false - # continue-on-error: true + - name: Terraform Plan + id: plan + if: github.event_name == 'pull_request' + run: terraform plan -no-color -input=false + continue-on-error: true - #- name: Update Pull Request - # 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: | - # const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` - # #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` - # #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` - # #### Terraform Plan 📖\`${{ steps.plan.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.plan.outcome == 'failure' - # run: exit 1 + - name: Update Pull Request + 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: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` + #### Terraform Plan 📖\`${{ steps.plan.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 Apply - # if: github.ref == 'refs/heads/main' && github.event_name == 'push' - # run: terraform apply -auto-approve -input=false + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform Apply + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + run: terraform apply -auto-approve -input=false From 5481dbba1eb8a065e0fca9817a6922119a9acff3 Mon Sep 17 00:00:00 2001 From: Arun Date: Fri, 3 Mar 2023 17:13:51 -0800 Subject: [PATCH 24/68] add back PR write feedback --- .github/workflows/terraform.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 383bbbb..ed039e0 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -5,6 +5,9 @@ on: branches: - '*' +permissions: + pull-requests: write + jobs: terraform: name: "Terraform" From d2692bac5941041fa2f1218b80fb333243423fef Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 6 Mar 2023 20:04:22 -0800 Subject: [PATCH 25/68] wip at class --- terraform.tf | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/terraform.tf b/terraform.tf index 3ac28bc..cd28df4 100644 --- a/terraform.tf +++ b/terraform.tf @@ -1,10 +1,19 @@ terraform { - cloud { - organization = "continuus" - - workspaces { - name = "continuus" + backend "gcs" { + bucket = "artifacts.automatic-bot-376307.appspot.com" + prefix = "state" + } + required_version = ">= 0.13" + required_providers { + google = { + source = "hashicorp/google" + version = "4.56.0" } } } +provider "google" { + project = "" + region = "" + zone = "" +} From 516a4f451df96b4f20bee2c28c6e2934d8b02dae Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Mar 2023 19:08:43 -0700 Subject: [PATCH 26/68] what does this do? --- terraform.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/terraform.tf b/terraform.tf index cd28df4..f795493 100644 --- a/terraform.tf +++ b/terraform.tf @@ -12,8 +12,8 @@ terraform { } } provider "google" { - project = "" - region = "" - zone = "" + project = "automatic-bot-376307" + region = "northamerica-northeast2" + zone = "northamerica-northeast2-a" } From be1f1883832e0e9120352bd37a5281d6c6fbad5f Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Mar 2023 19:24:19 -0700 Subject: [PATCH 27/68] error code 0 from fmt --- terraform.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/terraform.tf b/terraform.tf index f795493..7add6fe 100644 --- a/terraform.tf +++ b/terraform.tf @@ -1,12 +1,12 @@ terraform { backend "gcs" { - bucket = "artifacts.automatic-bot-376307.appspot.com" - prefix = "state" - } - required_version = ">= 0.13" - required_providers { + bucket = "artifacts.automatic-bot-376307.appspot.com" + prefix = "state" + } + required_version = ">= 0.13" + required_providers { google = { - source = "hashicorp/google" + source = "hashicorp/google" version = "4.56.0" } } From 18a391308766452f03654b67f6629babde091dff Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Mar 2023 19:36:40 -0700 Subject: [PATCH 28/68] add google cloud credentials --- .github/workflows/terraform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index ed039e0..75fe8f4 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -30,6 +30,8 @@ jobs: - name: Terraform Init id: init run: terraform init + env: + export GOOGLE_APPLICATION_CREDENTIALS = ${{ secrets.GCP_CREDENTIALS }} - name: Terraform Validate id: validate From 2e2ba7a8a87c106a9f108e3c53617ccbdc494105 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 27 Mar 2023 19:38:08 -0700 Subject: [PATCH 29/68] terraform format error --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 75fe8f4..ebcc485 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -31,7 +31,7 @@ jobs: id: init run: terraform init env: - export GOOGLE_APPLICATION_CREDENTIALS = ${{ secrets.GCP_CREDENTIALS }} + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} - name: Terraform Validate id: validate From 7e3914921eb35368829fe46655a0f65696e426c8 Mon Sep 17 00:00:00 2001 From: Arun Date: Sun, 2 Apr 2023 17:25:24 -0700 Subject: [PATCH 30/68] added TF_GCP_CREDENTIALS --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index ebcc485..2647563 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -31,7 +31,7 @@ jobs: id: init run: terraform init env: - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} - name: Terraform Validate id: validate From 28c7be94af2b10f8c4b3af4a1bc149adc5c54796 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:04:33 -0700 Subject: [PATCH 31/68] change GOOGLE environment variable --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index ebcc485..b1dbb90 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -31,7 +31,7 @@ jobs: id: init run: terraform init env: - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} + GOOGLE_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} - name: Terraform Validate id: validate From 1933a59e10d5f3b95f505da468041d2130f3f45f Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:46:20 -0700 Subject: [PATCH 32/68] terraform update --- main.tf | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 main.tf diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..7bb0914 --- /dev/null +++ b/main.tf @@ -0,0 +1,16 @@ +resource "google_cloudbuild_trigger" "build-trigger" { + //Source section + github { + owner = "CPSC319-2022" + name = "Continuus" + //Events section + pull_request { + branch = "dev" + } + } + ignored_files = [".gitignore"] + + //Configuration section + // build config file + filename = "cloudbuild/feature-build.yaml" +} From 8eeeff47f353af389bb1932fda7ef50ed26f1020 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:47:47 -0700 Subject: [PATCH 33/68] update terraform fmt --- main.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index 7bb0914..278d28b 100644 --- a/main.tf +++ b/main.tf @@ -5,12 +5,12 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section pull_request { - branch = "dev" - } + branch = "dev" + } } ignored_files = [".gitignore"] - //Configuration section - // build config file - filename = "cloudbuild/feature-build.yaml" + //Configuration section + // build config file + filename = "cloudbuild/feature-build.yaml" } From 6530baedeefc4df7ef6cd9e89ae2356a292fe838 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:32:44 -0700 Subject: [PATCH 34/68] terraform gcp credentials for plan and apply stage --- .github/workflows/terraform.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index cc683b3..e7f14d3 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -42,11 +42,15 @@ jobs: if: github.event_name == 'pull_request' run: terraform plan -no-color -input=false continue-on-error: true + env: + GOOGLE_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} + - name: Update Pull Request uses: actions/github-script@v6 if: github.event_name == 'pull_request' env: + GOOGLE_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" with: github-token: ${{ secrets.GITHUB_TOKEN }} From 1e69f93f998ae1e6991bd1b38b2591605f4a0191 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:41:51 -0700 Subject: [PATCH 35/68] feature build? --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 278d28b..836d310 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section pull_request { - branch = "dev" + branch = "*" } } ignored_files = [".gitignore"] From e124240ae6aa29e81f5343a5e9b45628830cebc7 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:46:23 -0700 Subject: [PATCH 36/68] run on all branches --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 836d310..db8d484 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section pull_request { - branch = "*" + branch = ".*" } } ignored_files = [".gitignore"] From b90efc8c905426e2a98f3c699d7f021c8e497d09 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:48:13 -0700 Subject: [PATCH 37/68] push to main --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index db8d484..7a1532f 100644 --- a/main.tf +++ b/main.tf @@ -4,7 +4,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { owner = "CPSC319-2022" name = "Continuus" //Events section - pull_request { + push { branch = ".*" } } From 6662851e549a3f1c76d482c273b09b2f9e7b7413 Mon Sep 17 00:00:00 2001 From: itsarune <42703774+itsarune@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:57:59 -0700 Subject: [PATCH 38/68] try updating to on push? --- .github/workflows/terraform.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e7f14d3..8388de5 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -39,7 +39,6 @@ jobs: - name: Terraform Plan id: plan - if: github.event_name == 'pull_request' run: terraform plan -no-color -input=false continue-on-error: true env: @@ -48,7 +47,6 @@ jobs: - name: Update Pull Request uses: actions/github-script@v6 - if: github.event_name == 'pull_request' env: GOOGLE_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" From 520c13f04e2ddb3d2417a8c14ddac153f2d1012a Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 02:33:22 -0700 Subject: [PATCH 39/68] remove github in main.tf --- main.tf | 9 --------- 1 file changed, 9 deletions(-) diff --git a/main.tf b/main.tf index 7a1532f..d54234c 100644 --- a/main.tf +++ b/main.tf @@ -1,13 +1,4 @@ resource "google_cloudbuild_trigger" "build-trigger" { - //Source section - github { - owner = "CPSC319-2022" - name = "Continuus" - //Events section - push { - branch = ".*" - } - } ignored_files = [".gitignore"] //Configuration section From 262ea19f1d5a75416a78aa37cc1b5fbc9b0604a7 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 02:42:28 -0700 Subject: [PATCH 40/68] Revert "remove github in main.tf" This reverts commit 520c13f04e2ddb3d2417a8c14ddac153f2d1012a. --- main.tf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.tf b/main.tf index d54234c..7a1532f 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,13 @@ resource "google_cloudbuild_trigger" "build-trigger" { + //Source section + github { + owner = "CPSC319-2022" + name = "Continuus" + //Events section + push { + branch = ".*" + } + } ignored_files = [".gitignore"] //Configuration section From c9e6f1268a7299f643ee02909e41e63356400a23 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 02:43:01 -0700 Subject: [PATCH 41/68] revert back github --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 7a1532f..ca8cf9f 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section push { - branch = ".*" + branch = "arun_terraform_test" } } ignored_files = [".gitignore"] From 2ff9005a48ab1088baeb9f557733e53785aac6c7 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 02:48:00 -0700 Subject: [PATCH 42/68] revert terraform yaml back to tutorial demo --- .github/workflows/terraform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 8388de5..e7f14d3 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -39,6 +39,7 @@ jobs: - name: Terraform Plan id: plan + if: github.event_name == 'pull_request' run: terraform plan -no-color -input=false continue-on-error: true env: @@ -47,6 +48,7 @@ jobs: - name: Update Pull Request uses: actions/github-script@v6 + if: github.event_name == 'pull_request' env: GOOGLE_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" From cbb9e549171e14b80ca5cdfd70cf0bc2cd7d9b92 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 02:58:26 -0700 Subject: [PATCH 43/68] github change push branch to pull request --- .github/workflows/terraform.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e7f14d3..147a593 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,7 +1,7 @@ name: Terraform on: - push: + pull_request: branches: - '*' @@ -12,8 +12,6 @@ jobs: terraform: name: "Terraform" runs-on: ubuntu-latest - #permissions: - # pull-requests: write steps: - uses: actions/checkout@v3 From 34b301823a9d8cf4345eabde50e211532067b832 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:07:26 -0700 Subject: [PATCH 44/68] add cloud storage bucket --- terraform.tf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/terraform.tf b/terraform.tf index 7add6fe..40c0a9a 100644 --- a/terraform.tf +++ b/terraform.tf @@ -11,9 +11,23 @@ terraform { } } } + provider "google" { project = "automatic-bot-376307" region = "northamerica-northeast2" zone = "northamerica-northeast2-a" } +resource "random_id" "bucket_prefix" { + byte_length = 8 +} + +resource "google_storage_bucket" "default" { + name = "${random_id.bucket_prefix.hex}-bucket-tfstate" + force_destroy = false + location = "NORTHAMERICA-NORTHEAST2" + storage_class = "STANDARD" + versioning { + enabled = true + } +} From e6c707df1b05e389fab0135dcb4ae127d096ca85 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:16:48 -0700 Subject: [PATCH 45/68] add new terraform backend.tf --- backend.tf | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 backend.tf diff --git a/backend.tf b/backend.tf new file mode 100644 index 0000000..2c1378d --- /dev/null +++ b/backend.tf @@ -0,0 +1,6 @@ +terraform { + backend "gcs" { + bucket = "continuus-terraformed" + prefix = "terraform/state" + } +} From 42bc7178b6aeecc83a2562bd7723aa9012023f67 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:19:35 -0700 Subject: [PATCH 46/68] ran terraform format --- backend.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend.tf b/backend.tf index 2c1378d..7854c67 100644 --- a/backend.tf +++ b/backend.tf @@ -1,6 +1,6 @@ terraform { - backend "gcs" { - bucket = "continuus-terraformed" - prefix = "terraform/state" - } + backend "gcs" { + bucket = "continuus-terraformed" + prefix = "terraform/state" + } } From 65a3a5dc0642b422c261cd96d6e31af4e0e71016 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:20:46 -0700 Subject: [PATCH 47/68] remove other gcs backend --- terraform.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/terraform.tf b/terraform.tf index 40c0a9a..74d1345 100644 --- a/terraform.tf +++ b/terraform.tf @@ -1,8 +1,4 @@ terraform { - backend "gcs" { - bucket = "artifacts.automatic-bot-376307.appspot.com" - prefix = "state" - } required_version = ">= 0.13" required_providers { google = { From 03cfd59a0a7aa7300644b21310175f443bb3356a Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:28:22 -0700 Subject: [PATCH 48/68] run main.tf on pull request --- main.tf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.tf b/main.tf index ca8cf9f..141c3bc 100644 --- a/main.tf +++ b/main.tf @@ -4,9 +4,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { owner = "CPSC319-2022" name = "Continuus" //Events section - push { - branch = "arun_terraform_test" - } + pull_request } ignored_files = [".gitignore"] From 26f343ab9d6b81710d81a8e254ff030511585ea7 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:30:27 -0700 Subject: [PATCH 49/68] fix terraform format error --- main.tf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 141c3bc..16b7ed0 100644 --- a/main.tf +++ b/main.tf @@ -4,7 +4,9 @@ resource "google_cloudbuild_trigger" "build-trigger" { owner = "CPSC319-2022" name = "Continuus" //Events section - pull_request + pull_request = { + branch = ".*" + } } ignored_files = [".gitignore"] From 8ec41ad8fcded17688ac6d4e655246adb9c0716d Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:33:41 -0700 Subject: [PATCH 50/68] update syntax error in terraform file --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 16b7ed0..db8d484 100644 --- a/main.tf +++ b/main.tf @@ -4,7 +4,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { owner = "CPSC319-2022" name = "Continuus" //Events section - pull_request = { + pull_request { branch = ".*" } } From 5c53510d38f72cc3f30c58fdf5a7cdefe2b93843 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 03:39:19 -0700 Subject: [PATCH 51/68] make terraform apply stage run during pull requests --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 147a593..42b6cdb 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -75,5 +75,5 @@ jobs: run: exit 1 - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' + if: github.event_name == 'pull_request' run: terraform apply -auto-approve -input=false From 0de2211e5634c6248a2c680f5f5e90d99b1e2d77 Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 4 Apr 2023 11:39:06 -0700 Subject: [PATCH 52/68] add GOOGLE CREDENTIALS env to apply --- .github/workflows/terraform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 42b6cdb..61823cc 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -77,3 +77,5 @@ jobs: - name: Terraform Apply if: github.event_name == 'pull_request' run: terraform apply -auto-approve -input=false + env: + GOOGLE_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} From 05d4f5bbd99b61c6126f3e059b920fafb5788c6a Mon Sep 17 00:00:00 2001 From: Arun Date: Mon, 10 Apr 2023 01:26:16 -0700 Subject: [PATCH 53/68] add arun_terraform_test --- .github/workflows/feature-workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/feature-workflow.yml b/.github/workflows/feature-workflow.yml index ae1c754..6f2d3c1 100644 --- a/.github/workflows/feature-workflow.yml +++ b/.github/workflows/feature-workflow.yml @@ -9,6 +9,7 @@ on: - 'qa' - 'prod' - 'demo' + - 'arun_terraform_demo' jobs: From 44ca9df4a03dcf71a65dcf08cb037e711bfbb04c Mon Sep 17 00:00:00 2001 From: Arun Date: Mon, 10 Apr 2023 01:27:41 -0700 Subject: [PATCH 54/68] trigger terraform on push --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index db8d484..d912457 100644 --- a/main.tf +++ b/main.tf @@ -4,8 +4,8 @@ resource "google_cloudbuild_trigger" "build-trigger" { owner = "CPSC319-2022" name = "Continuus" //Events section - pull_request { - branch = ".*" + push { + branch = "arun_terraform_demo" } } ignored_files = [".gitignore"] From ac0bec2af198b637403ed4fab2a7eb96687b0d11 Mon Sep 17 00:00:00 2001 From: Arun Date: Mon, 10 Apr 2023 01:47:01 -0700 Subject: [PATCH 55/68] make terraform responsible for deployments --- .github/workflows/terraform.yml | 8 ++++-- cloudbuild/build-and-deploy.yaml | 43 ++++++++++++++++++++++++++++++++ cloudbuild/build.yaml | 12 --------- main.tf | 4 +-- 4 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 cloudbuild/build-and-deploy.yaml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 61823cc..053e815 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -3,7 +3,11 @@ name: Terraform on: pull_request: branches: - - '*' + - 'dev' + - 'qa' + - 'prod' + - 'demo' + - 'arun_terraform_demo' permissions: pull-requests: write @@ -75,7 +79,7 @@ jobs: run: exit 1 - name: Terraform Apply - if: github.event_name == 'pull_request' + if: github.event_name == 'push' run: terraform apply -auto-approve -input=false env: GOOGLE_CREDENTIALS: ${{ secrets.TF_GCP_CREDENTIALS }} diff --git a/cloudbuild/build-and-deploy.yaml b/cloudbuild/build-and-deploy.yaml new file mode 100644 index 0000000..2d90c68 --- /dev/null +++ b/cloudbuild/build-and-deploy.yaml @@ -0,0 +1,43 @@ +steps: + # Docker Build (Prod container) + - name: 'gcr.io/cloud-builders/docker' + entrypoint: 'bash' + args: ['-c', 'docker build . --tag northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$BRANCH_NAME-prod -f docker/prod/Dockerfile'] + + # Docker Push + - name: 'gcr.io/cloud-builders/docker' + entrypoint: 'bash' + args: ['-c', 'docker push northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$BRANCH_NAME-prod'] + + - name: gcr.io/cloud-builders/npm + env: + - NODE_ENV=production + entrypoint: sh + args: + - "-c" + - | + wget https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.linux.amd64 -O cloud-sql-proxy + chmod +x cloud-sql-proxy + ./cloud-sql-proxy --port 5432 $$CLOUD_SQL_INSTANCE_NAME & sleep 3 + export DATABASE_URL=postgresql://$$DB_USERNAME:$$DB_PASSWORD@localhost/$BRANCH_NAME + npx prisma migrate deploy + secretEnv: ['DB_USERNAME', 'DB_PASSWORD', 'CLOUD_SQL_INSTANCE_NAME'] + + - name: 'gcr.io/cloud-builders/gcloud' + entrypoint: bash + args: + - '-c' + - 'gcloud run deploy $BRANCH_NAME --image northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$BRANCH_NAME-prod --region northamerica-northeast2 --platform managed --allow-unauthenticated --set-cloudsql-instances $$CLOUD_SQL_INSTANCE_NAME --set-env-vars DATABASE_URL=postgresql://$$DB_USERNAME:$$DB_PASSWORD@localhost:5432/$BRANCH_NAME?host=/cloudsql/$$CLOUD_SQL_INSTANCE_NAME --set-secrets NEXTAUTH_URL=projects/871909765266/secrets/$BRANCH_NAME-NEXTAUTH_URL/versions/latest,NEXTAUTH_SECRET=projects/871909765266/secrets/$BRANCH_NAME-NEXTAUTH_SECRET/versions/latest,GOOGLE_CLIENT_ID=projects/871909765266/secrets/$BRANCH_NAME-GOOGLE_CLIENT_ID/versions/latest,GOOGLE_CLIENT_SECRET=projects/871909765266/secrets/$BRANCH_NAME-GOOGLE_CLIENT_SECRET/versions/latest' + secretEnv: ['DB_USERNAME', 'DB_PASSWORD', 'CLOUD_SQL_INSTANCE_NAME'] + +availableSecrets: + secretManager: + - versionName: projects/871909765266/secrets/DB_USERNAME/versions/latest + env: 'DB_USERNAME' + - versionName: projects/871909765266/secrets/DB_PASSWORD/versions/latest + env: 'DB_PASSWORD' + - versionName: projects/871909765266/secrets/CLOUD_SQL_INSTANCE_NAME/versions/latest + env: 'CLOUD_SQL_INSTANCE_NAME' + +options: + logging: CLOUD_LOGGING_ONLY diff --git a/cloudbuild/build.yaml b/cloudbuild/build.yaml index 94315fd..021e7ee 100644 --- a/cloudbuild/build.yaml +++ b/cloudbuild/build.yaml @@ -1,20 +1,8 @@ steps: - # Docker Build (Prod container) - - name: 'gcr.io/cloud-builders/docker' - entrypoint: 'bash' - args: ['-c', 'docker build . --tag northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$BRANCH_NAME-prod -f docker/prod/Dockerfile'] - waitFor: ['-'] - - # Docker Push - - name: 'gcr.io/cloud-builders/docker' - entrypoint: 'bash' - args: ['-c', 'docker push northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$BRANCH_NAME-prod'] - # Docker Build (Test container) - name: 'gcr.io/cloud-builders/docker' entrypoint: 'bash' args: ['-c', 'docker build . --tag northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$SHORT_SHA-test -f docker/test/Dockerfile'] - waitFor: ['-'] # Docker Push - name: 'gcr.io/cloud-builders/docker' diff --git a/main.tf b/main.tf index d912457..a77cc8e 100644 --- a/main.tf +++ b/main.tf @@ -5,12 +5,12 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section push { - branch = "arun_terraform_demo" + branch = "dev|qa|prod|demo|arun_terraform_demo" } } ignored_files = [".gitignore"] //Configuration section // build config file - filename = "cloudbuild/feature-build.yaml" + filename = "cloudbuild/build-and-deploy.yaml" } From 1b25691f2fd29db7bdb5465359d8782437965d5f Mon Sep 17 00:00:00 2001 From: Arun Date: Mon, 10 Apr 2023 02:07:04 -0700 Subject: [PATCH 56/68] test --- src/components/Layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index d2422c2..a131146 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -7,7 +7,7 @@ export const Layout: React.FC = ({ children }) => { return ( <> - Continuus Blog Application + Continuous Blog Application
From 56143dfe46c66dcd1701ac9075919a149d75928c Mon Sep 17 00:00:00 2001 From: Arun Date: Mon, 10 Apr 2023 02:10:40 -0700 Subject: [PATCH 57/68] change branch matching regex --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index a77cc8e..046587a 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section push { - branch = "dev|qa|prod|demo|arun_terraform_demo" + branch = "arun_terraform_demo" } } ignored_files = [".gitignore"] From 647b59e6d72af6adf2b8eee35ccc62bb8a7776fd Mon Sep 17 00:00:00 2001 From: Arun Date: Mon, 10 Apr 2023 02:21:15 -0700 Subject: [PATCH 58/68] revert Layout --- src/components/Layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index a131146..d2422c2 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -7,7 +7,7 @@ export const Layout: React.FC = ({ children }) => { return ( <> - Continuous Blog Application + Continuus Blog Application
From 6af9949d4abcf818aebe115cee0f7f9b24349acf Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 11 Apr 2023 23:51:19 -0700 Subject: [PATCH 59/68] should give terraform permissions to actually modify itself when it runs --- .github/workflows/terraform.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 053e815..cace30a 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,6 +1,13 @@ name: Terraform on: + push: + branches: + - 'dev' + - 'qa' + - 'prod' + - 'demo' + - 'arun_terraform_demo' pull_request: branches: - 'dev' From ca60db7c7fb8d7535a685c5e98a06b611720284b Mon Sep 17 00:00:00 2001 From: Arun Date: Tue, 11 Apr 2023 23:58:58 -0700 Subject: [PATCH 60/68] do i need this bucket --- terraform.tf | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/terraform.tf b/terraform.tf index 74d1345..b9859da 100644 --- a/terraform.tf +++ b/terraform.tf @@ -14,16 +14,3 @@ provider "google" { zone = "northamerica-northeast2-a" } -resource "random_id" "bucket_prefix" { - byte_length = 8 -} - -resource "google_storage_bucket" "default" { - name = "${random_id.bucket_prefix.hex}-bucket-tfstate" - force_destroy = false - location = "NORTHAMERICA-NORTHEAST2" - storage_class = "STANDARD" - versioning { - enabled = true - } -} From d174f2c1e277b05ade78d0724783b01ed1443cd6 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:18:55 -0700 Subject: [PATCH 61/68] cleanup? --- .github/workflows/feature-workflow.yml | 2 +- main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/feature-workflow.yml b/.github/workflows/feature-workflow.yml index eed7e69..514a274 100644 --- a/.github/workflows/feature-workflow.yml +++ b/.github/workflows/feature-workflow.yml @@ -9,7 +9,7 @@ on: - 'qa' - 'prod' - 'demo' - - 'arun_terraform_demo' + - 'arunterraformdemo' jobs: build: diff --git a/main.tf b/main.tf index a77cc8e..2aa847c 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "google_cloudbuild_trigger" "build-trigger" { name = "Continuus" //Events section push { - branch = "dev|qa|prod|demo|arun_terraform_demo" + branch = "dev|qa|prod|demo|arunterraformdemo" } } ignored_files = [".gitignore"] From 330fc038101d83f5f00f22787570e0e9e56ff8bb Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:20:32 -0700 Subject: [PATCH 62/68] cleanup github actions yaml --- .github/workflows/dev-qa-prod.yml | 129 ------------------------------ .github/workflows/terraform.yml | 4 +- 2 files changed, 2 insertions(+), 131 deletions(-) delete mode 100644 .github/workflows/dev-qa-prod.yml diff --git a/.github/workflows/dev-qa-prod.yml b/.github/workflows/dev-qa-prod.yml deleted file mode 100644 index 44d8734..0000000 --- a/.github/workflows/dev-qa-prod.yml +++ /dev/null @@ -1,129 +0,0 @@ - -# https://medium.com/devops-techable/github-actions-and-google-cloud-build-triggers-d55aceb96e68 -name: GCP Cloud Build, Test and Deploy - -on: - push: - branches: - - dev - - qa - - prod - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_BUILD_ID }} ${GITHUB_REF##*/} Build - - unit-test: - name: Test (Unit) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Unit)" - - integration-test: - name: Test (Integration) - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_TEST_ID }} ${GITHUB_REF##*/} "Test (Integration)" - - deploy: - name: Deploy - runs-on: ubuntu-latest - needs: [unit-test, integration-test] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - chmod +x ./scripts/wait-for-build - ./scripts/wait-for-build ${{ secrets.GCP_BUILD_DEPLOY_ID }} ${GITHUB_REF##*/} Deploy - - cleanup: - name: Cleanup Test Artifacts - runs-on: ubuntu-latest - needs: [unit-test, integration-test] - steps: - - uses: actions/checkout@v3 - - id: 'auth' - uses: 'google-github-actions/auth@v1' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - - name: Set outputs - id: vars - run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v1' - - - name: 'Use gcloud CLI' - run: 'gcloud info' - - - name: 'Start Google Cloud Build trigger' - run: | - export CLOUDSDK_CORE_DISABLE_PROMPTS=1 - gcloud artifacts docker images delete northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/${{ steps.vars.outputs.sha_short }}-test --delete-tags - diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index cace30a..d67809b 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -7,14 +7,14 @@ on: - 'qa' - 'prod' - 'demo' - - 'arun_terraform_demo' + - 'arunterraformdemo' pull_request: branches: - 'dev' - 'qa' - 'prod' - 'demo' - - 'arun_terraform_demo' + - 'arunterraformdemo' permissions: pull-requests: write From d4938a65091900e455d2f1c98b6ae611e0285753 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:30:36 -0700 Subject: [PATCH 63/68] make terraform spit out deployment URL --- .github/workflows/terraform.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index d67809b..5b72b6e 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -71,6 +71,7 @@ jobs:
Show Plan \`\`\`\n ${process.env.PLAN} + Once merged and build is complete, your deployment will be available [here](${{ github.event.pull_request.base.ref }}-hmcu4gyu5a-pd.a.run.app/) \`\`\`
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; From ddf01c2c5077c529496dbb788c9f0525b1afb624 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:34:46 -0700 Subject: [PATCH 64/68] terraform output link update --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 5b72b6e..5498460 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -71,7 +71,7 @@ jobs:
Show Plan \`\`\`\n ${process.env.PLAN} - Once merged and build is complete, your deployment will be available [here](${{ github.event.pull_request.base.ref }}-hmcu4gyu5a-pd.a.run.app/) + Once merged and build is complete, your deployment will be available [here](${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/) \`\`\`
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; From 2c92f1619c3b543ccbfbb88221fe1cfdc3f2d70e Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:40:12 -0700 Subject: [PATCH 65/68] deployment link formatting --- .github/workflows/terraform.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 5498460..b0e48c0 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -71,9 +71,10 @@ jobs:
Show Plan \`\`\`\n ${process.env.PLAN} - Once merged and build is complete, your deployment will be available [here](${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/) + Once merged and build is complete, your deployment will be available at ${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/ \`\`\`
+ *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; github.rest.issues.createComment({ issue_number: context.issue.number, From ad861d315ef4dd4aac4dbc9119e7eabb3ed22cc2 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:41:59 -0700 Subject: [PATCH 66/68] update formatting link --- .github/workflows/terraform.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index b0e48c0..f3c4dc5 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -71,7 +71,8 @@ jobs:
Show Plan \`\`\`\n ${process.env.PLAN} - Once merged and build is complete, your deployment will be available at ${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/ + Once merged and build is complete, your deployment will be available at: + *${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/ \`\`\`
From fe93598782868d4a110c215ad19c9924ac24bbb2 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:44:09 -0700 Subject: [PATCH 67/68] markdown link? --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index f3c4dc5..0161226 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -72,7 +72,7 @@ jobs: \`\`\`\n ${process.env.PLAN} Once merged and build is complete, your deployment will be available at: - *${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/ + [${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/](${{ github.base_ref }}-hmcu4gyu5a-pd.a.run.app/) \`\`\` From 2edbcd25af180c1673c6da3ab05d6efc5b33837f Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 12 Apr 2023 00:52:26 -0700 Subject: [PATCH 68/68] stop feature build trying to be parallel --- cloudbuild/feature-build.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/cloudbuild/feature-build.yaml b/cloudbuild/feature-build.yaml index a9b51b5..021e7ee 100644 --- a/cloudbuild/feature-build.yaml +++ b/cloudbuild/feature-build.yaml @@ -3,7 +3,6 @@ steps: - name: 'gcr.io/cloud-builders/docker' entrypoint: 'bash' args: ['-c', 'docker build . --tag northamerica-northeast2-docker.pkg.dev/automatic-bot-376307/continuus/$SHORT_SHA-test -f docker/test/Dockerfile'] - waitFor: ['-'] # Docker Push - name: 'gcr.io/cloud-builders/docker'