@@ -138,6 +138,19 @@ func resourceDashboard() *schema.Resource {
138
138
Default : false ,
139
139
Description : "Set when to use AND operator for fetching dashboard tags." ,
140
140
},
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
+ },
141
154
},
142
155
}
143
156
}
@@ -158,6 +171,7 @@ func dashboardFromResourceData(d *schema.ResourceData) (checkly.Dashboard, error
158
171
HideTags : d .Get ("hide_tags" ).(bool ),
159
172
Width : d .Get ("width" ).(string ),
160
173
UseTagsAndOperator : d .Get ("use_tags_and_operator" ).(bool ),
174
+ IsPrivate : d .Get ("is_private" ).(bool ),
161
175
Tags : stringsFromSet (d .Get ("tags" ).(* schema.Set )),
162
176
}
163
177
@@ -182,6 +196,19 @@ func resourceDataFromDashboard(s *checkly.Dashboard, d *schema.ResourceData) err
182
196
d .Set ("tags" , s .Tags )
183
197
d .Set ("width" , s .Width )
184
198
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
+
185
212
return nil
186
213
}
187
214
@@ -199,7 +226,10 @@ func resourceDashboardCreate(d *schema.ResourceData, client interface{}) error {
199
226
}
200
227
201
228
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 )
203
233
}
204
234
205
235
func resourceDashboardUpdate (d * schema.ResourceData , client interface {}) error {
@@ -214,7 +244,10 @@ func resourceDashboardUpdate(d *schema.ResourceData, client interface{}) error {
214
244
return fmt .Errorf ("resourceDashboardUpdate: API error: %w" , err )
215
245
}
216
246
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 )
218
251
}
219
252
220
253
func resourceDashboardDelete (d * schema.ResourceData , client interface {}) error {
0 commit comments