Skip to content

Commit 4dbee2a

Browse files
pilimartinezNacho Anaya
and
Nacho Anaya
authored
feat: add private locations assignment to checks/groups (#168)
* add private location assignment to groups issue-164 * feat: add support for private locations assignment on checks/groups * refactor: use default sets for private locations * chore: bump go sdk version * test: add private locations to check/test groups Co-authored-by: Nacho Anaya <[email protected]>
1 parent 8ec33d2 commit 4dbee2a

8 files changed

+51
-9
lines changed

checkly/resource_check.go

+15
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ func resourceCheck() *schema.Resource {
185185
},
186186
},
187187
},
188+
"private_locations": {
189+
Type: schema.TypeSet,
190+
Optional: true,
191+
Elem: &schema.Schema{
192+
Type: schema.TypeString,
193+
},
194+
DefaultFunc: func() (interface{}, error) {
195+
return []tfMap{}, nil
196+
},
197+
Description: "An array of one or more private locations slugs.",
198+
},
188199
"alert_settings": {
189200
Type: schema.TypeSet,
190201
Optional: true,
@@ -505,6 +516,7 @@ func resourceDataFromCheck(c *checkly.Check, d *schema.ResourceData) error {
505516
}
506517
d.Set("group_id", c.GroupID)
507518
d.Set("group_order", c.GroupOrder)
519+
d.Set("private_locations", c.PrivateLocations)
508520
d.Set("alert_channel_subscription", c.AlertChannelSubscriptions)
509521
d.SetId(d.Id())
510522
return nil
@@ -631,6 +643,9 @@ func checkFromResourceData(d *schema.ResourceData) (checkly.Check, error) {
631643
check.RuntimeID = &runtimeId
632644
}
633645

646+
privateLocations := stringsFromSet(d.Get("private_locations").(*schema.Set))
647+
check.PrivateLocations = &privateLocations
648+
634649
if check.Type == checkly.TypeAPI {
635650
// this will prevent subsequent apply from causing a tf config change in browser checks
636651
check.Request = requestFromSet(d.Get("request").(*schema.Set))

checkly/resource_check_group.go

+23
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ func resourceCheckGroup() *schema.Resource {
5151
},
5252
Description: "An array of one or more data center locations where to run the checks.",
5353
},
54+
"private_locations": {
55+
Type: schema.TypeSet,
56+
Required: true,
57+
Elem: &schema.Schema{
58+
Type: schema.TypeString,
59+
},
60+
DefaultFunc: func() (interface{}, error) {
61+
return []tfMap{}, nil
62+
},
63+
Description: "An array of one or more private locations slugs.",
64+
},
5465
"environment_variables": {
5566
Type: schema.TypeMap,
5667
Optional: true,
@@ -395,6 +406,7 @@ func resourceDataFromCheckGroup(g *checkly.Group, d *schema.ResourceData) error
395406
return fmt.Errorf("error setting request for resource %s: %s", d.Id(), err)
396407
}
397408
d.Set("alert_channel_subscription", g.AlertChannelSubscriptions)
409+
d.Set("private_locations", g.PrivateLocations)
398410
d.SetId(d.Id())
399411
return nil
400412
}
@@ -434,9 +446,20 @@ func checkGroupFromResourceData(d *schema.ResourceData) (checkly.Group, error) {
434446
group.RuntimeID = &runtimeId
435447
}
436448

449+
privateLocations := stringsFromSet(d.Get("private_locations").(*schema.Set))
450+
group.PrivateLocations = &privateLocations
451+
437452
return group, nil
438453
}
439454

455+
func stringsFromSet2(set *schema.Set) []string {
456+
r := make([]string, set.Len())
457+
for i, item := range set.List() {
458+
r[i] = item.(string)
459+
}
460+
return r
461+
}
462+
440463
func setFromAPICheckDefaults(a checkly.APICheckDefaults) []tfMap {
441464
s := tfMap{}
442465
s["url"] = a.BaseURL

checkly/resource_check_group_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ func TestEncodeDecodeGroupResource(t *testing.T) {
2424
}
2525

2626
var wantGroup = checkly.Group{
27-
Name: "test",
28-
Activated: true,
29-
Muted: false,
30-
Tags: []string{"auto"},
31-
Locations: []string{"eu-west-1"},
32-
Concurrency: 3,
27+
Name: "test",
28+
Activated: true,
29+
Muted: false,
30+
Tags: []string{"auto"},
31+
Locations: []string{"eu-west-1"},
32+
PrivateLocations: &[]string{},
33+
Concurrency: 3,
3334
APICheckDefaults: checkly.APICheckDefaults{
3435
BaseURL: "example.com/api/test",
3536
Headers: []checkly.KeyValue{

checkly/resource_check_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ var wantCheck = checkly.Check{
344344
Muted: false,
345345
ShouldFail: false,
346346
Locations: []string{"eu-west-1"},
347+
PrivateLocations: &[]string{},
347348
Script: "foo",
348349
DegradedResponseTime: 15000,
349350
MaxResponseTime: 30000,

docs/resources/check.md

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ resource "checkly_check" "example-check" {
207207
- `frequency_offset` (Number) This property only valid for API high frequency checks. To create a hight frequency check, the property `frequency` must be `0` and `frequency_offset` could be `10`, `20` or `30`.
208208
- `group_id` (Number) The id of the check group this check is part of.
209209
- `group_order` (Number) The position of this check in a check group. It determines in what order checks are run when a group is triggered from the API or from CI/CD.
210+
- `private_locations` (Set of String) Private locations assigned to the check.
210211
- `id` (String) The ID of this resource.
211212
- `local_setup_script` (String) A valid piece of Node.js code to run in the setup phase.
212213
- `local_teardown_script` (String) A valid piece of Node.js code to run in the teardown phase.

docs/resources/check_group.md

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ resource "checkly_check_group" "test-group1" {
145145
- `tags` (Set of String) Tags for organizing and filtering checks.
146146
- `teardown_snippet_id` (Number) An ID reference to a snippet to use in the teardown phase of an API check.
147147
- `use_global_alert_settings` (Boolean) When true, the account level alert settings will be used, not the alert setting defined on this check group.
148+
- `private_locations` (Set of String) Private locations assigned to the group.
148149

149150
<a id="nestedblock--alert_channel_subscription"></a>
150151
### Nested Schema for `alert_channel_subscription`

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/aws/aws-sdk-go v1.42.35 // indirect
7-
github.com/checkly/checkly-go-sdk v1.6.0
7+
github.com/checkly/checkly-go-sdk v1.6.1
88
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
99
github.com/google/go-cmp v0.5.8
1010
github.com/gruntwork-io/terratest v0.40.17

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3k
149149
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
150150
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
151151
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
152-
github.com/checkly/checkly-go-sdk v1.6.0 h1:KkHf+lR1W21/HQah48rPzBUdJ2EoGzvPV1rdG1MHVYY=
153-
github.com/checkly/checkly-go-sdk v1.6.0/go.mod h1:a1I5B287Fd06TL1C+V/9szb3ZU4+0Di100Zn8h+CDgg=
152+
github.com/checkly/checkly-go-sdk v1.6.1 h1:R504wAr5hjqYCnEiU25UOW9v5l7N9cMF6izbmg36uA4=
153+
github.com/checkly/checkly-go-sdk v1.6.1/go.mod h1:a1I5B287Fd06TL1C+V/9szb3ZU4+0Di100Zn8h+CDgg=
154154
github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw=
155155
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
156156
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=

0 commit comments

Comments
 (0)