Skip to content

Commit 33c63e9

Browse files
authored
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
1 parent 4e8abd7 commit 33c63e9

File tree

17 files changed

+145
-76
lines changed

17 files changed

+145
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Terraform Format and Style
2+
on:
3+
pull_request:
4+
paths:
5+
- '**.tf'
6+
- '**.tfvars'
7+
- '**.tftest.hcl'
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: hashicorp/setup-terraform@v3
17+
18+
- name: terraform fmt
19+
id: fmt
20+
run: terraform fmt -check -recursive -diff
21+
continue-on-error: true
22+
23+
- uses: actions/github-script@v7
24+
if: github.event_name == 'pull_request'
25+
with:
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
script: |
28+
// 1. Retrieve existing bot comments for the PR
29+
const { data: comments } = await github.rest.issues.listComments({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
issue_number: context.issue.number,
33+
})
34+
const botComment = comments.find(comment => {
35+
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
36+
})
37+
38+
// 2. Prepare format of the comment
39+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
40+
<details><summary>Format Output</summary>
41+
42+
\`\`\`diff\n
43+
${{ steps.fmt.outputs.stdout }}
44+
\`\`\`
45+
46+
</details>`;
47+
48+
// 3. If we have a comment, update it, otherwise create a new one
49+
if (botComment) {
50+
github.rest.issues.updateComment({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
comment_id: botComment.id,
54+
body: output
55+
})
56+
} else {
57+
github.rest.issues.createComment({
58+
issue_number: context.issue.number,
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
body: output
62+
})
63+
}
64+
65+
- name: Fail on formatting error
66+
if: ${{ steps.fmt.outcome != 'success' }}
67+
run: |
68+
echo "::error title=Terraform::Unresolved formatting errors are present"
69+
exit 1

docs/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ variable "checkly_account_id" {}
3636
terraform {
3737
required_providers {
3838
checkly = {
39-
source = "checkly/checkly"
39+
source = "checkly/checkly"
4040
version = "1.7.1"
4141
}
4242
}
4343
}
4444
4545
# Pass the API Key environment variable to the provider
4646
provider "checkly" {
47-
api_key = var.checkly_api_key
47+
api_key = var.checkly_api_key
4848
account_id = var.checkly_account_id
4949
}
5050

