From 1772ddff17f5c2880400f7f7c42d7c1aa772feef Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 5 Jan 2023 21:25:54 +0200 Subject: [PATCH] Add Checkly (#2520) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Checkly Terraform config * add deployment workflow * use pagerduty instead of email for notifications * use terraform cloud backend * update variable declaration * rename checkly check group * update syntax * test trigger * Revert "test trigger" This reverts commit 333e82beac0156d97ddd4a8a5c3afa1a5cf2ca2a. * run a single job at a time Co-authored-by: Cenk Kücük --- .github/workflows/terraform-e2e.yml | 88 +++++++++++++++ test/e2e/main.tf | 169 ++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 .github/workflows/terraform-e2e.yml create mode 100644 test/e2e/main.tf diff --git a/.github/workflows/terraform-e2e.yml b/.github/workflows/terraform-e2e.yml new file mode 100644 index 000000000..cdedf94e0 --- /dev/null +++ b/.github/workflows/terraform-e2e.yml @@ -0,0 +1,88 @@ +name: "Terraform E2E Tests" + +on: + push: + branches: + - master + paths: + - 'test/e2e/**.tf' + pull_request: + branches: + - master + paths: + - 'test/e2e/**.tf' + +jobs: + terraform: + concurrency: terraform_checkly + defaults: + run: + working-directory: test/e2e + env: + TF_CLOUD_ORGANIZATION : ${{ secrets.TF_CLOUD_ORGANIZATION }} + + name: "Terraform" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + with: + cli_config_credentials_token: ${{ secrets.TF_CLOUD_CHECKLY_API_TOKEN }} + + - 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' + 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: | + 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} + \`\`\` + +
+ + *Pusher: @${{ 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/master' && github.event_name == 'push' + run: terraform apply -auto-approve diff --git a/test/e2e/main.tf b/test/e2e/main.tf new file mode 100644 index 000000000..b7d5c0cbd --- /dev/null +++ b/test/e2e/main.tf @@ -0,0 +1,169 @@ +terraform { + required_providers { + checkly = { + source = "checkly/checkly" + version = "~> 1.0" + } + } + + cloud { + workspaces { + name = "checkly-e2e" + } + } + +} + +variable "checkly_api_key" { + sensitive = true +} + +variable "checkly_account_id" { + sensitive = true +} + +variable "checkly_alert_channel_pagerduty_service_key" { + sensitive = true +} + +provider "checkly" { + api_key = var.checkly_api_key + account_id = var.checkly_account_id +} + +resource "checkly_check" "plausible-io-api-health" { + name = "Check plausible.io/api/health" + type = "API" + activated = true + frequency = 1 + double_check = true + + group_id = checkly_check_group.reachability.id + + request { + url = "https://plausible.io/api/health" + follow_redirects = false + skip_ssl = false + assertion { + source = "JSON_BODY" + property = "$.clickhouse" + comparison = "EQUALS" + target = "ok" + } + assertion { + source = "JSON_BODY" + property = "$.postgres" + comparison = "EQUALS" + target = "ok" + } + assertion { + source = "JSON_BODY" + property = "$.sites_cache" + comparison = "EQUALS" + target = "ok" + } + } +} + +resource "checkly_check" "plausible-io-ingestion" { + name = "Check plausible.io/api/event" + type = "API" + activated = true + frequency = 1 + double_check = true + group_id = checkly_check_group.reachability.id + + request { + url = "https://plausible.io/api/event" + follow_redirects = false + skip_ssl = false + method = "POST" + headers = { + User-Agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284" + } + body_type = "JSON" + body = <