@@ -2,6 +2,7 @@ package datadog
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "log"
78 "net/http"
@@ -4522,6 +4523,83 @@ func getQueryTableRequestSchema() map[string]*schema.Schema {
45224523 ValidateDiagFunc : validators .ValidateEnumValue (datadogV1 .NewWidgetSortFromValue ),
45234524 Optional : true ,
45244525 },
4526+ "sort" : {
4527+ Description : "The controls for sorting the widget" ,
4528+ Type : schema .TypeList ,
4529+ Optional : true ,
4530+ MaxItems : 1 ,
4531+ Elem : & schema.Resource {
4532+ Schema : map [string ]* schema.Schema {
4533+ "count" : {
4534+ Description : "The number of items to limit the widget to" ,
4535+ Type : schema .TypeInt ,
4536+ Required : true ,
4537+ },
4538+ "order_by" : {
4539+ Description : "The array of items to sort the widget by in order" ,
4540+ Type : schema .TypeList ,
4541+ Required : true ,
4542+ MinItems : 1 ,
4543+ MaxItems : 1 ,
4544+ Elem : & schema.Resource {
4545+ Schema : map [string ]* schema.Schema {
4546+ "type" : {
4547+ Description : "Sort type. Allowed enum values: formula, group" ,
4548+ Type : schema .TypeString ,
4549+ Required : true ,
4550+ ValidateFunc : validation .StringInSlice ([]string {
4551+ "formula" , "group" ,
4552+ }, false ),
4553+ },
4554+ "name" : {
4555+ Description : "The name of the group" ,
4556+ Type : schema .TypeString ,
4557+ Optional : true ,
4558+ },
4559+ "index" : {
4560+ Description : "The index of the formula to sort by" ,
4561+ Type : schema .TypeInt ,
4562+ Optional : true ,
4563+ },
4564+ "order" : {
4565+ Description : "Widget sorting methods. Allowed enum values: asc, desc" ,
4566+ Type : schema .TypeString ,
4567+ Required : true ,
4568+ ValidateFunc : validation .StringInSlice ([]string {
4569+ "asc" , "desc" ,
4570+ }, false ),
4571+ },
4572+ },
4573+ CustomizeDiff : func (ctx context.Context , diff * schema.ResourceDiff , i interface {}) error {
4574+ // type as discriminator field validation
4575+ typeVal := diff .Get ("type" ).(string )
4576+ nameVal := diff .Get ("name" ).(* string )
4577+ indexVal := diff .Get ("index" ).(* int )
4578+
4579+ if typeVal == "formula" {
4580+ if indexVal == nil {
4581+ return errors .New ("index is required for type formula" )
4582+ }
4583+ if nameVal != nil {
4584+ return errors .New ("name should not be set for type formula" )
4585+ }
4586+ return nil
4587+ } else if typeVal == "group" {
4588+ if nameVal == nil {
4589+ return errors .New ("name is required for type group" )
4590+ }
4591+ if indexVal != nil {
4592+ return errors .New ("index should not be set for type group" )
4593+ }
4594+ return nil
4595+ }
4596+ return errors .New ("type should be set to either formula or group" )
4597+ },
4598+ },
4599+ },
4600+ },
4601+ },
4602+ },
45254603 "cell_display_mode" : {
45264604 Description : "A list of display modes for each table cell." ,
45274605 Type : schema .TypeList ,
0 commit comments