Skip to content

Commit

Permalink
feat(dashboards): Adds excluded to options in variable in `newr…
Browse files Browse the repository at this point in the history
…elic_one_dashboard` (#2756)
  • Loading branch information
shashank-reddy-nr authored Oct 28, 2024
1 parent fe5b505 commit 4c1e489
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/go-agent/v3 v3.30.0
github.com/newrelic/go-insights v1.0.3
github.com/newrelic/newrelic-client-go/v2 v2.47.0
github.com/newrelic/newrelic-client-go/v2 v2.50.0
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ github.com/newrelic/go-agent/v3 v3.30.0 h1:ZXHCT/Cot4iIPwcegCZURuRQOsfmGA6wilW+S
github.com/newrelic/go-agent/v3 v3.30.0/go.mod h1:9utrgxlSryNqRrTvII2XBL+0lpofXbqXApvVWPpbzUg=
github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ=
github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4=
github.com/newrelic/newrelic-client-go/v2 v2.47.0 h1:4+Q4ynp1lHm2t8OopQ6lmac+dJD0E3AvbHQAuSW7+ws=
github.com/newrelic/newrelic-client-go/v2 v2.47.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4=
github.com/newrelic/newrelic-client-go/v2 v2.50.0 h1:rnaNyTzK2RsSgbIDzReQCkmgkKl1lwIF5c+MZuIKFnA=
github.com/newrelic/newrelic-client-go/v2 v2.50.0/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down
6 changes: 6 additions & 0 deletions newrelic/resource_newrelic_one_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func dashboardVariableSchemaElem() *schema.Resource {
Optional: true,
Description: "Only applies to variables of type NRQL. With this turned on, the time range for the NRQL query will override the time picker on dashboards and other pages. Turn this off to use the time picker as normal.",
},
"excluded": {
Type: schema.TypeBool,
Optional: true,
Description: "Only applies to variables of type NRQL. With this turned on, query condition defined with the variable will not be included in the query.",
},
},
},
},
Expand Down Expand Up @@ -890,6 +895,7 @@ func resourceNewRelicOneDashboardRead(ctx context.Context, d *schema.ResourceDat
log.Printf("[INFO] Reading New Relic One dashboard %s", d.Id())

dashboard, err := client.Dashboards.GetDashboardEntityWithContext(ctx, common.EntityGUID(d.Id()))

if err != nil {
if _, ok := err.(*errors.NotFound); ok {
d.SetId("")
Expand Down
11 changes: 11 additions & 0 deletions newrelic/resource_newrelic_one_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ func TestAccNewRelicOneDashboard_VariablesNRQL(t *testing.T) {
ResourceName: "newrelic_one_dashboard.bar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"variable.0.options",
},
},
},
})
Expand Down Expand Up @@ -829,6 +832,10 @@ func testAccCheckNewRelicOneDashboardConfig_VariableNRQL() string {
replacement_strategy = "default"
title = "title"
type = "nrql"
options {
excluded = true
ignore_time_range = true
}
}
`
}
Expand All @@ -850,6 +857,10 @@ func testAccCheckNewRelicOneDashboardConfig_VariableNRQLUpdated() string {
replacement_strategy = "default"
title = "title"
type = "nrql"
options {
excluded = false
ignore_time_range = false
}
}
`
}
Expand Down
30 changes: 22 additions & 8 deletions newrelic/structures_newrelic_one_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,9 @@ func expandDashboardWidgetInput(w map[string]interface{}, meta interface{}, visu
cfg.Limit = l.(float64)
}

var platformOptions = dashboards.RawConfigurationPlatformOptions{}

if l, ok := w["ignore_time_range"]; ok {
var platformOptions = dashboards.RawConfigurationPlatformOptions{}
platformOptions.IgnoreTimeRange = l.(bool)
cfg.PlatformOptions = &platformOptions
}
Expand Down Expand Up @@ -1014,9 +1015,20 @@ func expandVariableOptions(in []interface{}) *dashboards.DashboardVariableOption
var out dashboards.DashboardVariableOptionsInput

for _, v := range in {

cfg := v.(map[string]interface{})
var ignoreTimeRangePtr, excludedPtr *bool

if ignoreTimeRange, ok := cfg["ignore_time_range"].(bool); ok {
ignoreTimeRangePtr = &ignoreTimeRange
}

if excluded, ok := cfg["excluded"].(bool); ok {
excludedPtr = &excluded
}
out = dashboards.DashboardVariableOptionsInput{
IgnoreTimeRange: cfg["ignore_time_range"].(bool),
IgnoreTimeRange: ignoreTimeRangePtr,
Excluded: excludedPtr,
}
}

Expand Down Expand Up @@ -1050,7 +1062,6 @@ func flattenDashboardEntity(dashboard *entities.DashboardEntity, d *schema.Resou
return err
}
}

return nil
}

Expand Down Expand Up @@ -1080,14 +1091,12 @@ func flattenDashboardUpdateResult(result *dashboards.DashboardUpdateResult, d *s
return err
}
}

if dashboard.Variables != nil && len(dashboard.Variables) > 0 {
variables := flattenDashboardVariable(&dashboard.Variables, d)
if err := d.Set("variable", variables); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -1117,7 +1126,6 @@ func flattenDashboardVariable(in *[]entities.DashboardVariable, d *schema.Resour
m["options"] = options
}
}

out[i] = m
}
return out
Expand Down Expand Up @@ -1178,7 +1186,13 @@ func flattenVariableOptions(in *entities.DashboardVariableOptions, d *schema.Res
// (set it to the value of ignore_time_range seen in the response returned by the API)
out := make([]interface{}, 1)
n := make(map[string]interface{})
n["ignore_time_range"] = in.IgnoreTimeRange
option := options[0].(map[string]interface{})
if _, excludedFetchedOk := option["excluded"]; excludedFetchedOk {
n["excluded"] = in.Excluded
}
if _, ignoreTimeRangeFetchedOk := option["ignore_time_range"]; ignoreTimeRangeFetchedOk {
n["ignore_time_range"] = in.IgnoreTimeRange
}
out[0] = n
return out
}
Expand Down Expand Up @@ -1708,7 +1722,7 @@ func validateDashboardArguments(ctx context.Context, d *schema.ResourceDiff, met
errorsList = append(errorsList, err.Error())
}

//adding a function to validate that the " to and "from" feilds in "threshold" for table & line widget are a floating point number.
//adding a function to validate that the " to and "from" fields in "threshold" for table & line widget are a floating point number.
validateThresholdFields(d, &errorsList, "widget_table")
validateThresholdFields(d, &errorsList, "widget_line")

Expand Down
2 changes: 1 addition & 1 deletion testing/newrelic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ terraform {

provider "newrelic" {
region = "US" # US or EU
}
}
2 changes: 1 addition & 1 deletion website/docs/r/one_dashboard.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ The following arguments are supported:
* `type` - (Required) Specifies the data type of the variable and where its possible values may come from. One of `enum`, `nrql` or `string`
* `options` - (Optional) Specifies additional options to be added to dashboard variables. Supports the following nested attribute(s) -
* `ignore_time_range` - (Optional) An argument with a boolean value that is supported only by variables of `type` _nrql_ - when true, the time range specified in the query will override the time picker on dashboards and other pages.

* `excluded` - (Optional) An argument with a boolean value. With this turned on, the query condition defined with the variable will not be included in the query. Defaults to `false`.
### Nested `item` blocks

The following arguments are supported:
Expand Down

0 comments on commit 4c1e489

Please sign in to comment.