From 8ecf3f044d08cebeddc7ffa70b959575fbf8c75d Mon Sep 17 00:00:00 2001 From: Vinay Reddy Godhala Date: Mon, 23 Sep 2024 16:30:10 +0530 Subject: [PATCH] feat(dashboard): adress review comments-adding support for data format to newrelic_one_dashboard resource in terraform --- newrelic/resource_newrelic_one_dashboard.go | 7 ++- newrelic/structures_newrelic_one_dashboard.go | 1 - website/docs/r/one_dashboard.html.markdown | 47 ++++++++++++++++--- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/newrelic/resource_newrelic_one_dashboard.go b/newrelic/resource_newrelic_one_dashboard.go index d9961cf84..926d89a7c 100644 --- a/newrelic/resource_newrelic_one_dashboard.go +++ b/newrelic/resource_newrelic_one_dashboard.go @@ -489,10 +489,9 @@ func dashboardWidgetDataFormatSchemaElem() *schema.Resource { Description: "The column name to be sorted", }, "type": { - Type: schema.TypeString, - Required: true, - Description: "Defines the type of the mentioned column", - ValidateFunc: validation.StringInSlice([]string{"decimal", "date", "duration", "recent-relative", "custom", "humanized"}, true), + Type: schema.TypeString, + Required: true, + Description: "Defines the type of the mentioned column", }, "format": { Type: schema.TypeString, diff --git a/newrelic/structures_newrelic_one_dashboard.go b/newrelic/structures_newrelic_one_dashboard.go index 43c5fbfa1..9c02a266f 100644 --- a/newrelic/structures_newrelic_one_dashboard.go +++ b/newrelic/structures_newrelic_one_dashboard.go @@ -1812,7 +1812,6 @@ func validateWidgetDataFormatterStructure(d *schema.ResourceDiff, errorsList *[] *errorsList = append(*errorsList, fmt.Sprintf("'format' should not be provided if 'type' has the value %s", dataFormat["type"])) } } - fmt.Printf("i am inside dataFormatsOk %v\n", dataFormat["precision"]) if dataFormat["type"] != nil && dataFormat["precision"] != 0 { if dataFormat["precision"] != "" && slices.Contains(acceptedTypes, dataFormat["type"].(string)) { *errorsList = append(*errorsList, fmt.Sprintf("'precision' should not be provided if 'type' has the value %s", dataFormat["type"])) diff --git a/website/docs/r/one_dashboard.html.markdown b/website/docs/r/one_dashboard.html.markdown index 012800209..550b30fda 100644 --- a/website/docs/r/one_dashboard.html.markdown +++ b/website/docs/r/one_dashboard.html.markdown @@ -373,11 +373,18 @@ Each widget type supports an additional set of arguments: ### Nested `data_format` blocks -Nested `data_format` specifies the data structure format in the table. It defines how the data is organized and interpreted.This attribute requires specifying the following attributes in a nested block - +Nested `data_format` blocks help specify the format of data displayed by a widget per attribute in the data returned by the NRQL query rendering the widget; thereby defining how the data fetched is best interpreted. This is supported for **billboards** and **tables**, as these are the only widgets in dashboards which return single or multi-faceted data that may be formatted based on the type of data returned. +This attribute requires specifying the following attributes in a nested block - * `name` - (Required) This attribute mandates the specification of the column name to be formatted. It identifies which column the data format should be applied to. - * `type` - (Required) This attribute sets the format category for your data. Accepted values include `decimal` for numeric values, `date` for date/time values, `duration` for length of time, `recent-relative` for values referencing a relative point in time, `custom` for specific date/time formats and `humanized` to set autoformat as true. - * `format` - (Optional) This attribute is provided when the `type` attribute is set to `date`, defining the specific date format to be applied to your data. + * `type` - (Required) This attribute sets the format category for your data. Accepted values include - + - `decimal` for numeric values + - `date` for date/time values + - `duration` for length of time + - `recent-relative` for values referencing a relative point in time + - `custom` to be used with date/time values, in order to select a specific format the date/time value would need to be rendered as + - `humanized` to be used with numeric values, in order to enable Autoformat + * `format` - (Optional) This attribute is provided when the `name` is that of a column comprising date/time values and the `type` attribute is set to `custom` defining the specific date format to be applied to your data. | Accepted value | Format | |---------------------|-------------------------| @@ -391,10 +398,11 @@ Nested `data_format` specifies the data structure format in the table. It define | `%b %d, %Y, %X` | `MMM DD, YYYY,hh:mm:ss` | | `%X` | `hh:mm:ss` | --> **IMPORTANT!** - `type` should be set to `custom` inorder to use the formats listed above. * `precision` - (Optional) This attribute is utilized when the `type` attribute is set to `decimal`, stipulating the precise number of digits after the decimal point for your data. +-> **IMPORTANT!** + Refer below code snippets to identify the correct set of combinations. + ```hcl widget_table { title = "List of Transactions" @@ -409,8 +417,8 @@ Nested `data_format` specifies the data structure format in the table. It define } data_format { - name = "Avg duration" - type = "date" + name = "Max duration" + Type = "duration" } data_format { @@ -424,6 +432,31 @@ Nested `data_format` specifies the data structure format in the table. It define } } ``` +* `type` should be set to `date` for default date/time values and `custom` inorder to use the formats listed above. +```hcl + data_format { + name = "timestamp" + Type = "date" + } + + data_format { + name = "timestamp" + Type = "custom" + Format = "%Y-%m-%dT%X.%L%Z" + } +``` +* `type` should be set to `decimal` for numeric values and `humanized` in order to enable Autoformat for numeric values. +```hcl + data_format { + name = "count" + type = "decimal" + Precision = 4 + } + data_format { + name = "count" + type = "humanized" + } +``` ### Nested `nrql_query` blocks