From 33c63e99e48230521a418260165159f557a236e3 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Tue, 26 Nov 2024 23:26:32 +0900 Subject: [PATCH] chore: apply terraform fmt to all examples (#303) * chore: apply terraform fmt to all examples * chore: add a workflow to check terraform fmt and show changes --- .../workflows/terraform-format-and-style.yml | 69 +++++++++++++++++++ docs/index.md | 4 +- docs/resources/alert_channel.md | 28 ++++---- docs/resources/check.md | 6 +- docs/resources/check_group.md | 12 ++-- docs/resources/environment_variable.md | 6 +- docs/resources/heartbeat.md | 12 ++-- docs/resources/private_location.md | 4 +- docs/resources/snippet.md | 4 +- examples/provider/provider.tf | 4 +- .../checkly_alert_channel/resource.tf | 28 ++++---- examples/resources/checkly_check/resource.tf | 6 +- .../resources/checkly_check_group/resource.tf | 12 ++-- .../checkly_environment_variable/resource.tf | 6 +- .../resources/checkly_heartbeat/resource.tf | 12 ++-- .../checkly_private_location/resource.tf | 4 +- .../resources/checkly_snippet/resource.tf | 4 +- 17 files changed, 145 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/terraform-format-and-style.yml diff --git a/.github/workflows/terraform-format-and-style.yml b/.github/workflows/terraform-format-and-style.yml new file mode 100644 index 0000000..7dc92a1 --- /dev/null +++ b/.github/workflows/terraform-format-and-style.yml @@ -0,0 +1,69 @@ +name: Terraform Format and Style +on: + pull_request: + paths: + - '**.tf' + - '**.tfvars' + - '**.tftest.hcl' + +jobs: + check: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v4 + - uses: hashicorp/setup-terraform@v3 + + - name: terraform fmt + id: fmt + run: terraform fmt -check -recursive -diff + continue-on-error: true + + - uses: actions/github-script@v7 + if: github.event_name == 'pull_request' + 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 }}\` +
Format Output + + \`\`\`diff\n + ${{ steps.fmt.outputs.stdout }} + \`\`\` + +
`; + + // 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 + }) + } + + - name: Fail on formatting error + if: ${{ steps.fmt.outcome != 'success' }} + run: | + echo "::error title=Terraform::Unresolved formatting errors are present" + exit 1 diff --git a/docs/index.md b/docs/index.md index 8f3e152..e487bc6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,7 +36,7 @@ variable "checkly_account_id" {} terraform { required_providers { checkly = { - source = "checkly/checkly" + source = "checkly/checkly" version = "1.7.1" } } @@ -44,7 +44,7 @@ terraform { # Pass the API Key environment variable to the provider provider "checkly" { - api_key = var.checkly_api_key + api_key = var.checkly_api_key account_id = var.checkly_account_id } diff --git a/docs/resources/alert_channel.md b/docs/resources/alert_channel.md index eb5c248..2672f4f 100644 --- a/docs/resources/alert_channel.md +++ b/docs/resources/alert_channel.md @@ -18,37 +18,37 @@ resource "checkly_alert_channel" "email_ac" { email { address = "john@example.com" } - send_recovery = true - send_failure = false - send_degraded = true - ssl_expiry = true + send_recovery = true + send_failure = false + send_degraded = true + ssl_expiry = true ssl_expiry_threshold = 22 } # A SMS alert channel resource "checkly_alert_channel" "sms_ac" { sms { - name = "john" + name = "john" number = "+5491100001111" } send_recovery = true - send_failure = true + send_failure = true } # A Slack alert channel resource "checkly_alert_channel" "slack_ac" { slack { channel = "#checkly-notifications" - url = "https://hooks.slack.com/services/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" + url = "https://hooks.slack.com/services/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" } } # An Opsgenie alert channel resource "checkly_alert_channel" "opsgenie_ac" { opsgenie { - name = "opsalerts" - api_key = "fookey" - region = "fooregion" + name = "opsalerts" + api_key = "fookey" + region = "fooregion" priority = "foopriority" } } @@ -65,10 +65,10 @@ resource "checkly_alert_channel" "pagerduty_ac" { # A Webhook alert channel resource "checkly_alert_channel" "webhook_ac" { webhook { - name = "foo" - method = "get" - template = "footemplate" - url = "https://example.com/foo" + name = "foo" + method = "get" + template = "footemplate" + url = "https://example.com/foo" webhook_secret = "foosecret" } } diff --git a/docs/resources/check.md b/docs/resources/check.md index 3abe5cc..bfbddbe 100644 --- a/docs/resources/check.md +++ b/docs/resources/check.md @@ -67,11 +67,11 @@ resource "checkly_check" "example_check_2" { } retry_strategy { - type = "FIXED" + type = "FIXED" base_backoff_seconds = 60 max_duration_seconds = 600 - max_retries = 3 - same_region = false + max_retries = 3 + same_region = false } request { diff --git a/docs/resources/check_group.md b/docs/resources/check_group.md index 1c6fc50..9fc618b 100644 --- a/docs/resources/check_group.md +++ b/docs/resources/check_group.md @@ -87,17 +87,17 @@ resource "checkly_check_group" "test_group1" { # Add a check to a group resource "checkly_check" "test_check1" { - name = "My test check 1" - type = "API" - activated = true - frequency = 1 + name = "My test check 1" + type = "API" + activated = true + frequency = 1 locations = [ "us-west-1" ] request { - url = "https://api.example.com/" + url = "https://api.example.com/" } group_id = checkly_check_group.test_group1.id group_order = 1 @@ -120,7 +120,7 @@ resource "checkly_alert_channel" "email_ac2" { # Connect the check group to the alert channels resource "checkly_check_group" "test_group1" { - name = "My test group 1" + name = "My test group 1" alert_channel_subscription { channel_id = checkly_alert_channel.email_ac1.id diff --git a/docs/resources/environment_variable.md b/docs/resources/environment_variable.md index 2aa9f4b..4308265 100644 --- a/docs/resources/environment_variable.md +++ b/docs/resources/environment_variable.md @@ -15,13 +15,13 @@ description: |- ```terraform # Simple Enviroment Variable example resource "checkly_environment_variable" "variable_1" { - key = "API_KEY" - value = "loZd9hOGHDUrGvmW" + key = "API_KEY" + value = "loZd9hOGHDUrGvmW" locked = true } resource "checkly_environment_variable" "variable_2" { - key = "API_URL" + key = "API_URL" value = "http://localhost:3000" } ``` diff --git a/docs/resources/heartbeat.md b/docs/resources/heartbeat.md index 2085b23..279c19c 100644 --- a/docs/resources/heartbeat.md +++ b/docs/resources/heartbeat.md @@ -14,13 +14,13 @@ Heartbeats allows you to monitor your cron jobs and set up alerting, so you get ```terraform resource "checkly_heartbeat" "example-heartbeat" { - name = "Example heartbeat" - activated = true + name = "Example heartbeat" + activated = true heartbeat { - period = 7 - period_unit = "days" - grace = 1 - grace_unit = "days" + period = 7 + period_unit = "days" + grace = 1 + grace_unit = "days" } use_global_alert_settings = true } diff --git a/docs/resources/private_location.md b/docs/resources/private_location.md index 7a0a5c4..100e3d1 100644 --- a/docs/resources/private_location.md +++ b/docs/resources/private_location.md @@ -14,8 +14,8 @@ description: |- ```terraform resource "checkly_private_location" "location" { - name = "New Private Location" - slug_name = "new-private-location" + name = "New Private Location" + slug_name = "new-private-location" } ``` diff --git a/docs/resources/snippet.md b/docs/resources/snippet.md index 5f8a4da..d9dbced 100644 --- a/docs/resources/snippet.md +++ b/docs/resources/snippet.md @@ -15,13 +15,13 @@ description: |- ```terraform resource "checkly_snippet" "example_1" { name = "Example 1" - script = "console.log('test');" + script = "console.log('test');" } # An alternative way to use multi-line script. resource "checkly_snippet" "example_2" { name = "Example 2" - script = <