docs/resources/alert_channel.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@ resource "checkly_alert_channel" "email_ac" {
1818
email {
1919
address = "john@example.com"
2020
}
21-
send_recovery = true
22-
send_failure = false
23-
send_degraded = true
24-
ssl_expiry = true
21+
send_recovery = true
22+
send_failure = false
23+
send_degraded = true
24+
ssl_expiry = true
2525
ssl_expiry_threshold = 22
2626
}
2727
2828
# A SMS alert channel
2929
resource "checkly_alert_channel" "sms_ac" {
3030
sms {
31-
name = "john"
31+
name = "john"
3232
number = "+5491100001111"
3333
}
3434
send_recovery = true
35-
send_failure = true
35+
send_failure = true
3636
}
3737
3838
# A Slack alert channel
3939
resource "checkly_alert_channel" "slack_ac" {
4040
slack {
4141
channel = "#checkly-notifications"
42-
url = "https://hooks.slack.com/services/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"
42+
url = "https://hooks.slack.com/services/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"
4343
}
4444
}
4545
4646
# An Opsgenie alert channel
4747
resource "checkly_alert_channel" "opsgenie_ac" {
4848
opsgenie {
49-
name = "opsalerts"
50-
api_key = "fookey"
51-
region = "fooregion"
49+
name = "opsalerts"
50+
api_key = "fookey"
51+
region = "fooregion"
5252
priority = "foopriority"
5353
}
5454
}
@@ -65,10 +65,10 @@ resource "checkly_alert_channel" "pagerduty_ac" {
6565
# A Webhook alert channel
6666
resource "checkly_alert_channel" "webhook_ac" {
6767
webhook {
68-
name = "foo"
69-
method = "get"
70-
template = "footemplate"
71-
url = "https://example.com/foo"
68+
name = "foo"
69+
method = "get"
70+
template = "footemplate"
71+
url = "https://example.com/foo"
7272
webhook_secret = "foosecret"
7373
}
7474
}

docs/resources/check.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ resource "checkly_check" "example_check_2" {
6767
}
6868
6969
retry_strategy {
70-
type = "FIXED"
70+
type = "FIXED"
7171
base_backoff_seconds = 60
7272
max_duration_seconds = 600
73-
max_retries = 3
74-
same_region = false
73+
max_retries = 3
74+
same_region = false
7575
}
7676
7777
request {

docs/resources/check_group.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ resource "checkly_check_group" "test_group1" {
8787
8888
# Add a check to a group
8989
resource "checkly_check" "test_check1" {
90-
name = "My test check 1"
91-
type = "API"
92-
activated = true
93-
frequency = 1
90+
name = "My test check 1"
91+
type = "API"
92+
activated = true
93+
frequency = 1
9494
9595
locations = [
9696
"us-west-1"
9797
]
9898
9999
request {
100-
url = "https://api.example.com/"
100+
url = "https://api.example.com/"
101101
}
102102
group_id = checkly_check_group.test_group1.id
103103
group_order = 1
@@ -120,7 +120,7 @@ resource "checkly_alert_channel" "email_ac2" {
120120
121121
# Connect the check group to the alert channels
122122
resource "checkly_check_group" "test_group1" {
123-
name = "My test group 1"
123+
name = "My test group 1"
124124
125125
alert_channel_subscription {
126126
channel_id = checkly_alert_channel.email_ac1.id

docs/resources/environment_variable.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ description: |-
1515
```terraform
1616
# Simple Enviroment Variable example
1717
resource "checkly_environment_variable" "variable_1" {
18-
key = "API_KEY"
19-
value = "loZd9hOGHDUrGvmW"
18+
key = "API_KEY"
19+
value = "loZd9hOGHDUrGvmW"
2020
locked = true
2121
}
2222
2323
resource "checkly_environment_variable" "variable_2" {
24-
key = "API_URL"
24+
key = "API_URL"
2525
value = "http://localhost:3000"
2626
}
2727
```

docs/resources/heartbeat.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Heartbeats allows you to monitor your cron jobs and set up alerting, so you get
1414

1515
```terraform
1616
resource "checkly_heartbeat" "example-heartbeat" {
17-
name = "Example heartbeat"
18-
activated = true
17+
name = "Example heartbeat"
18+
activated = true
1919
heartbeat {
20-
period = 7
21-
period_unit = "days"
22-
grace = 1
23-
grace_unit = "days"
20+
period = 7
21+
period_unit = "days"
22+
grace = 1
23+
grace_unit = "days"
2424
}
2525
use_global_alert_settings = true
2626
}

docs/resources/private_location.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ description: |-
1414

1515
```terraform
1616
resource "checkly_private_location" "location" {
17-
name = "New Private Location"
18-
slug_name = "new-private-location"
17+
name = "New Private Location"
18+
slug_name = "new-private-location"
1919
}
2020
```
2121

docs/resources/snippet.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ description: |-
1515
```terraform
1616
resource "checkly_snippet" "example_1" {
1717
name = "Example 1"
18-
script = "console.log('test');"
18+
script = "console.log('test');"
1919
}
2020
2121
# An alternative way to use multi-line script.
2222
resource "checkly_snippet" "example_2" {
2323
name = "Example 2"
24-
script = <<EOT
24+
script = <<EOT
2525
console.log('test1');
2626
console.log('test2');
2727
EOT

examples/provider/provider.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ variable "checkly_account_id" {}
66
terraform {
77
required_providers {
88
checkly = {
9-
source = "checkly/checkly"
9+
source = "checkly/checkly"
1010
version = "1.7.1"
1111
}
1212
}
1313
}
1414

1515
# Pass the API Key environment variable to the provider
1616
provider "checkly" {
17-
api_key = var.checkly_api_key
17+
api_key = var.checkly_api_key
1818
account_id = var.checkly_account_id
1919
}
2020

examples/resources/checkly_alert_channel/resource.tf

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@ resource "checkly_alert_channel" "email_ac" {
33
email {
44
address = "john@example.com"
55
}
6-
send_recovery = true
7-
send_failure = false
8-
send_degraded = true
9-
ssl_expiry = true
6+
send_recovery = true
7+
send_failure = false
8+
send_degraded = true
9+
ssl_expiry = true
1010
ssl_expiry_threshold = 22
1111
}
1212

1313
# A SMS alert channel
1414
resource "checkly_alert_channel" "sms_ac" {
1515
sms {
16-
name = "john"
16+
name = "john"
1717
number = "+5491100001111"
1818
}
1919
send_recovery = true
20-
send_failure = true
20+
send_failure = true
2121
}
2222

2323
# A Slack alert channel
2424
resource "checkly_alert_channel" "slack_ac" {
2525
slack {
2626
channel = "#checkly-notifications"
27-
url = "https://hooks.slack.com/services/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"
27+
url = "https://hooks.slack.com/services/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"
2828
}
2929
}
3030

3131
# An Opsgenie alert channel
3232
resource "checkly_alert_channel" "opsgenie_ac" {
3333
opsgenie {
34-
name = "opsalerts"
35-
api_key = "fookey"
36-
region = "fooregion"
34+
name = "opsalerts"
35+
api_key = "fookey"
36+
region = "fooregion"
3737
priority = "foopriority"
3838
}
3939
}
@@ -50,10 +50,10 @@ resource "checkly_alert_channel" "pagerduty_ac" {
5050
# A Webhook alert channel
5151
resource "checkly_alert_channel" "webhook_ac" {
5252
webhook {
53-
name = "foo"
54-
method = "get"
55-
template = "footemplate"
56-
url = "https://example.com/foo"
53+
name = "foo"
54+
method = "get"
55+
template = "footemplate"
56+
url = "https://example.com/foo"
5757
webhook_secret = "foosecret"
5858
}
5959
}

examples/resources/checkly_check/resource.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ resource "checkly_check" "example_check_2" {
5252
}
5353

5454
retry_strategy {
55-
type = "FIXED"
55+
type = "FIXED"
5656
base_backoff_seconds = 60
5757
max_duration_seconds = 600
58-
max_retries = 3
59-
same_region = false
58+
max_retries = 3
59+
same_region = false
6060
}
6161

6262
request {

examples/resources/checkly_check_group/resource.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ resource "checkly_check_group" "test_group1" {
7272

7373
# Add a check to a group
7474
resource "checkly_check" "test_check1" {
75-
name = "My test check 1"
76-
type = "API"
77-
activated = true
78-
frequency = 1
75+
name = "My test check 1"
76+
type = "API"
77+
activated = true
78+
frequency = 1
7979

8080
locations = [
8181
"us-west-1"
8282
]
8383

8484
request {
85-
url = "https://api.example.com/"
85+
url = "https://api.example.com/"
8686
}
8787
group_id = checkly_check_group.test_group1.id
8888
group_order = 1
@@ -105,7 +105,7 @@ resource "checkly_alert_channel" "email_ac2" {
105105

106106
# Connect the check group to the alert channels
107107
resource "checkly_check_group" "test_group1" {
108-
name = "My test group 1"
108+
name = "My test group 1"
109109

110110
alert_channel_subscription {
111111
channel_id = checkly_alert_channel.email_ac1.id

0 commit comments

Comments
 (0)