diff --git a/go.mod b/go.mod index 3b102a7ea..49037e63d 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 0e6ce6263..0b712ded8 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/newrelic/resource_newrelic_one_dashboard.go b/newrelic/resource_newrelic_one_dashboard.go index 926d89a7c..a78248e31 100644 --- a/newrelic/resource_newrelic_one_dashboard.go +++ b/newrelic/resource_newrelic_one_dashboard.go @@ -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.", + }, }, }, }, @@ -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("") diff --git a/newrelic/resource_newrelic_one_dashboard_test.go b/newrelic/resource_newrelic_one_dashboard_test.go index 0bb6d8eff..4b3a16789 100644 --- a/newrelic/resource_newrelic_one_dashboard_test.go +++ b/newrelic/resource_newrelic_one_dashboard_test.go @@ -454,6 +454,9 @@ func TestAccNewRelicOneDashboard_VariablesNRQL(t *testing.T) { ResourceName: "newrelic_one_dashboard.bar", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "variable.0.options", + }, }, }, }) @@ -829,6 +832,10 @@ func testAccCheckNewRelicOneDashboardConfig_VariableNRQL() string { replacement_strategy = "default" title = "title" type = "nrql" + options { + excluded = true + ignore_time_range = true + } } ` } @@ -850,6 +857,10 @@ func testAccCheckNewRelicOneDashboardConfig_VariableNRQLUpdated() string { replacement_strategy = "default" title = "title" type = "nrql" + options { + excluded = false + ignore_time_range = false + } } ` } diff --git a/newrelic/structures_newrelic_one_dashboard.go b/newrelic/structures_newrelic_one_dashboard.go index 089429d17..f97c85e9d 100644 --- a/newrelic/structures_newrelic_one_dashboard.go +++ b/newrelic/structures_newrelic_one_dashboard.go @@ -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 } @@ -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, } } @@ -1050,7 +1062,6 @@ func flattenDashboardEntity(dashboard *entities.DashboardEntity, d *schema.Resou return err } } - return nil } @@ -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 } @@ -1117,7 +1126,6 @@ func flattenDashboardVariable(in *[]entities.DashboardVariable, d *schema.Resour m["options"] = options } } - out[i] = m } return out @@ -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 } @@ -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") diff --git a/testing/newrelic.tf b/testing/newrelic.tf index ce4e4816f..22af2bd52 100644 --- a/testing/newrelic.tf +++ b/testing/newrelic.tf @@ -8,4 +8,4 @@ terraform { provider "newrelic" { region = "US" # US or EU -} +} \ No newline at end of file diff --git a/website/docs/r/one_dashboard.html.markdown b/website/docs/r/one_dashboard.html.markdown index c5622b976..4eb491c57 100644 --- a/website/docs/r/one_dashboard.html.markdown +++ b/website/docs/r/one_dashboard.html.markdown @@ -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: