Skip to content

Commit a284989

Browse files
authored
* fix: turn alert settings into type list and computed to stop showings diffs each time
1 parent aec6a22 commit a284989

File tree

3 files changed

+57
-45
lines changed

3 files changed

+57
-45
lines changed

checkly/resource_check.go

+29-25
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func resourceCheck() *schema.Resource {
231231
Description: "An array of one or more private locations slugs.",
232232
},
233233
"alert_settings": {
234-
Type: schema.TypeSet,
234+
Type: schema.TypeList,
235235
Optional: true,
236236
Computed: true,
237237
MaxItems: 1,
@@ -243,8 +243,9 @@ func resourceCheck() *schema.Resource {
243243
Description: "Determines what type of escalation to use. Possible values are `RUN_BASED` or `TIME_BASED`.",
244244
},
245245
"run_based_escalation": {
246-
Type: schema.TypeSet,
246+
Type: schema.TypeList,
247247
Optional: true,
248+
Computed: true,
248249
Elem: &schema.Resource{
249250
Schema: map[string]*schema.Schema{
250251
"failed_run_threshold": {
@@ -256,8 +257,9 @@ func resourceCheck() *schema.Resource {
256257
},
257258
},
258259
"time_based_escalation": {
259-
Type: schema.TypeSet,
260+
Type: schema.TypeList,
260261
Optional: true,
262+
Computed: true,
261263
Elem: &schema.Resource{
262264
Schema: map[string]*schema.Schema{
263265
"minutes_failing_threshold": {
@@ -269,8 +271,9 @@ func resourceCheck() *schema.Resource {
269271
},
270272
},
271273
"reminders": {
272-
Type: schema.TypeSet,
274+
Type: schema.TypeList,
273275
Optional: true,
276+
Computed: true,
274277
Elem: &schema.Resource{
275278
Schema: map[string]*schema.Schema{
276279
"amount": {
@@ -288,8 +291,9 @@ func resourceCheck() *schema.Resource {
288291
},
289292
},
290293
"parallel_run_failure_threshold": {
291-
Type: schema.TypeSet,
294+
Type: schema.TypeList,
292295
Optional: true,
296+
Computed: true,
293297
Elem: &schema.Resource{
294298
Schema: map[string]*schema.Schema{
295299
"enabled": {
@@ -799,7 +803,7 @@ func checkFromResourceData(d *schema.ResourceData) (checkly.Check, error) {
799803
TearDownSnippetID: int64(d.Get("teardown_snippet_id").(int)),
800804
LocalSetupScript: d.Get("local_setup_script").(string),
801805
LocalTearDownScript: d.Get("local_teardown_script").(string),
802-
AlertSettings: alertSettingsFromSet(d.Get("alert_settings").(*schema.Set)),
806+
AlertSettings: alertSettingsFromSet(d.Get("alert_settings").([]interface{})),
803807
UseGlobalAlertSettings: d.Get("use_global_alert_settings").(bool),
804808
GroupID: int64(d.Get("group_id").(int)),
805809
GroupOrder: d.Get("group_order").(int),
@@ -877,26 +881,26 @@ func basicAuthFromSet(s *schema.Set) *checkly.BasicAuth {
877881
}
878882
}
879883

880-
func alertSettingsFromSet(s *schema.Set) checkly.AlertSettings {
881-
if s.Len() == 0 {
884+
func alertSettingsFromSet(s []interface{}) checkly.AlertSettings {
885+
if len(s) == 0 {
882886
return checkly.AlertSettings{
883887
EscalationType: checkly.RunBased,
884888
RunBasedEscalation: checkly.RunBasedEscalation{
885889
FailedRunThreshold: 1,
886890
},
887891
}
888892
}
889-
res := s.List()[0].(tfMap)
893+
res := s[0].(tfMap)
890894
alertSettings := checkly.AlertSettings{
891895
EscalationType: res["escalation_type"].(string),
892-
Reminders: remindersFromSet(res["reminders"].(*schema.Set)),
893-
ParallelRunFailureThreshold: parallelRunFailureThresholdFromSet(res["parallel_run_failure_threshold"].(*schema.Set)),
896+
Reminders: remindersFromSet(res["reminders"].([]interface{})),
897+
ParallelRunFailureThreshold: parallelRunFailureThresholdFromSet(res["parallel_run_failure_threshold"].([]interface{})),
894898
}
895899

896900
if alertSettings.EscalationType == checkly.RunBased {
897-
alertSettings.RunBasedEscalation = runBasedEscalationFromSet(res["run_based_escalation"].(*schema.Set))
901+
alertSettings.RunBasedEscalation = runBasedEscalationFromSet(res["run_based_escalation"].([]interface{}))
898902
} else {
899-
alertSettings.TimeBasedEscalation = timeBasedEscalationFromSet(res["time_based_escalation"].(*schema.Set))
903+
alertSettings.TimeBasedEscalation = timeBasedEscalationFromSet(res["time_based_escalation"].([]interface{}))
900904
}
901905

902906
return alertSettings
@@ -953,42 +957,42 @@ func environmentVariablesFromSet(s []interface{}) []checkly.EnvironmentVariable
953957
return res
954958
}
955959

956-
func runBasedEscalationFromSet(s *schema.Set) checkly.RunBasedEscalation {
957-
if s.Len() == 0 {
960+
func runBasedEscalationFromSet(s []interface{}) checkly.RunBasedEscalation {
961+
if len(s) == 0 {
958962
return checkly.RunBasedEscalation{}
959963
}
960-
res := s.List()[0].(tfMap)
964+
res := s[0].(tfMap)
961965
return checkly.RunBasedEscalation{
962966
FailedRunThreshold: res["failed_run_threshold"].(int),
963967
}
964968
}
965969

966-
func timeBasedEscalationFromSet(s *schema.Set) checkly.TimeBasedEscalation {
967-
if s.Len() == 0 {
970+
func timeBasedEscalationFromSet(s []interface{}) checkly.TimeBasedEscalation {
971+
if len(s) == 0 {
968972
return checkly.TimeBasedEscalation{}
969973
}
970-
res := s.List()[0].(tfMap)
974+
res := s[0].(tfMap)
971975
return checkly.TimeBasedEscalation{
972976
MinutesFailingThreshold: res["minutes_failing_threshold"].(int),
973977
}
974978
}
975979

976-
func remindersFromSet(s *schema.Set) checkly.Reminders {
977-
if s.Len() == 0 {
980+
func remindersFromSet(s []interface{}) checkly.Reminders {
981+
if len(s) == 0 {
978982
return checkly.Reminders{}
979983
}
980-
res := s.List()[0].(tfMap)
984+
res := s[0].(tfMap)
981985
return checkly.Reminders{
982986
Amount: res["amount"].(int),
983987
Interval: res["interval"].(int),
984988
}
985989
}
986990

987-
func parallelRunFailureThresholdFromSet(s *schema.Set) checkly.ParallelRunFailureThreshold {
988-
if s.Len() == 0 {
991+
func parallelRunFailureThresholdFromSet(s []interface{}) checkly.ParallelRunFailureThreshold {
992+
if len(s) == 0 {
989993
return checkly.ParallelRunFailureThreshold{}
990994
}
991-
res := s.List()[0].(tfMap)
995+
res := s[0].(tfMap)
992996
return checkly.ParallelRunFailureThreshold{
993997
Enabled: res["enabled"].(bool),
994998
Percentage: res["percentage"].(int),

checkly/resource_check_group.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func resourceCheckGroup() *schema.Resource {
9999
Type: schema.TypeBool,
100100
Optional: true,
101101
Description: "Setting this to `true` will trigger a retry when a check fails from the failing region and another, randomly selected region before marking the check as failed.",
102-
Deprecated: "The property `double_check` is deprecated and will be removed in a future version. To enable retries for failed check runs, use the `retry_strategy` property instead.",
102+
Deprecated: "The property `double_check` is deprecated and will be removed in a future version. To enable retries for failed check runs, use the `retry_strategy` property instead.",
103103
},
104104
"tags": {
105105
Type: schema.TypeSet,
@@ -152,7 +152,7 @@ func resourceCheckGroup() *schema.Resource {
152152
},
153153
},
154154
"alert_settings": {
155-
Type: schema.TypeSet,
155+
Type: schema.TypeList,
156156
Optional: true,
157157
Computed: true,
158158
MaxItems: 1,
@@ -165,8 +165,9 @@ func resourceCheckGroup() *schema.Resource {
165165
Description: "Determines what type of escalation to use. Possible values are `RUN_BASED` or `TIME_BASED`.",
166166
},
167167
"run_based_escalation": {
168-
Type: schema.TypeSet,
168+
Type: schema.TypeList,
169169
Optional: true,
170+
Computed: true,
170171
Elem: &schema.Resource{
171172
Schema: map[string]*schema.Schema{
172173
"failed_run_threshold": {
@@ -178,8 +179,9 @@ func resourceCheckGroup() *schema.Resource {
178179
},
179180
},
180181
"time_based_escalation": {
181-
Type: schema.TypeSet,
182+
Type: schema.TypeList,
182183
Optional: true,
184+
Computed: true,
183185
Elem: &schema.Resource{
184186
Schema: map[string]*schema.Schema{
185187
"minutes_failing_threshold": {
@@ -191,8 +193,9 @@ func resourceCheckGroup() *schema.Resource {
191193
},
192194
},
193195
"reminders": {
194-
Type: schema.TypeSet,
196+
Type: schema.TypeList,
195197
Optional: true,
198+
Computed: true,
196199
Elem: &schema.Resource{
197200
Schema: map[string]*schema.Schema{
198201
"amount": {
@@ -210,8 +213,9 @@ func resourceCheckGroup() *schema.Resource {
210213
},
211214
},
212215
"parallel_run_failure_threshold": {
213-
Type: schema.TypeSet,
216+
Type: schema.TypeList,
214217
Optional: true,
218+
Computed: true,
215219
Elem: &schema.Resource{
216220
Schema: map[string]*schema.Schema{
217221
"enabled": {
@@ -534,7 +538,7 @@ func checkGroupFromResourceData(d *schema.ResourceData) (checkly.Group, error) {
534538
TearDownSnippetID: int64(d.Get("teardown_snippet_id").(int)),
535539
LocalSetupScript: d.Get("local_setup_script").(string),
536540
LocalTearDownScript: d.Get("local_teardown_script").(string),
537-
AlertSettings: alertSettingsFromSet(d.Get("alert_settings").(*schema.Set)),
541+
AlertSettings: alertSettingsFromSet(d.Get("alert_settings").([]interface{})),
538542
UseGlobalAlertSettings: d.Get("use_global_alert_settings").(bool),
539543
APICheckDefaults: apiCheckDefaultsFromSet(d.Get("api_check_defaults").(*schema.Set)),
540544
AlertChannelSubscriptions: alertChannelSubscriptionsFromSet(d.Get("alert_channel_subscription").([]interface{})),

checkly/resource_heartbeat.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func resourceHeartbeat() *schema.Resource {
4949
Description: "A list of tags for organizing and filtering checks.",
5050
},
5151
"alert_settings": {
52-
Type: schema.TypeSet,
52+
Type: schema.TypeList,
5353
Optional: true,
5454
Computed: true,
5555
MaxItems: 1,
@@ -61,8 +61,9 @@ func resourceHeartbeat() *schema.Resource {
6161
Description: "Determines what type of escalation to use. Possible values are `RUN_BASED` or `TIME_BASED`.",
6262
},
6363
"run_based_escalation": {
64-
Type: schema.TypeSet,
64+
Type: schema.TypeList,
6565
Optional: true,
66+
Computed: true,
6667
Elem: &schema.Resource{
6768
Schema: map[string]*schema.Schema{
6869
"failed_run_threshold": {
@@ -74,8 +75,9 @@ func resourceHeartbeat() *schema.Resource {
7475
},
7576
},
7677
"time_based_escalation": {
77-
Type: schema.TypeSet,
78+
Type: schema.TypeList,
7879
Optional: true,
80+
Computed: true,
7981
Elem: &schema.Resource{
8082
Schema: map[string]*schema.Schema{
8183
"minutes_failing_threshold": {
@@ -87,8 +89,9 @@ func resourceHeartbeat() *schema.Resource {
8789
},
8890
},
8991
"reminders": {
90-
Type: schema.TypeSet,
92+
Type: schema.TypeList,
9193
Optional: true,
94+
Computed: true,
9295
Elem: &schema.Resource{
9396
Schema: map[string]*schema.Schema{
9497
"amount": {
@@ -106,8 +109,9 @@ func resourceHeartbeat() *schema.Resource {
106109
},
107110
},
108111
"parallel_run_failure_threshold": {
109-
Type: schema.TypeSet,
112+
Type: schema.TypeList,
110113
Optional: true,
114+
Computed: true,
111115
Elem: &schema.Resource{
112116
Schema: map[string]*schema.Schema{
113117
"enabled": {
@@ -174,8 +178,8 @@ func resourceHeartbeat() *schema.Resource {
174178
Elem: &schema.Resource{
175179
Schema: map[string]*schema.Schema{
176180
"period": {
177-
Type: schema.TypeInt,
178-
Required: true,
181+
Type: schema.TypeInt,
182+
Required: true,
179183
Description: "How often you expect a ping to the ping URL.",
180184
},
181185
"period_unit": {
@@ -198,8 +202,8 @@ func resourceHeartbeat() *schema.Resource {
198202
Description: "Possible values `seconds`, `minutes`, `hours` and `days`.",
199203
},
200204
"grace": {
201-
Type: schema.TypeInt,
202-
Required: true,
205+
Type: schema.TypeInt,
206+
Required: true,
203207
Description: "How long Checkly should wait before triggering any alerts when a ping does not arrive within the set period.",
204208
},
205209
"grace_unit": {
@@ -222,9 +226,9 @@ func resourceHeartbeat() *schema.Resource {
222226
Description: "Possible values `seconds`, `minutes`, `hours` and `days`.",
223227
},
224228
"ping_token": {
225-
Type: schema.TypeString,
226-
Optional: true,
227-
Computed: true,
229+
Type: schema.TypeString,
230+
Optional: true,
231+
Computed: true,
228232
Description: "Custom token to generate your ping URL. Checkly will expect a ping to `https://ping.checklyhq.com/[PING_TOKEN]`.",
229233
},
230234
},
@@ -317,7 +321,7 @@ func heartbeatCheckFromResourceData(d *schema.ResourceData) (checkly.HeartbeatCh
317321
Activated: d.Get("activated").(bool),
318322
Muted: d.Get("muted").(bool),
319323
Tags: stringsFromSet(d.Get("tags").(*schema.Set)),
320-
AlertSettings: alertSettingsFromSet(d.Get("alert_settings").(*schema.Set)),
324+
AlertSettings: alertSettingsFromSet(d.Get("alert_settings").([]interface{})),
321325
UseGlobalAlertSettings: d.Get("use_global_alert_settings").(bool),
322326
AlertChannelSubscriptions: alertChannelSubscriptionsFromSet(d.Get("alert_channel_subscription").([]interface{})),
323327
}

0 commit comments

Comments
 (0)