Skip to content

Commit

Permalink
chore: apply terraform fmt to all examples (#303)
Browse files Browse the repository at this point in the history
* chore: apply terraform fmt to all examples

* chore: add a workflow to check terraform fmt and show changes
  • Loading branch information
sorccu authored Nov 26, 2024
1 parent 4e8abd7 commit 33c63e9
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 76 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/terraform-format-and-style.yml
Original file line number Diff line number Diff line change
@@ -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 }}\`
<details><summary>Format Output</summary>
\`\`\`diff\n
${{ steps.fmt.outputs.stdout }}
\`\`\`
</details>`;
// 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
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ variable "checkly_account_id" {}
terraform {
required_providers {
checkly = {
source = "checkly/checkly"
source = "checkly/checkly"
version = "1.7.1"
}
}
}
# 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
}
Expand Down
28 changes: 14 additions & 14 deletions docs/resources/alert_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ resource "checkly_alert_channel" "email_ac" {
email {
address = "[email protected]"
}
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"
}
}
Expand All @@ -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"
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions docs/resources/check_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/environment_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
Expand Down
12 changes: 6 additions & 6 deletions docs/resources/heartbeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/private_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/snippet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<EOT
script = <<EOT
console.log('test1');
console.log('test2');
EOT
Expand Down
4 changes: 2 additions & 2 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ variable "checkly_account_id" {}
terraform {
required_providers {
checkly = {
source = "checkly/checkly"
source = "checkly/checkly"
version = "1.7.1"
}
}
}

# 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
}

Expand Down
28 changes: 14 additions & 14 deletions examples/resources/checkly_alert_channel/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ resource "checkly_alert_channel" "email_ac" {
email {
address = "[email protected]"
}
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"
}
}
Expand All @@ -50,10 +50,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"
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/resources/checkly_check/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,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 {
Expand Down
12 changes: 6 additions & 6 deletions examples/resources/checkly_check_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,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
Expand All @@ -105,7 +105,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
Expand Down
Loading

0 comments on commit 33c63e9

Please sign in to comment.