Skip to content

Commit ba48b60

Browse files
pilimartinezbenben
andauthored
feat: support private dashboard creation (#250)
* feat: support private dashboard creation * fix: add condition for private dashboards * 🥹 resource_dashboard.go: properly assign private dashboard keys * fix: move keys to string * fix: add new go version * docs: update docs with key as string --------- Co-authored-by: ben <[email protected]>
1 parent 919bf84 commit ba48b60

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

checkly/resource_dashboard.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ func resourceDashboard() *schema.Resource {
138138
Default: false,
139139
Description: "Set when to use AND operator for fetching dashboard tags.",
140140
},
141+
"is_private": {
142+
Type: schema.TypeBool,
143+
Optional: true,
144+
Default: false,
145+
Description: "Set your dashboard as private and generate key.",
146+
},
147+
// moving to TypeString here https://github.com/hashicorp/terraform-plugin-sdk/issues/792
148+
"key": {
149+
Type: schema.TypeString,
150+
Computed: true,
151+
Sensitive: true,
152+
Description: "The access key when the dashboard is private.",
153+
},
141154
},
142155
}
143156
}
@@ -158,6 +171,7 @@ func dashboardFromResourceData(d *schema.ResourceData) (checkly.Dashboard, error
158171
HideTags: d.Get("hide_tags").(bool),
159172
Width: d.Get("width").(string),
160173
UseTagsAndOperator: d.Get("use_tags_and_operator").(bool),
174+
IsPrivate: d.Get("is_private").(bool),
161175
Tags: stringsFromSet(d.Get("tags").(*schema.Set)),
162176
}
163177

@@ -182,6 +196,19 @@ func resourceDataFromDashboard(s *checkly.Dashboard, d *schema.ResourceData) err
182196
d.Set("tags", s.Tags)
183197
d.Set("width", s.Width)
184198
d.Set("use_tags_and_operator", s.UseTagsAndOperator)
199+
d.Set("is_private", s.IsPrivate)
200+
201+
// if the dashboard is private, we either do nothing
202+
// or set the key to a new value if there is any
203+
if s.IsPrivate {
204+
if len(s.Keys) > 0 {
205+
d.Set("key", s.Keys[0].RawKey)
206+
}
207+
} else {
208+
// if the dashboard is public, remove the key
209+
d.Set("key", nil)
210+
}
211+
185212
return nil
186213
}
187214

@@ -199,7 +226,10 @@ func resourceDashboardCreate(d *schema.ResourceData, client interface{}) error {
199226
}
200227

201228
d.SetId(result.DashboardID)
202-
return resourceDashboardRead(d, client)
229+
230+
// we cannot take the detour through resourceDashboardRead since
231+
// we would not get the keys back from an additional GET call
232+
return resourceDataFromDashboard(result, d)
203233
}
204234

205235
func resourceDashboardUpdate(d *schema.ResourceData, client interface{}) error {
@@ -214,7 +244,10 @@ func resourceDashboardUpdate(d *schema.ResourceData, client interface{}) error {
214244
return fmt.Errorf("resourceDashboardUpdate: API error: %w", err)
215245
}
216246
d.SetId(result.DashboardID)
217-
return resourceDashboardRead(d, client)
247+
248+
// we cannot take the detour through resourceDashboardRead since
249+
// we would not get the keys back from an additional GET call
250+
return resourceDataFromDashboard(result, d)
218251
}
219252

220253
func resourceDashboardDelete(d *schema.ResourceData, client interface{}) error {

docs/resources/dashboard.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ resource "checkly_dashboard" "dashboard_1" {
4444
- `favicon` (String) A URL pointing to an image file to use as browser favicon.
4545
- `header` (String) A piece of text displayed at the top of your dashboard.
4646
- `hide_tags` (Boolean) Show or hide the tags on the dashboard.
47+
- `is_private` (Boolean) Set your dashboard as private and generate key.
4748
- `link` (String) A link to for the dashboard logo.
4849
- `logo` (String) A URL pointing to an image file to use for the dashboard logo.
4950
- `paginate` (Boolean) Determines if pagination is on or off.
@@ -56,5 +57,6 @@ resource "checkly_dashboard" "dashboard_1" {
5657
### Read-Only
5758

5859
- `id` (String) The ID of this resource.
60+
- `key` (String, Sensitive) The access key when the dashboard is private.
5961

6062

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/aws/aws-sdk-go v1.44.122 // indirect
7-
github.com/checkly/checkly-go-sdk v1.6.3
7+
github.com/checkly/checkly-go-sdk v1.6.4
88
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
99
github.com/google/go-cmp v0.5.9
1010
github.com/gruntwork-io/terratest v0.41.16

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
231231
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
232232
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
233233
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
234-
github.com/checkly/checkly-go-sdk v1.6.3 h1:+9PongdPyORBmUbzBpwZBCANEr7og/RTnnt9gHhoamk=
235-
github.com/checkly/checkly-go-sdk v1.6.3/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
234+
github.com/checkly/checkly-go-sdk v1.6.4 h1:tV/iT9dLRP1yWJyYO9YayHtXVTujyc8/nfYOfW8lfGU=
235+
github.com/checkly/checkly-go-sdk v1.6.4/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
236236
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
237237
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
238238
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=

0 commit comments

Comments
 (0)