Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update table widget definition and request #686

Merged
merged 9 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-10-12T09:17:33.888248+02:00
2020-10-15T14:21:31.028762-04:00
200 changes: 100 additions & 100 deletions datadog/cassettes/TestAccDatadogDashboardQueryTable.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-10-12T09:17:33.889361+02:00
2020-10-15T14:21:31.031775-04:00
248 changes: 124 additions & 124 deletions datadog/cassettes/TestAccDatadogDashboardQueryTable_import.yaml

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,10 @@ func getQueryTableDefinitionSchema() map[string]*schema.Schema {
Schema: getWidgetCustomLinkSchema(),
},
},
"has_search_bar": {
Type: schema.TypeString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a string enum ("always", "never", or "auto") – is there a way to specify an enum?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ok thanks. You could do something like set a ValidateFunc with stringInSlice - https://github.com/hashicorp/terraform/blob/master/helper/validation/validation.go#L32 but I think its OK to just document the allowed fields too.

Optional: true,
},
}
}
func buildDatadogQueryTableDefinition(terraformDefinition map[string]interface{}) *datadogV1.TableWidgetDefinition {
Expand All @@ -3379,6 +3383,9 @@ func buildDatadogQueryTableDefinition(terraformDefinition map[string]interface{}
if v, ok := terraformDefinition["custom_link"].([]interface{}); ok && len(v) > 0 {
datadogDefinition.SetCustomLinks(*buildDatadogWidgetCustomLinks(&v))
}
if v, ok := terraformDefinition["has_search_bar"].(string); ok && len(v) != 0 {
datadogDefinition.SetHasSearchBar(datadogV1.TableWidgetHasSearchBar(v))
}
return datadogDefinition
}
func buildTerraformQueryTableDefinition(datadogDefinition datadogV1.TableWidgetDefinition) map[string]interface{} {
Expand All @@ -3401,6 +3408,9 @@ func buildTerraformQueryTableDefinition(datadogDefinition datadogV1.TableWidgetD
if v, ok := datadogDefinition.GetCustomLinksOk(); ok {
terraformDefinition["custom_link"] = buildTerraformWidgetCustomLinks(v)
}
if v, ok := datadogDefinition.GetHasSearchBarOk(); ok {
terraformDefinition["has_search_bar"] = *v
}
return terraformDefinition
}

Expand Down Expand Up @@ -3438,6 +3448,11 @@ func getQueryTableRequestSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
},
"cell_display_mode": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
}
}
func buildDatadogQueryTableRequests(terraformRequests *[]interface{}) *[]datadogV1.TableWidgetRequest {
Expand Down Expand Up @@ -3484,6 +3499,13 @@ func buildDatadogQueryTableRequests(terraformRequests *[]interface{}) *[]datadog
if v, ok := terraformRequest["order"].(string); ok && len(v) != 0 {
datadogQueryTableRequest.SetOrder(datadogV1.WidgetSort(v))
}
if v, ok := terraformRequest["cell_display_mode"].([]interface{}); ok && len(v) != 0 {
datadogCellDisplayMode := make([]datadogV1.TableWidgetCellDisplayMode, len(v))
for i, cellDisplayMode := range v {
datadogCellDisplayMode[i] = datadogV1.TableWidgetCellDisplayMode(cellDisplayMode.(string))
}
datadogQueryTableRequest.CellDisplayMode = &datadogCellDisplayMode
}
datadogRequests[i] = *datadogQueryTableRequest
}
return &datadogRequests
Expand Down Expand Up @@ -3531,6 +3553,13 @@ func buildTerraformQueryTableRequests(datadogQueryTableRequests *[]datadogV1.Tab
if v, ok := datadogRequest.GetOrderOk(); ok {
terraformRequest["order"] = *v
}
if v, ok := datadogRequest.GetCellDisplayModeOk(); ok {
terraformCellDisplayMode := make([]datadogV1.TableWidgetCellDisplayMode, len(*v))
for i, cellDisplayMode := range *v {
terraformCellDisplayMode[i] = cellDisplayMode
}
terraformRequest["cell_display_mode"] = terraformCellDisplayMode
}
terraformRequests[i] = terraformRequest
}
return &terraformRequests
Expand Down
8 changes: 8 additions & 0 deletions datadog/resource_datadog_dashboard_query_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ resource "datadog_dashboard" "query_table_dashboard" {
alias = "cpu user"
limit = 25
order = "desc"
cell_display_mode = ["number"]
}
request {
q = "avg:system.load.1{*} by {service, team}"
Expand All @@ -118,11 +119,13 @@ resource "datadog_dashboard" "query_table_dashboard" {
comparator = ">"
}
alias = "system load"
cell_display_mode = ["number"]
}
custom_link {
link = "https://app.datadoghq.com/dashboard/lists"
label = "Test Custom Link label"
}
has_search_bar = "auto"
}
}

Expand All @@ -137,6 +140,7 @@ resource "datadog_dashboard" "query_table_dashboard" {
row_type = "resource"
}
}
has_search_bar = "never"
}
}
}
Expand Down Expand Up @@ -193,6 +197,10 @@ var datadogDashboardQueryTableAsserts = []string{
"widget.0.query_table_definition.0.custom_link.# = 1",
"widget.0.query_table_definition.0.custom_link.0.label = Test Custom Link label",
"widget.0.query_table_definition.0.custom_link.0.link = https://app.datadoghq.com/dashboard/lists",
"widget.0.query_table_definition.0.request.0.cell_display_mode.0 = number",
"widget.0.query_table_definition.0.request.1.cell_display_mode.0 = number",
"widget.0.query_table_definition.0.has_search_bar = auto",
"widget.1.query_table_definition.0.has_search_bar = never",
}

func TestAccDatadogDashboardQueryTable(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,13 @@ Nested `widget` blocks have the following structure:
- `aggregator`: (Optional) The aggregator to use for time aggregation. One of `avg`, `min`, `max`, `sum`, `last`.
- `limit`: (Required) The number of lines to show in the table.
- `order`: (Optional) The sort order for the rows. One of `desc` or `asc`.
- `cell_display_mode`: (Optional) A list of display modes for each table cell. List items one of "number", "bar".
- `title`: (Optional) The title of the widget.
- `title_size`: (Optional) The size of the widget's title. Default is 16.
- `title_align`: (Optional) The alignment of the widget's title. One of "left", "center", or "right".
- `time`: (Optional) Nested block describing the timeframe to use when displaying the widget. The structure of this block is described [below](dashboard.html#nested-widget-time-blocks).
- `custom_link`: (Optional) Nested block describing a custom link. The structure of this block is described [below](dashboard.html#nested-widget-custom_link-blocks).
- `has_search_bar`: (Optional) Controls the display of the search bar. One of "auto", "always", "never".
- `scatterplot_definition`: The definition for a Scatterplot widget. Exactly one nested block is allowed with the following structure:
- `request`: (Required) Nested block describing the request to use when displaying the widget. Exactly one request block is allowed with the following structure:
- `x`: (Optional) The query used for the X-Axis. Exactly one nested block is allowed with the following structure: - `q`: (Required) The metric query to use in the widget. - `aggregator`: (Optional) Aggregator used for the request. One of "avg", "min", "max", "sum", "last".
Expand Down