@@ -67,9 +67,19 @@ func ResourceReport() *schema.Resource {
6767 Description : "Name of the report." ,
6868 },
6969 "dashboard_id" : {
70- Type : schema .TypeInt ,
71- Required : true ,
72- Description : "Dashboard to be sent in the report." ,
70+ Type : schema .TypeInt ,
71+ ExactlyOneOf : []string {"dashboard_id" , "dashboard_uid" },
72+ Computed : true ,
73+ Optional : true ,
74+ Deprecated : "Use dashboard_uid instead" ,
75+ Description : "Dashboard to be sent in the report. This field is deprecated, use `dashboard_uid` instead." ,
76+ },
77+ "dashboard_uid" : {
78+ Type : schema .TypeString ,
79+ ExactlyOneOf : []string {"dashboard_id" , "dashboard_uid" },
80+ Computed : true ,
81+ Optional : true ,
82+ Description : "Dashboard to be sent in the report." ,
7383 },
7484 "recipients" : {
7585 Type : schema .TypeList ,
@@ -217,7 +227,7 @@ func ResourceReport() *schema.Resource {
217227func CreateReport (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
218228 client := meta .(* client ).gapi
219229
220- report , err := schemaToReport (d )
230+ report , err := schemaToReport (client , d )
221231 if err != nil {
222232 return diag .FromErr (err )
223233 }
@@ -249,7 +259,8 @@ func ReadReport(ctx context.Context, d *schema.ResourceData, meta interface{}) d
249259 return diag .FromErr (err )
250260 }
251261
252- d .Set ("dashboard_id" , r .DashboardID )
262+ d .Set ("dashboard_id" , r .Dashboards [0 ].Dashboard .ID )
263+ d .Set ("dashboard_uid" , r .Dashboards [0 ].Dashboard .UID )
253264 d .Set ("name" , r .Name )
254265 d .Set ("recipients" , strings .Split (r .Recipients , "," ))
255266 d .Set ("reply_to" , r .ReplyTo )
@@ -259,11 +270,12 @@ func ReadReport(ctx context.Context, d *schema.ResourceData, meta interface{}) d
259270 d .Set ("layout" , r .Options .Layout )
260271 d .Set ("orientation" , r .Options .Orientation )
261272
262- if r .Options .TimeRange .From != "" {
273+ timeRange := r .Dashboards [0 ].TimeRange
274+ if timeRange .From != "" {
263275 d .Set ("time_range" , []interface {}{
264276 map [string ]interface {}{
265- "from" : r . Options . TimeRange .From ,
266- "to" : r . Options . TimeRange .To ,
277+ "from" : timeRange .From ,
278+ "to" : timeRange .To ,
267279 },
268280 })
269281 }
@@ -293,7 +305,7 @@ func ReadReport(ctx context.Context, d *schema.ResourceData, meta interface{}) d
293305func UpdateReport (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
294306 client := meta .(* client ).gapi
295307
296- report , err := schemaToReport (d )
308+ report , err := schemaToReport (client , d )
297309 if err != nil {
298310 return diag .FromErr (err )
299311 }
@@ -323,10 +335,34 @@ func DeleteReport(ctx context.Context, d *schema.ResourceData, meta interface{})
323335 return nil
324336}
325337
326- func schemaToReport (d * schema.ResourceData ) (gapi.Report , error ) {
338+ func schemaToReport (client * gapi.Client , d * schema.ResourceData ) (gapi.Report , error ) {
339+ id := int64 (d .Get ("dashboard_id" ).(int ))
340+ uid := d .Get ("dashboard_uid" ).(string )
341+ if uid == "" {
342+ dashboards , err := client .DashboardsByIDs ([]int64 {id })
343+ if err != nil {
344+ return gapi.Report {}, fmt .Errorf ("error getting dashboard %d: %v" , id , err )
345+ }
346+ for _ , dashboard := range dashboards {
347+ if int64 (dashboard .ID ) == id {
348+ uid = dashboard .UID
349+ break
350+ }
351+ }
352+ if uid == "" {
353+ return gapi.Report {}, fmt .Errorf ("dashboard %d not found" , id )
354+ }
355+ }
356+
327357 frequency := d .Get ("schedule.0.frequency" ).(string )
328358 report := gapi.Report {
329- DashboardID : int64 (d .Get ("dashboard_id" ).(int )),
359+ Dashboards : []gapi.ReportDashboard {
360+ {
361+ Dashboard : gapi.ReportDashboardIdentifier {
362+ UID : uid ,
363+ },
364+ },
365+ },
330366 Name : d .Get ("name" ).(string ),
331367 Recipients : strings .Join (listToStringSlice (d .Get ("recipients" ).([]interface {})), "," ),
332368 ReplyTo : d .Get ("reply_to" ).(string ),
@@ -347,7 +383,7 @@ func schemaToReport(d *schema.ResourceData) (gapi.Report, error) {
347383 timeRange := d .Get ("time_range" ).([]interface {})
348384 if len (timeRange ) > 0 {
349385 timeRange := timeRange [0 ].(map [string ]interface {})
350- report .Options .TimeRange = gapi.ReportTimeRange {From : timeRange ["from" ].(string ), To : timeRange ["to" ].(string )}
386+ report .Dashboards [ 0 ] .TimeRange = gapi.ReportDashboardTimeRange {From : timeRange ["from" ].(string ), To : timeRange ["to" ].(string )}
351387 }
352388
353389 // Set schedule start time
0 commit comments