From d3cbc614729f0fa23ce470adeb6d33786f097647 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Thu, 8 Aug 2024 19:02:41 +0530 Subject: [PATCH 01/21] feat(synthetics): multi browser, devices changes in couple of synthetics monitors --- newrelic/resource_helpers_synthetics.go | 19 +++++++++++++++++++ ...urce_newrelic_synthetics_script_monitor.go | 18 +++++++++++++++++- ...source_newrelic_synthetics_step_monitor.go | 18 ++++++++++++++++++ ...relic_synthetics_script_browser_monitor.go | 16 ++++++++++++++++ ...ctures_newrelic_synthetics_step_monitor.go | 16 ++++++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/newrelic/resource_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index fa189c472..026781f3d 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -236,6 +236,25 @@ func expandSyntheticsPublicLocations(locations []interface{}) []string { return locationsOut } +func expandSyntheticsBrowsers(browsers []interface{}) []synthetics.SyntheticsBrowser { + browsersOut := make([]synthetics.SyntheticsBrowser, len(browsers)) + + for i, v := range browsers { + browsersOut[i] = synthetics.SyntheticsBrowser(v.(string)) + + } + return browsersOut +} + +func expandSyntheticsDevices(devices []interface{}) []synthetics.SyntheticsDevice { + devicesOut := make([]synthetics.SyntheticsDevice, len(devices)) + + for i, v := range devices { + devicesOut[i] = synthetics.SyntheticsDevice(v.(string)) + } + return devicesOut +} + func expandSyntheticsPrivateLocations(locations []interface{}) []synthetics.SyntheticsPrivateLocationInput { locationsOut := make([]synthetics.SyntheticsPrivateLocationInput, len(locations)) diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index 9cfc09ebd..d23ea8016 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -65,7 +65,7 @@ func syntheticsScriptMonitorLocationsSchema() map[string]*schema.Schema { } } -// Scripted browser monitors have advanced options, but scripted API monitors do not. +// Scripted browser monitors have advanced options, browsers and devices fields, but scripted API monitors do not. func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "enable_screenshot_on_failure_and_script": { @@ -83,6 +83,22 @@ func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Sc Optional: true, Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", }, + "browsers": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + + " EDGE, FIREFOX, and NONE.", + }, + "devices": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", + }, } } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index 58b00f095..b5cada763 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -101,6 +101,22 @@ func syntheticsStepMonitorSchema() map[string]*schema.Schema { Optional: true, Description: "The specific semver version of the runtime type.", }, + "browsers": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + + " EDGE, FIREFOX, and NONE.", + }, + "devices": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", + }, } } @@ -223,6 +239,8 @@ func resourceNewRelicSyntheticsStepMonitorUpdate(ctx context.Context, d *schema. _ = d.Set("locations_public", resp.Monitor.Locations.Public) _ = d.Set("steps", flattenSyntheticsMonitorSteps(resp.Monitor.Steps)) _ = d.Set("period_in_minutes", syntheticsMonitorPeriodInMinutesValueMap[resp.Monitor.Period]) + _ = d.Set("browsers", resp.Monitor.Browsers) + _ = d.Set("devices", resp.Monitor.Devices) err = setSyntheticsMonitorAttributes(d, map[string]string{ "guid": string(resp.Monitor.GUID), diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index ec9749538..0628c3fc0 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -25,6 +25,14 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics input.Locations.Public = expandSyntheticsPublicLocations(v.(*schema.Set).List()) } + if v, ok := d.GetOk("browsers"); ok { + input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) + } + + if v, ok := d.GetOk("devices"); ok { + input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) + } + sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -87,6 +95,14 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. input.Locations.Private = expandSyntheticsPrivateLocations(v.(*schema.Set).List()) } + if v, ok := d.GetOk("browsers"); ok { + input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) + } + + if v, ok := d.GetOk("devices"); ok { + input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) + } + sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") diff --git a/newrelic/structures_newrelic_synthetics_step_monitor.go b/newrelic/structures_newrelic_synthetics_step_monitor.go index 01d70463d..b60161b69 100644 --- a/newrelic/structures_newrelic_synthetics_step_monitor.go +++ b/newrelic/structures_newrelic_synthetics_step_monitor.go @@ -31,6 +31,14 @@ func buildSyntheticsStepMonitorCreateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } + if v, ok := d.GetOk("browsers"); ok { + input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) + } + + if v, ok := d.GetOk("devices"); ok { + input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) + } + runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -76,6 +84,14 @@ func buildSyntheticsStepMonitorUpdateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } + if v, ok := d.GetOk("browsers"); ok { + input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) + } + + if v, ok := d.GetOk("devices"); ok { + input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) + } + runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") From bb702fa97ffac763c0035d7aa29bd783be811bd5 Mon Sep 17 00:00:00 2001 From: vagrawal-newrelic Date: Sun, 11 Aug 2024 14:17:08 +0530 Subject: [PATCH 02/21] feat(synthetic Browser Monitor): Add multi browser support for simple browser synthetic monitor --- newrelic/resource_newrelic_synthetics_monitor.go | 16 ++++++++++++++++ .../resource_newrelic_synthetics_monitor_test.go | 6 ++++++ ...newrelic_synthetics_simple_browser_monitor.go | 16 ++++++++++++++++ website/docs/r/synthetics_monitor.html.markdown | 5 ++++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index 953e820f9..ecf8d5025 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -145,6 +145,22 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource { Description: "Capture a screenshot during job execution", Optional: true, }, + "browsers": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + + " EDGE, FIREFOX, and NONE.", + }, + "devices": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", + }, "custom_header": { Type: schema.TypeSet, Description: "Custom headers to use in monitor job", diff --git a/newrelic/resource_newrelic_synthetics_monitor_test.go b/newrelic/resource_newrelic_synthetics_monitor_test.go index a73657f55..9486db2ab 100644 --- a/newrelic/resource_newrelic_synthetics_monitor_test.go +++ b/newrelic/resource_newrelic_synthetics_monitor_test.go @@ -327,6 +327,8 @@ func TestAccNewRelicSyntheticsSimpleBrowserMonitor(t *testing.T) { "script_language", "device_orientation", "device_type", + "devices", + "browsers", }, }, }, @@ -344,6 +346,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp name = "customer-header-2" value = "header-value-2" } + devices = ["MOBILE_LANDSCAPE","MOBILE_PORTRAIT"] + browsers = ["CHROME","FIREFOX"] enable_screenshot_on_failure_and_script = true validation_string = "success" verify_ssl = true @@ -368,6 +372,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfigUpdated(name string, mon name = "name" value = "simple_browser" } + devices = ["MOBILE_LANDSCAPE"] + browsers = ["CHROME"] enable_screenshot_on_failure_and_script = false validation_string = "success" verify_ssl = false diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index 9d1a928ee..0acd631fd 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -47,6 +47,14 @@ func buildSyntheticsSimpleBrowserMonitor(d *schema.ResourceData) (synthetics.Syn simpleBrowserMonitorInput.AdvancedOptions.UseTlsValidation = &vs } + if v, ok := d.GetOk("devices"); ok { + simpleBrowserMonitorInput.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) + } + + if v, ok := d.GetOk("browsers"); ok { + simpleBrowserMonitorInput.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) + } + err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d, simpleBrowserMonitorInput) if err != nil { return *simpleBrowserMonitorInput, err @@ -137,6 +145,14 @@ func buildSyntheticsSimpleBrowserMonitorUpdateStruct(d *schema.ResourceData) (sy simpleBrowserMonitorUpdateInput.AdvancedOptions.UseTlsValidation = &vs } + if v, ok := d.GetOk("devices"); ok { + simpleBrowserMonitorUpdateInput.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) + } + + if v, ok := d.GetOk("browsers"); ok { + simpleBrowserMonitorUpdateInput.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) + } + err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d, simpleBrowserMonitorUpdateInput) if err != nil { return *simpleBrowserMonitorUpdateInput, err diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index e734052b6..c99cae2e6 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -53,7 +53,8 @@ resource "newrelic_synthetics_monitor" "monitor" { name = "some_name" value = "some_value" } - + devices = ["MOBILE_LANDSCAPE","MOBILE_PORTRAIT"] + browsers = ["CHROME","FIREFOX"] enable_screenshot_on_failure_and_script = true validation_string = "success" verify_ssl = true @@ -103,6 +104,8 @@ The `BROWSER` monitor type supports the following additional arguments: * `script_language` - (Optional) The programing language that should execute the script. * `device_orientation` - (Optional) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. * `device_type` - (Optional) Device emulation type field. Valid values are `MOBILE` and `TABLET`. +* `devices` - (Optional) The devices on which monitor will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE`, `TABLET_PORTRAIT` and `NONE` . +* `browsers` - (Optional) The browsers on which monitor will run. Valid values are `CHROME`, `EDGE`, `FIREFOX`, and `NONE` . #### Deprecated runtime From 51c20cabe8ac0bed27e69e0aa4933dc376643c7c Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 13 Aug 2024 11:42:54 +0530 Subject: [PATCH 03/21] feat(synthetics): added integration test changes of multi browsers support --- go.mod | 2 + ...thetics_script_monitor_integration_test.go | 5 ++- ...e_newrelic_synthetics_step_monitor_test.go | 10 +++-- ...relic_synthetics_script_browser_monitor.go | 20 ++++----- ...ctures_newrelic_synthetics_step_monitor.go | 20 ++++----- testing/newrelic.tf | 44 +++++++++++++++++++ .../r/synthetics_script_monitor.html.markdown | 14 +++--- .../r/synthetics_step_monitor.html.markdown | 10 +++-- 8 files changed, 89 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index b888aec05..5555b2f83 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/newrelic/terraform-provider-newrelic/v2 go 1.21 +replace github.com/newrelic/newrelic-client-go/v2 => ../newrelic-client-go + require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 github.com/mitchellh/go-homedir v1.1.0 diff --git a/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go b/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go index e40ccab7e..902d83dfd 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go @@ -137,6 +137,8 @@ func TestAccNewRelicSyntheticsScriptBrowserMonitor(t *testing.T) { "enable_screenshot_on_failure_and_script", "device_orientation", "device_type", + "browsers", + "devices", }, }, }, @@ -250,7 +252,8 @@ func testAccNewRelicSyntheticsScriptBrowserMonitorConfig(name string) string { device_orientation = "PORTRAIT" device_type = "MOBILE" - + browsers = ["CHROME"] + devices = ["MOBILE_PORTRAIT"] tag { key = "Name" values = ["scriptedMonitor"] diff --git a/newrelic/resource_newrelic_synthetics_step_monitor_test.go b/newrelic/resource_newrelic_synthetics_step_monitor_test.go index 827dd1de6..1c195ac64 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor_test.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor_test.go @@ -28,8 +28,8 @@ func TestAccNewRelicSyntheticsStepMonitor(t *testing.T) { Config: testAccNewRelicSyntheticsStepMonitorConfig( rName, "", - "", - "", + "CHROME_BROWSER", + "100", ), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicSyntheticsMonitorEntityExists(resourceName), @@ -56,6 +56,8 @@ func TestAccNewRelicSyntheticsStepMonitor(t *testing.T) { "location_private", "tag", "enable_screenshot_on_failure_and_script", + "browsers", + "devices", }, }, }, @@ -82,7 +84,9 @@ resource "newrelic_synthetics_step_monitor" "foo" { type = "NAVIGATE" values = ["https://google.com"] } - + browsers = ["CHROME"] + devices = ["DESKTOP"] + %[2]s } `, diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index 0628c3fc0..f8c0dc563 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -25,13 +25,11 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics input.Locations.Public = expandSyntheticsPublicLocations(v.(*schema.Set).List()) } - if v, ok := d.GetOk("browsers"); ok { - input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + input.Browsers = &typedBrowsers - if v, ok := d.GetOk("devices"); ok { - input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) - } + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + input.Devices = &typedDevices sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") @@ -95,13 +93,11 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. input.Locations.Private = expandSyntheticsPrivateLocations(v.(*schema.Set).List()) } - if v, ok := d.GetOk("browsers"); ok { - input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + input.Browsers = &typedBrowsers - if v, ok := d.GetOk("devices"); ok { - input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) - } + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + input.Devices = &typedDevices sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") diff --git a/newrelic/structures_newrelic_synthetics_step_monitor.go b/newrelic/structures_newrelic_synthetics_step_monitor.go index b60161b69..56a1125e9 100644 --- a/newrelic/structures_newrelic_synthetics_step_monitor.go +++ b/newrelic/structures_newrelic_synthetics_step_monitor.go @@ -31,13 +31,11 @@ func buildSyntheticsStepMonitorCreateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } - if v, ok := d.GetOk("browsers"); ok { - input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + input.Browsers = &typedBrowsers - if v, ok := d.GetOk("devices"); ok { - input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) - } + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + input.Devices = &typedDevices runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -84,13 +82,11 @@ func buildSyntheticsStepMonitorUpdateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } - if v, ok := d.GetOk("browsers"); ok { - input.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + input.Browsers = &typedBrowsers - if v, ok := d.GetOk("devices"); ok { - input.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) - } + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + input.Devices = &typedDevices runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") diff --git a/testing/newrelic.tf b/testing/newrelic.tf index ce4e4816f..d73f6ea80 100644 --- a/testing/newrelic.tf +++ b/testing/newrelic.tf @@ -9,3 +9,47 @@ terraform { provider "newrelic" { region = "US" # US or EU } + +# +# resource "newrelic_synthetics_script_monitor" "monitor" { +# status = "DISABLED" +# name = "name123" +# type = "SCRIPT_BROWSER" +# locations_public = ["AP_SOUTH_1", "AP_EAST_1"] +# period = "EVERY_HOUR" +# devices = ["MOBILE_LANDSCAPE", "DESKTOP", "TABLET_LANDSCAPE"] +# browsers = ["EDGE", "CHROME", "FIREFOX"] +# enable_screenshot_on_failure_and_script = false +# +# script = "$browser.get('https://one.newrelic.com')" +# +# runtime_type_version = "100" +# runtime_type = "CHROME_BROWSER" +# script_language = "JAVASCRIPT" +# +# tag { +# key = "some_key" +# values = ["some_value"] +# } +# } + +resource "newrelic_synthetics_step_monitor" "foo" { + name = "step_name123" + enable_screenshot_on_failure_and_script = true + locations_public = ["US_EAST_1", "US_EAST_2"] + period = "EVERY_6_HOURS" + status = "DISABLED" + runtime_type = "CHROME_BROWSER" + runtime_type_version = "100" + devices = ["MOBILE_LANDSCAPE", "DESKTOP"] + browsers = ["EDGE", "CHROME"] + steps { + ordinal = 0 + type = "NAVIGATE" + values = ["https://www.newrelic.com"] + } + tag { + key = "some_key" + values = ["some_value"] + } +} \ No newline at end of file diff --git a/website/docs/r/synthetics_script_monitor.html.markdown b/website/docs/r/synthetics_script_monitor.html.markdown index 52de5afdc..0848f274c 100644 --- a/website/docs/r/synthetics_script_monitor.html.markdown +++ b/website/docs/r/synthetics_script_monitor.html.markdown @@ -53,7 +53,9 @@ resource "newrelic_synthetics_script_monitor" "monitor" { runtime_type_version = "100" runtime_type = "CHROME_BROWSER" script_language = "JAVASCRIPT" - + devices = ["DESKTOP", "MOBILE_LANDSCAPE", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] + tag { key = "some_key" values = ["some_value"] @@ -84,8 +86,10 @@ The following are the common arguments supported for `SCRIPT_API` and `SCRIPT_BR The `SCRIPTED_BROWSER` monitor type supports the following additional argument: * `enable_screenshot_on_failure_and_script` - (Optional) Capture a screenshot during job execution. -* `device_orientation` - (Optional) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. -* `device_type` - (Optional) Device emulation type field. Valid values are `MOBILE` and `TABLET`. +* `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. +* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `TABLET`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. +* `device_orientation` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_orientation`*) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. +* `device_type` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_type`*) Device emulation type field. Valid values are `MOBILE` and `TABLET`. #### Deprecated runtime @@ -170,8 +174,8 @@ resource "newrelic_synthetics_script_monitor" "monitor" { runtime_type_version = "100" runtime_type = "CHROME_BROWSER" script_language = "JAVASCRIPT" - device_type = "MOBILE" - device_orientation = "LANDSCAPE" + devices = ["DESKTOP", "MOBILE_LANDSCAPE", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] tag { key = "some_key" diff --git a/website/docs/r/synthetics_step_monitor.html.markdown b/website/docs/r/synthetics_step_monitor.html.markdown index 1d4e4cd46..e8e8f5d7c 100644 --- a/website/docs/r/synthetics_step_monitor.html.markdown +++ b/website/docs/r/synthetics_step_monitor.html.markdown @@ -57,6 +57,8 @@ The following are the common arguments supported for `STEP` monitor: -> **WARNING** Support for legacy Synthetics runtimes **will reach its end-of-life (EOL) on October 22, 2024**. In addition, creating **_new_** monitors using the legacy runtime **will no longer be supported after August 26, 2024**. In light of the above, kindly **upgrade your Synthetic Monitors to the new runtime** at the earliest, if they are still using the legacy runtime. Please check out [this page](https://forum.newrelic.com/s/hubtopic/aAXPh0000001brxOAA/upcoming-endoflife-legacy-synthetics-runtimes-and-cpm) for more details on the EOL, action needed (specific to monitors using public and private locations), relevant resources, and more. * `steps` - (Required) The steps that make up the script the monitor will run. See [Nested steps blocks](#nested-steps-blocks) below for details. +* `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. +* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `TABLET`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. * `tag` - (Optional) The tags that will be associated with the monitor. See [Nested tag blocks](#nested-tag-blocks) below for details. ### Nested `location private` blocks @@ -97,9 +99,11 @@ resource "newrelic_synthetics_private_location" "foo" { } resource "newrelic_synthetics_step_monitor" "foo" { - name = "Sample Step Monitor" - period = "EVERY_6_HOURS" - status = "ENABLED" + name = "Sample Step Monitor" + period = "EVERY_6_HOURS" + status = "ENABLED" + devices = ["DESKTOP", "MOBILE_LANDSCAPE", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] location_private { guid = newrelic_synthetics_private_location.foo.id vse_password = "secret" From baaec8032b62d3e3d880c294beb4e4466f8e6e0c Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Fri, 16 Aug 2024 14:52:08 +0530 Subject: [PATCH 04/21] fix(synthetics): made changes to show drift if monitor config changes from UI --- newrelic/resource_helpers_synthetics.go | 2 ++ ...urce_newrelic_synthetics_script_monitor.go | 13 ++++++------ ...relic_synthetics_simple_browser_monitor.go | 20 ++++++++----------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/newrelic/resource_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index 026781f3d..892a57bae 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -507,6 +507,8 @@ var syntheticsMonitorTagKeyToSchemaAttrMap = map[string]string{ "scriptLanguage": "script_language", "deviceOrientation": "device_orientation", "deviceType": "device_type", + "browsers": "browsers", + "devices": "devices", } func getCertCheckMonitorValuesFromEntityTags(tags []entities.EntityTag) (domain string, daysUntilExpiration int) { diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index d23ea8016..165849978 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -2,15 +2,13 @@ package newrelic import ( "context" - "log" - - "github.com/newrelic/newrelic-client-go/v2/pkg/common" - "github.com/newrelic/newrelic-client-go/v2/pkg/entities" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/newrelic/newrelic-client-go/v2/pkg/common" + "github.com/newrelic/newrelic-client-go/v2/pkg/entities" "github.com/newrelic/newrelic-client-go/v2/pkg/synthetics" + "log" ) func resourceNewRelicSyntheticsScriptMonitor() *schema.Resource { @@ -244,10 +242,11 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. }) _ = d.Set("period_in_minutes", int(e.GetPeriod())) - for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { - if len(t.Values) == 1 { + if t.Key == "devices" || t.Key == "browsers" { + _ = d.Set(k, t.Values) + } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } } diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index 0acd631fd..e1ad0c257 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -47,13 +47,11 @@ func buildSyntheticsSimpleBrowserMonitor(d *schema.ResourceData) (synthetics.Syn simpleBrowserMonitorInput.AdvancedOptions.UseTlsValidation = &vs } - if v, ok := d.GetOk("devices"); ok { - simpleBrowserMonitorInput.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + simpleBrowserMonitorInput.Browsers = &typedBrowsers - if v, ok := d.GetOk("browsers"); ok { - simpleBrowserMonitorInput.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) - } + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + simpleBrowserMonitorInput.Devices = &typedDevices err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d, simpleBrowserMonitorInput) if err != nil { @@ -145,13 +143,11 @@ func buildSyntheticsSimpleBrowserMonitorUpdateStruct(d *schema.ResourceData) (sy simpleBrowserMonitorUpdateInput.AdvancedOptions.UseTlsValidation = &vs } - if v, ok := d.GetOk("devices"); ok { - simpleBrowserMonitorUpdateInput.Devices = expandSyntheticsDevices(v.(*schema.Set).List()) - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + simpleBrowserMonitorUpdateInput.Browsers = &typedBrowsers - if v, ok := d.GetOk("browsers"); ok { - simpleBrowserMonitorUpdateInput.Browsers = expandSyntheticsBrowsers(v.(*schema.Set).List()) - } + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + simpleBrowserMonitorUpdateInput.Devices = &typedDevices err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d, simpleBrowserMonitorUpdateInput) if err != nil { From 14fab7349a9bd26d96aa97af90b7b1de06532b57 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Mon, 19 Aug 2024 10:02:13 +0530 Subject: [PATCH 05/21] fix(synthetics): fixed feat to see drift if user changes sometime in UI --- newrelic/resource_newrelic_synthetics_monitor.go | 4 +++- newrelic/resource_newrelic_synthetics_step_monitor.go | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index ecf8d5025..4bf6a92d8 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -324,7 +324,9 @@ func setCommonSyntheticsMonitorAttributes(v *entities.EntityInterface, d *schema if e.MonitorType == entities.SyntheticMonitorTypeTypes.BROWSER { for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { - if len(t.Values) == 1 { + if t.Key == "devices" || t.Key == "browsers" { + _ = d.Set(k, t.Values) + } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index b5cada763..a129bd9e8 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -212,9 +212,12 @@ func resourceNewRelicSyntheticsStepMonitorRead(ctx context.Context, d *schema.Re _ = d.Set("runtime_type", runtimeType) _ = d.Set("runtime_type_version", runtimeTypeVersion) } - + for _, t := range e.Tags { + if t.Key == "devices" || t.Key == "browsers" { + _ = d.Set(t.Key, t.Values) + } + } } - return diag.FromErr(err) } @@ -239,8 +242,6 @@ func resourceNewRelicSyntheticsStepMonitorUpdate(ctx context.Context, d *schema. _ = d.Set("locations_public", resp.Monitor.Locations.Public) _ = d.Set("steps", flattenSyntheticsMonitorSteps(resp.Monitor.Steps)) _ = d.Set("period_in_minutes", syntheticsMonitorPeriodInMinutesValueMap[resp.Monitor.Period]) - _ = d.Set("browsers", resp.Monitor.Browsers) - _ = d.Set("devices", resp.Monitor.Devices) err = setSyntheticsMonitorAttributes(d, map[string]string{ "guid": string(resp.Monitor.GUID), From cf76c2eff84e7084df3397b17af688d0bf3f745b Mon Sep 17 00:00:00 2001 From: pranav-new-relic Date: Fri, 30 Aug 2024 13:21:32 +0530 Subject: [PATCH 06/21] fix(synthetics): allow new -> legacy runtime downgrade until Oct 22 for simple browser, scripted monitors --- ...uctures_newrelic_synthetics_script_api_monitor.go | 12 ++++++++---- ...res_newrelic_synthetics_script_browser_monitor.go | 12 ++++++++---- ...res_newrelic_synthetics_simple_browser_monitor.go | 12 ++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/newrelic/structures_newrelic_synthetics_script_api_monitor.go b/newrelic/structures_newrelic_synthetics_script_api_monitor.go index f7bc25ce8..e096a61fc 100644 --- a/newrelic/structures_newrelic_synthetics_script_api_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_api_monitor.go @@ -27,9 +27,8 @@ func buildSyntheticsScriptAPIMonitorInput(d *schema.ResourceData) synthetics.Syn _, runtimeTypeOk := d.GetOk("runtime_type") _, runtimeVersionOk := d.GetOk("runtime_type_version") + input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeVersionOk { - input.Runtime = &synthetics.SyntheticsRuntimeInput{} - if v, ok := d.GetOk("script_language"); ok { input.Runtime.ScriptLanguage = v.(string) } @@ -39,6 +38,9 @@ func buildSyntheticsScriptAPIMonitorInput(d *schema.ResourceData) synthetics.Syn if v, ok := d.GetOk("runtime_type_version"); ok { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(v.(string)) } + } else { + input.Runtime.RuntimeType = "" + input.Runtime.RuntimeTypeVersion = "" } return input @@ -66,9 +68,8 @@ func buildSyntheticsScriptAPIMonitorUpdateInput(d *schema.ResourceData) syntheti _, runtimeTypeOk := d.GetOk("runtime_type") _, runtimeVersionOk := d.GetOk("runtime_type_version") + input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeVersionOk { - input.Runtime = &synthetics.SyntheticsRuntimeInput{} - if v, ok := d.GetOk("script_language"); ok { input.Runtime.ScriptLanguage = v.(string) } @@ -78,6 +79,9 @@ func buildSyntheticsScriptAPIMonitorUpdateInput(d *schema.ResourceData) syntheti if v, ok := d.GetOk("runtime_type_version"); ok { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(v.(string)) } + } else { + input.Runtime.RuntimeType = "" + input.Runtime.RuntimeTypeVersion = "" } return input diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index ec9749538..a587a3f97 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -29,9 +29,8 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") + input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { - input.Runtime = &synthetics.SyntheticsRuntimeInput{} - if scriptLangOk { input.Runtime.ScriptLanguage = sciptLang.(string) } @@ -43,6 +42,9 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics if runtimeTypeVersionOk { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } + } else { + input.Runtime.RuntimeType = "" + input.Runtime.RuntimeTypeVersion = "" } enableScreenshot := d.Get("enable_screenshot_on_failure_and_script").(bool) @@ -90,9 +92,8 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") + input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { - input.Runtime = &synthetics.SyntheticsRuntimeInput{} - if scriptLangOk { input.Runtime.ScriptLanguage = sciptLang.(string) } @@ -104,6 +105,9 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. if runtimeTypeVersionOk { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } + } else { + input.Runtime.RuntimeType = "" + input.Runtime.RuntimeTypeVersion = "" } enableScreenshot := d.Get("enable_screenshot_on_failure_and_script").(bool) diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index 9d1a928ee..a659dcd69 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -60,9 +60,8 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d *schema.Reso runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") + simpleBrowserMonitorInput.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { - simpleBrowserMonitorInput.Runtime = &synthetics.SyntheticsRuntimeInput{} - if scriptLangOk { simpleBrowserMonitorInput.Runtime.ScriptLanguage = scriptLang.(string) } @@ -74,6 +73,9 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d *schema.Reso if runtimeTypeVersionOk { simpleBrowserMonitorInput.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } + } else { + simpleBrowserMonitorInput.Runtime.RuntimeType = "" + simpleBrowserMonitorInput.Runtime.RuntimeTypeVersion = "" } do, doOk := d.GetOk("device_orientation") @@ -150,9 +152,8 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") + simpleBrowserMonitorUpdateInput.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { - simpleBrowserMonitorUpdateInput.Runtime = &synthetics.SyntheticsRuntimeInput{} - if scriptLangOk { simpleBrowserMonitorUpdateInput.Runtime.ScriptLanguage = scriptLang.(string) } @@ -164,6 +165,9 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d if runtimeTypeVersionOk { simpleBrowserMonitorUpdateInput.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } + } else { + simpleBrowserMonitorUpdateInput.Runtime.RuntimeType = "" + simpleBrowserMonitorUpdateInput.Runtime.RuntimeTypeVersion = "" } do, doOk := d.GetOk("device_orientation") From 186c53c9e0fe1f3a14bf9c7d2f0a7652a667695a Mon Sep 17 00:00:00 2001 From: pranav-new-relic Date: Fri, 30 Aug 2024 13:58:42 +0530 Subject: [PATCH 07/21] chore(synthetics): update code to revert setting empty strings in simple browser monitor update function --- .../structures_newrelic_synthetics_simple_browser_monitor.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index a659dcd69..d33e0b67b 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -152,8 +152,8 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") - simpleBrowserMonitorUpdateInput.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { + simpleBrowserMonitorUpdateInput.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk { simpleBrowserMonitorUpdateInput.Runtime.ScriptLanguage = scriptLang.(string) } @@ -165,9 +165,6 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d if runtimeTypeVersionOk { simpleBrowserMonitorUpdateInput.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } - } else { - simpleBrowserMonitorUpdateInput.Runtime.RuntimeType = "" - simpleBrowserMonitorUpdateInput.Runtime.RuntimeTypeVersion = "" } do, doOk := d.GetOk("device_orientation") From 9c0d0a20f2ea51e22ff09a7ec16138898e4284e2 Mon Sep 17 00:00:00 2001 From: pranav-new-relic Date: Fri, 30 Aug 2024 14:00:04 +0530 Subject: [PATCH 08/21] chore(synthetics): update code to revert setting empty strings in simple browser monitor update function --- .../structures_newrelic_synthetics_simple_browser_monitor.go | 1 + 1 file changed, 1 insertion(+) diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index d33e0b67b..42520fa2d 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -154,6 +154,7 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { simpleBrowserMonitorUpdateInput.Runtime = &synthetics.SyntheticsRuntimeInput{} + if scriptLangOk { simpleBrowserMonitorUpdateInput.Runtime.ScriptLanguage = scriptLang.(string) } From 58010550ede4b1e5b13b88abe1723b4f0d5379ef Mon Sep 17 00:00:00 2001 From: vagrawal-newrelic Date: Fri, 16 Aug 2024 15:17:39 +0530 Subject: [PATCH 09/21] fix(synthetic monitor): Add logic to show drift in case of any UI change for simple browser synthetic monitor Setting up the browsers and devcies feilds from the tag in repose in the readcontext function for the simple browsers monitor synthetic monitor --- newrelic/resource_newrelic_synthetics_monitor.go | 2 +- website/docs/r/synthetics_monitor.html.markdown | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index c93ff7d57..6aff78935 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -326,7 +326,7 @@ func setCommonSyntheticsMonitorAttributes(v *entities.EntityInterface, d *schema if e.MonitorType == entities.SyntheticMonitorTypeTypes.BROWSER { for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { - if t.Key == "devices" || t.Key == "browsers" { + if t.Key == "browsers" || t.Key == "devices" { _ = d.Set(k, t.Values) } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index f3802d65e..c1acc97d0 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -102,8 +102,8 @@ The `BROWSER` monitor type supports the following additional arguments: * `runtime_type_version` - (Optional) The runtime type that the monitor will run. Valid value is `100`. * `runtime_type` - (Optional) The runtime type that the monitor will run. Valid value is `CHROME_BROWSER` * `script_language` - (Optional) The programing language that should execute the script. -* `device_orientation` - (Optional) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. -* `device_type` - (Optional) Device emulation type field. Valid values are `MOBILE` and `TABLET`. +* `device_orientation` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_orientation`*) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. +* `device_type` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_type`*) Device emulation type field. Valid values are `MOBILE` and `TABLET`. * `devices` - (Optional) The devices on which monitor will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE`, `TABLET_PORTRAIT` and `NONE` . * `browsers` - (Optional) The browsers on which monitor will run. Valid values are `CHROME`, `EDGE`, `FIREFOX`, and `NONE` . From 5aec0eb2645c9aa5f60100328655f1b748d1fb31 Mon Sep 17 00:00:00 2001 From: vagrawal-newrelic Date: Wed, 4 Sep 2024 14:30:44 +0530 Subject: [PATCH 10/21] feat(Synthetics): Removing device_type and device_orientation from the docs example section --- website/docs/r/synthetics_monitor.html.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index c1acc97d0..404a38c94 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -61,8 +61,6 @@ resource "newrelic_synthetics_monitor" "monitor" { runtime_type = "CHROME_BROWSER" runtime_type_version = "100" script_language = "JAVASCRIPT" - device_type = "MOBILE" - device_orientation = "LANDSCAPE" tag { key = "some_key" From 819e473208483edad4a242a291ba032e009006b3 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Wed, 4 Sep 2024 16:51:09 +0530 Subject: [PATCH 11/21] fix(drift): fixed the drift issue with devices field --- go.mod | 2 - newrelic/resource_helpers_synthetics.go | 6 +++ ...urce_newrelic_synthetics_script_monitor.go | 6 ++- testing/newrelic.tf | 44 ------------------- 4 files changed, 11 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index d02352fac..48fc1e9a6 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/newrelic/terraform-provider-newrelic/v2 go 1.21 -replace github.com/newrelic/newrelic-client-go/v2 => ../newrelic-client-go - require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 github.com/mitchellh/go-homedir v1.1.0 diff --git a/newrelic/resource_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index 444b0f77c..a1c3a09b3 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -569,3 +569,9 @@ func syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor(k, oldValue, new return false } + +func multiBrowsersDevicesDiffSuppressor(k, oldValue, newValue string, d *schema.ResourceData) bool { + attributeName := strings.Split(k, ".")[0] + isFieldPresent := d.GetRawConfig().GetAttr(attributeName).IsNull() + return isFieldPresent +} diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index f16813234..858490180 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -89,6 +89,7 @@ func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Sc Optional: true, Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + " EDGE, FIREFOX, and NONE.", + DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, }, "devices": { Type: schema.TypeSet, @@ -97,6 +98,7 @@ func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Sc Optional: true, Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", + DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, }, } } @@ -247,7 +249,9 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { if t.Key == "devices" || t.Key == "browsers" { - _ = d.Set(k, t.Values) + if len(d.Get(t.Key).(*schema.Set).List()) > 0 { + _ = d.Set(k, t.Values) + } } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } diff --git a/testing/newrelic.tf b/testing/newrelic.tf index d73f6ea80..22af2bd52 100644 --- a/testing/newrelic.tf +++ b/testing/newrelic.tf @@ -8,48 +8,4 @@ terraform { provider "newrelic" { region = "US" # US or EU -} - -# -# resource "newrelic_synthetics_script_monitor" "monitor" { -# status = "DISABLED" -# name = "name123" -# type = "SCRIPT_BROWSER" -# locations_public = ["AP_SOUTH_1", "AP_EAST_1"] -# period = "EVERY_HOUR" -# devices = ["MOBILE_LANDSCAPE", "DESKTOP", "TABLET_LANDSCAPE"] -# browsers = ["EDGE", "CHROME", "FIREFOX"] -# enable_screenshot_on_failure_and_script = false -# -# script = "$browser.get('https://one.newrelic.com')" -# -# runtime_type_version = "100" -# runtime_type = "CHROME_BROWSER" -# script_language = "JAVASCRIPT" -# -# tag { -# key = "some_key" -# values = ["some_value"] -# } -# } - -resource "newrelic_synthetics_step_monitor" "foo" { - name = "step_name123" - enable_screenshot_on_failure_and_script = true - locations_public = ["US_EAST_1", "US_EAST_2"] - period = "EVERY_6_HOURS" - status = "DISABLED" - runtime_type = "CHROME_BROWSER" - runtime_type_version = "100" - devices = ["MOBILE_LANDSCAPE", "DESKTOP"] - browsers = ["EDGE", "CHROME"] - steps { - ordinal = 0 - type = "NAVIGATE" - values = ["https://www.newrelic.com"] - } - tag { - key = "some_key" - values = ["some_value"] - } } \ No newline at end of file From 8cfbbc3ffb4ea51b17192c70e81b55673259b75f Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Fri, 6 Sep 2024 19:15:31 +0530 Subject: [PATCH 12/21] chore(synthetics): Computed method changes --- go.mod | 2 ++ go.sum | 2 -- newrelic/resource_helpers_synthetics.go | 31 ++++++++++++++--- .../resource_newrelic_synthetics_monitor.go | 27 +++++---------- ...urce_newrelic_synthetics_script_monitor.go | 31 +++++------------ ...source_newrelic_synthetics_step_monitor.go | 27 +++++---------- ...thetics_all_monitors_validation_helpers.go | 34 ++++++++++++++++++- ...relic_synthetics_script_browser_monitor.go | 27 +++++++++------ testing/newrelic.tf | 26 +++++++++++++- .../docs/r/synthetics_monitor.html.markdown | 8 ++--- .../r/synthetics_script_monitor.html.markdown | 6 ++-- .../r/synthetics_step_monitor.html.markdown | 2 +- 12 files changed, 137 insertions(+), 86 deletions(-) diff --git a/go.mod b/go.mod index 48fc1e9a6..d02352fac 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/newrelic/terraform-provider-newrelic/v2 go 1.21 +replace github.com/newrelic/newrelic-client-go/v2 => ../newrelic-client-go + require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index 30b796c41..f2494bcd4 100644 --- a/go.sum +++ b/go.sum @@ -270,8 +270,6 @@ 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.44.0 h1:n4zP64Hfui8pjW/D3tbE1Hi+Acbpz8nBIrI2miEAGiI= -github.com/newrelic/newrelic-client-go/v2 v2.44.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= 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_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index a1c3a09b3..8c1ab67cc 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -130,6 +130,25 @@ var SyntheticsUseLegacyRuntimeSchema = &schema.Schema{ DiffSuppressFunc: syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor, } +var browsersSchema = &schema.Schema{ + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Computed: true, + Description: "The multiple browsers list on which synthetic monitors will run. Valid values are array of CHROME," + + "and FIREFOX", +} +var devicesSchema = &schema.Schema{ + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: true, + Computed: true, + Description: "The multiple devices list on which synthetic monitors will run. Valid values are array of DESKTOP," + + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE and TABLET_PORTRAIT", +} + var syntheticsMonitorPeriodValueMap = map[int]synthetics.SyntheticsMonitorPeriod{ 1: synthetics.SyntheticsMonitorPeriodTypes.EVERY_MINUTE, 5: synthetics.SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES, @@ -570,8 +589,12 @@ func syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor(k, oldValue, new return false } -func multiBrowsersDevicesDiffSuppressor(k, oldValue, newValue string, d *schema.ResourceData) bool { - attributeName := strings.Split(k, ".")[0] - isFieldPresent := d.GetRawConfig().GetAttr(attributeName).IsNull() - return isFieldPresent +func setBrowsersDevicesIfNotPresent(d *schema.ResourceData) { + // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes to avoid Drift + if _, ok := d.GetOk("browsers"); !ok { + _ = d.Set("browsers", []string{}) + } + if _, ok := d.GetOk("devices"); !ok { + _ = d.Set("devices", []string{}) + } } diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index 6aff78935..b6d6fcce2 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -146,22 +146,8 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource { Description: "Capture a screenshot during job execution", Optional: true, }, - "browsers": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Optional: true, - Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + - " EDGE, FIREFOX, and NONE.", - }, - "devices": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Optional: true, - Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + - " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", - }, + "browsers": browsersSchema, + "devices": devicesSchema, "custom_header": { Type: schema.TypeSet, Description: "Custom headers to use in monitor job", @@ -260,7 +246,8 @@ func setAttributesFromCreate(res *synthetics.SyntheticsSimpleBrowserMonitorCreat _ = d.Set("locations_private", res.Monitor.Locations.Private) _ = d.Set("device_orientation", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceOrientation) _ = d.Set("device_type", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceType) - + _ = d.Set("browsers", res.Monitor.Browsers) + _ = d.Set("devices", res.Monitor.Devices) if res.Monitor.Runtime.RuntimeType != "" { _ = d.Set("runtime_type", res.Monitor.Runtime.RuntimeType) } @@ -335,6 +322,9 @@ func setCommonSyntheticsMonitorAttributes(v *entities.EntityInterface, d *schema } } + // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes + setBrowsersDevicesIfNotPresent(d) + for _, t := range e.Tags { if t.Key == "responseValidationText" { if len(t.Values) == 1 { @@ -437,7 +427,8 @@ func setSimpleBrowserAttributesFromUpdate(res *synthetics.SyntheticsSimpleBrowse _ = d.Set("locations_private", res.Monitor.Locations.Private) _ = d.Set("device_orientation", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceOrientation) _ = d.Set("device_type", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceType) - + _ = d.Set("browsers", res.Monitor.Browsers) + _ = d.Set("devices", res.Monitor.Devices) if res.Monitor.Runtime.RuntimeType != "" { _ = d.Set("runtime_type", res.Monitor.Runtime.RuntimeType) } diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index 858490180..b9299c03f 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -72,6 +72,8 @@ func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Sc Optional: true, Description: "Capture a screenshot during job execution.", }, + "browsers": browsersSchema, + "devices": devicesSchema, "device_orientation": { Type: schema.TypeString, Optional: true, @@ -82,24 +84,6 @@ func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Sc Optional: true, Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", }, - "browsers": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Optional: true, - Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + - " EDGE, FIREFOX, and NONE.", - DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, - }, - "devices": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Optional: true, - Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + - " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", - DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, - }, } } @@ -186,7 +170,8 @@ func resourceNewRelicSyntheticsScriptMonitorCreate(ctx context.Context, d *schem d.SetId(string(resp.Monitor.GUID)) _ = d.Set("account_id", accountID) _ = d.Set("period_in_minutes", syntheticsMonitorPeriodInMinutesValueMap[resp.Monitor.Period]) - + _ = d.Set("browsers", resp.Monitor.Browsers) + _ = d.Set("devices", resp.Monitor.Devices) attrs := map[string]string{"guid": string(resp.Monitor.GUID)} if err = setSyntheticsMonitorAttributes(d, attrs); err != nil { return diag.FromErr(err) @@ -244,14 +229,11 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. "period": string(syntheticsMonitorPeriodValueMap[int(e.GetPeriod())]), "status": string(e.MonitorSummary.Status), }) - _ = d.Set("period_in_minutes", int(e.GetPeriod())) for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { if t.Key == "devices" || t.Key == "browsers" { - if len(d.Get(t.Key).(*schema.Set).List()) > 0 { - _ = d.Set(k, t.Values) - } + _ = d.Set(k, t.Values) } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } @@ -259,6 +241,9 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. } } + // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes + setBrowsersDevicesIfNotPresent(d) + return diag.FromErr(err) } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index e7bd176e9..751dad642 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -103,22 +103,8 @@ func syntheticsStepMonitorSchema() map[string]*schema.Schema { Description: "The specific semver version of the runtime type.", }, SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema, - "browsers": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Optional: true, - Description: "The browsers that can be used to execute script execution. Valid values are array of CHROME," + - " EDGE, FIREFOX, and NONE.", - }, - "devices": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Optional: true, - Description: "The devices that can be used to execute script execution. Valid values are array of DESKTOP," + - " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE, TABLET_PORTRAIT and NONE.", - }, + "browsers": browsersSchema, + "devices": devicesSchema, } } @@ -164,7 +150,8 @@ func resourceNewRelicSyntheticsStepMonitorCreate(ctx context.Context, d *schema. if respRuntimeTypeVersion != "" { _ = d.Set("runtime_type_version", respRuntimeTypeVersion) } - + _ = d.Set("browsers", resp.Monitor.Browsers) + _ = d.Set("devices", resp.Monitor.Devices) return diag.FromErr(err) } @@ -219,6 +206,9 @@ func resourceNewRelicSyntheticsStepMonitorRead(ctx context.Context, d *schema.Re _ = d.Set(t.Key, t.Values) } } + + // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes + setBrowsersDevicesIfNotPresent(d) } return diag.FromErr(err) } @@ -262,7 +252,8 @@ func resourceNewRelicSyntheticsStepMonitorUpdate(ctx context.Context, d *schema. if respRuntimeTypeVersion != "" { _ = d.Set("runtime_type_version", respRuntimeTypeVersion) } - + _ = d.Set("browsers", resp.Monitor.Browsers) + _ = d.Set("devices", resp.Monitor.Devices) return diag.FromErr(err) } diff --git a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go index 685f01dbc..f7fa9d67b 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -16,6 +15,11 @@ func validateSyntheticMonitorRuntimeAttributes(ctx context.Context, d *schema.Re errorsList = append(errorsList, err...) } + err = validateDevicesFields(d) + if err != nil { + errorsList = append(errorsList, err...) + } + if len(errorsList) == 0 { return nil } @@ -152,3 +156,31 @@ https://forum.newrelic.com/s/hubtopic/aAXPh0000001brxOAA/upcoming-endoflife-lega https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/guides/synthetics_legacy_runtime_eol_migration_guide ` } + +// The following function will validate the device fields at the Terraform plan, ensuring that the user specifies +// either the devices field alone or both the device_type and device_orientation fields +func validateDevicesFields(d *schema.ResourceDiff) []error { + rawConfiguration := d.GetRawConfig() + + // GetAttr func will get below fields corresponding values from raw configuration that is from terraform configuration file + devicesValue := rawConfiguration.GetAttr("devices").IsNull() + deviceTypeValue := rawConfiguration.GetAttr("device_type").IsNull() + deviceOrientationValue := rawConfiguration.GetAttr("device_orientation").IsNull() + + if !devicesValue && !(deviceTypeValue && deviceOrientationValue) { + return []error{ + fmt.Errorf(`Cannot use 'devices', 'device_type', and 'device_orientation' simultaneously. + Use either 'devices' alone or both 'device_type' and 'device_orientation' fields together. + We recommend using the 'devices' field, as it allows you to select multiple combinations of device types and orientations.`), + } + } + + if deviceTypeValue != deviceOrientationValue { + return []error{ + fmt.Errorf("you need to specify both 'device_type' and 'device_orientation' fields; you can't use just one of them"), + } + } + + return nil + +} diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index f8c0dc563..94a270bbf 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -24,12 +24,14 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics if v, ok := d.GetOk("locations_public"); ok { input.Locations.Public = expandSyntheticsPublicLocations(v.(*schema.Set).List()) } - - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = &typedBrowsers - - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = &typedDevices + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + input.Browsers = &typedBrowsers + } + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + input.Devices = &typedDevices + } sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") @@ -93,11 +95,14 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. input.Locations.Private = expandSyntheticsPrivateLocations(v.(*schema.Set).List()) } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = &typedBrowsers - - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = &typedDevices + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + input.Browsers = &typedBrowsers + } + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + input.Devices = &typedDevices + } sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") diff --git a/testing/newrelic.tf b/testing/newrelic.tf index 22af2bd52..538f303f4 100644 --- a/testing/newrelic.tf +++ b/testing/newrelic.tf @@ -8,4 +8,28 @@ terraform { provider "newrelic" { region = "US" # US or EU -} \ No newline at end of file +} + + + +resource "newrelic_synthetics_script_monitor" "monitor" { + status = "DISABLED" + name = "name1236891625" + type = "SCRIPT_BROWSER" + period = "EVERY_HOUR" + script = "$browser.get('https://one.newrelic.com')" + + enable_screenshot_on_failure_and_script = false + locations_public = ["AP_SOUTH_1"] +# browsers = ["CHROME"] +# devices = [ "MOBILE_PORTRAIT", "MOBILE_LANDSCAPE"] + runtime_type_version = "" + runtime_type = "" + script_language = "JAVASCRIPT" + use_unsupported_legacy_runtime = true + tag { + key = "some_key" + values = ["some_value"] + } +} + diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index 404a38c94..9fef5b025 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -100,10 +100,10 @@ The `BROWSER` monitor type supports the following additional arguments: * `runtime_type_version` - (Optional) The runtime type that the monitor will run. Valid value is `100`. * `runtime_type` - (Optional) The runtime type that the monitor will run. Valid value is `CHROME_BROWSER` * `script_language` - (Optional) The programing language that should execute the script. -* `device_orientation` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_orientation`*) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. -* `device_type` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_type`*) Device emulation type field. Valid values are `MOBILE` and `TABLET`. -* `devices` - (Optional) The devices on which monitor will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE`, `TABLET_PORTRAIT` and `NONE` . -* `browsers` - (Optional) The browsers on which monitor will run. Valid values are `CHROME`, `EDGE`, `FIREFOX`, and `NONE` . +* `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. +* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. +* `device_orientation` - (Optional) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. We recommend you to use `devices` field instead of `device_type`,`device_orientation` fields, as it allows you to select multiple combinations of device types and orientations. +* `device_type` - (Optional) Device emulation type field. Valid values are `MOBILE` and `TABLET`. We recommend you to use `devices` field instead of `device_type`,`device_orientation` fields, as it allows you to select multiple combinations of device types and orientations. #### Deprecated Runtime diff --git a/website/docs/r/synthetics_script_monitor.html.markdown b/website/docs/r/synthetics_script_monitor.html.markdown index 5083b5a3e..1f000704c 100644 --- a/website/docs/r/synthetics_script_monitor.html.markdown +++ b/website/docs/r/synthetics_script_monitor.html.markdown @@ -87,9 +87,9 @@ The `SCRIPTED_BROWSER` monitor type supports the following additional argument: * `enable_screenshot_on_failure_and_script` - (Optional) Capture a screenshot during job execution. * `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. -* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `TABLET`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. -* `device_orientation` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_orientation`*) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. -* `device_type` - (Optional - *Deprecating soon. So, we recommend you to use `devices` attribute instead of `device_type`*) Device emulation type field. Valid values are `MOBILE` and `TABLET`. +* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. +* `device_orientation` - (Optional) Device emulation orientation field. Valid values are `LANDSCAPE` and `PORTRAIT`. We recommend you to use `devices` field instead of `device_type`,`device_orientation` fields, as it allows you to select multiple combinations of device types and orientations. +* `device_type` - (Optional) Device emulation type field. Valid values are `MOBILE` and `TABLET`. We recommend you to use `devices` field instead of `device_type`,`device_orientation` fields, as it allows you to select multiple combinations of device types and orientations. #### Deprecated runtime diff --git a/website/docs/r/synthetics_step_monitor.html.markdown b/website/docs/r/synthetics_step_monitor.html.markdown index b2765be94..b960a12b6 100644 --- a/website/docs/r/synthetics_step_monitor.html.markdown +++ b/website/docs/r/synthetics_step_monitor.html.markdown @@ -58,7 +58,7 @@ The following are the common arguments supported for `STEP` monitor: * `steps` - (Required) The steps that make up the script the monitor will run. See [Nested steps blocks](#nested-steps-blocks) below for details. * `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. -* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `TABLET`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. +* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. * `tag` - (Optional) The tags that will be associated with the monitor. See [Nested tag blocks](#nested-tag-blocks) below for details. ### Nested `location private` blocks From 774b7a6dd901f01ee7185664f9133cc7ce89abcc Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Sat, 7 Sep 2024 22:35:16 +0530 Subject: [PATCH 13/21] chore(synthetics): diff supress method changes, still need to address a bug --- newrelic/resource_helpers_synthetics.go | 32 +++++++++++++- ...ewrelic_synthetics_broken_links_monitor.go | 2 +- ..._newrelic_synthetics_cert_check_monitor.go | 2 +- .../resource_newrelic_synthetics_monitor.go | 2 +- ...urce_newrelic_synthetics_script_monitor.go | 4 +- ...source_newrelic_synthetics_step_monitor.go | 2 +- ...thetics_all_monitors_validation_helpers.go | 22 +++++----- testing/newrelic.tf | 43 ++++++++++++++----- 8 files changed, 81 insertions(+), 28 deletions(-) diff --git a/newrelic/resource_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index 8c1ab67cc..dc829e439 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -135,18 +135,18 @@ var browsersSchema = &schema.Schema{ Elem: &schema.Schema{Type: schema.TypeString}, MinItems: 1, Optional: true, - Computed: true, Description: "The multiple browsers list on which synthetic monitors will run. Valid values are array of CHROME," + "and FIREFOX", + DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, } var devicesSchema = &schema.Schema{ Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, MinItems: 1, Optional: true, - Computed: true, Description: "The multiple devices list on which synthetic monitors will run. Valid values are array of DESKTOP," + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE and TABLET_PORTRAIT", + DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, } var syntheticsMonitorPeriodValueMap = map[int]synthetics.SyntheticsMonitorPeriod{ @@ -598,3 +598,31 @@ func setBrowsersDevicesIfNotPresent(d *schema.ResourceData) { _ = d.Set("devices", []string{}) } } + +func multiBrowsersDevicesDiffSuppressor(k, oldValue, newValue string, d *schema.ResourceData) bool { + rawConfiguration := d.GetRawConfig() + runtimeTypeInConfig := rawConfiguration.GetAttr(SyntheticsRuntimeTypeAttrLabel) + isRuntimeTypeNil := runtimeTypeInConfig.IsNull() || runtimeTypeInConfig.AsString() == "" + + runtimeTypeVersionInConfig := rawConfiguration.GetAttr(SyntheticsRuntimeTypeVersionAttrLabel) + isRuntimeTypeVersionNil := runtimeTypeVersionInConfig.IsNull() || runtimeTypeVersionInConfig.AsString() == "" + + if isRuntimeTypeNil || isRuntimeTypeVersionNil { + return false + } + + _, monitorType := d.GetChange("type") + isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") + attributeName := strings.Split(k, ".")[0] + if attributeName == "devices" && isBrowserMonitor { + deviceTypeIsNil := rawConfiguration.GetAttr("device_type").IsNull() + deviceOrientationIsNil := rawConfiguration.GetAttr("device_orientation").IsNull() + if !deviceTypeIsNil && !deviceOrientationIsNil { + return false + } + } + + isFieldPresent := rawConfiguration.GetAttr(attributeName).IsNull() + + return isFieldPresent +} diff --git a/newrelic/resource_newrelic_synthetics_broken_links_monitor.go b/newrelic/resource_newrelic_synthetics_broken_links_monitor.go index ce10e0291..463d2db82 100644 --- a/newrelic/resource_newrelic_synthetics_broken_links_monitor.go +++ b/newrelic/resource_newrelic_synthetics_broken_links_monitor.go @@ -26,7 +26,7 @@ func resourceNewRelicSyntheticsBrokenLinksMonitor() *schema.Resource { syntheticsMonitorLocationsAsStringsSchema(), syntheticsMonitorRuntimeOptions(), ), - CustomizeDiff: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } diff --git a/newrelic/resource_newrelic_synthetics_cert_check_monitor.go b/newrelic/resource_newrelic_synthetics_cert_check_monitor.go index 3af302c5c..fdd8ef204 100644 --- a/newrelic/resource_newrelic_synthetics_cert_check_monitor.go +++ b/newrelic/resource_newrelic_synthetics_cert_check_monitor.go @@ -110,7 +110,7 @@ func resourceNewRelicSyntheticsCertCheckMonitor() *schema.Resource { }, SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema, }, - CustomizeDiff: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index b6d6fcce2..eeb2315a9 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -178,7 +178,7 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource { Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", }, }, - CustomizeDiff: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index b9299c03f..b587f8b56 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -26,7 +26,7 @@ func resourceNewRelicSyntheticsScriptMonitor() *schema.Resource { syntheticsScriptMonitorLocationsSchema(), syntheticsScriptBrowserMonitorAdvancedOptionsSchema(), ), - CustomizeDiff: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } @@ -242,7 +242,7 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. } // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes - setBrowsersDevicesIfNotPresent(d) + //setBrowsersDevicesIfNotPresent(d) return diag.FromErr(err) } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index 751dad642..15b697bb4 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -25,7 +25,7 @@ func resourceNewRelicSyntheticsStepMonitor() *schema.Resource { syntheticsMonitorCommonSchema(), syntheticsStepMonitorSchema(), ), - CustomizeDiff: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } diff --git a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go index f7fa9d67b..bc9ca1e00 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -5,17 +5,21 @@ import ( "errors" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "strings" ) -func validateSyntheticMonitorRuntimeAttributes(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { +func validateSyntheticMonitorAttributes(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { var errorsList []error err := validateSyntheticMonitorLegacyRuntimeAttributesOnCreate(d) if err != nil { errorsList = append(errorsList, err...) } - - err = validateDevicesFields(d) + _, monitorType := d.GetChange("type") + isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") + if isBrowserMonitor { + err = validateDevicesFields(d) + } if err != nil { errorsList = append(errorsList, err...) } @@ -163,11 +167,11 @@ func validateDevicesFields(d *schema.ResourceDiff) []error { rawConfiguration := d.GetRawConfig() // GetAttr func will get below fields corresponding values from raw configuration that is from terraform configuration file - devicesValue := rawConfiguration.GetAttr("devices").IsNull() - deviceTypeValue := rawConfiguration.GetAttr("device_type").IsNull() - deviceOrientationValue := rawConfiguration.GetAttr("device_orientation").IsNull() + devicesIsNil := rawConfiguration.GetAttr("devices").IsNull() + deviceTypeIsNil := rawConfiguration.GetAttr("device_type").IsNull() + deviceOrientationIsNil := rawConfiguration.GetAttr("device_orientation").IsNull() - if !devicesValue && !(deviceTypeValue && deviceOrientationValue) { + if !devicesIsNil && !(deviceTypeIsNil && deviceOrientationIsNil) { return []error{ fmt.Errorf(`Cannot use 'devices', 'device_type', and 'device_orientation' simultaneously. Use either 'devices' alone or both 'device_type' and 'device_orientation' fields together. @@ -175,12 +179,10 @@ func validateDevicesFields(d *schema.ResourceDiff) []error { } } - if deviceTypeValue != deviceOrientationValue { + if deviceTypeIsNil != deviceOrientationIsNil { return []error{ fmt.Errorf("you need to specify both 'device_type' and 'device_orientation' fields; you can't use just one of them"), } } - return nil - } diff --git a/testing/newrelic.tf b/testing/newrelic.tf index 538f303f4..8f2e3ca63 100644 --- a/testing/newrelic.tf +++ b/testing/newrelic.tf @@ -14,22 +14,45 @@ provider "newrelic" { resource "newrelic_synthetics_script_monitor" "monitor" { status = "DISABLED" - name = "name1236891625" - type = "SCRIPT_BROWSER" + name = "name1236" + type = "SCRIPT_API" period = "EVERY_HOUR" script = "$browser.get('https://one.newrelic.com')" - +# browsers = ["CHROME", "FIREFOX"] +# devices = ["MOBILE_PORTRAIT","TABLET_LANDSCAPE"] enable_screenshot_on_failure_and_script = false - locations_public = ["AP_SOUTH_1"] -# browsers = ["CHROME"] -# devices = [ "MOBILE_PORTRAIT", "MOBILE_LANDSCAPE"] - runtime_type_version = "" - runtime_type = "" - script_language = "JAVASCRIPT" - use_unsupported_legacy_runtime = true + locations_public = ["AP_SOUTH_1","US_EAST_1"] + runtime_type_version = "16.10" + runtime_type = "NODE_API" + script_language = "JAVASCRIPT" +# device_orientation = "LANDSCAPE" +# device_type = "MOBILE" +# use_unsupported_legacy_runtime = true tag { key = "some_key" values = ["some_value"] } } + +resource "newrelic_synthetics_script_monitor" "monitor2" { + status = "DISABLED" + name = "name1237" + type = "SCRIPT_BROWSER" + period = "EVERY_HOUR" + script = "$browser.get('https://one.newrelic.com')" +# browsers = ["CHROME", "FIREFOX"] +# devices = ["MOBILE_PORTRAIT","TABLET_LANDSCAPE"] + enable_screenshot_on_failure_and_script = false + locations_public = ["AP_SOUTH_1","US_EAST_1"] + runtime_type_version = "100" + runtime_type = "CHROME_BROWSER" + script_language = "JAVASCRIPT" + device_orientation = "LANDSCAPE" + device_type = "MOBILE" +# use_unsupported_legacy_runtime = true + tag { + key = "some_key" + values = ["some_value"] + } +} From 436dda5cea71435918c06731bf297625520e56e3 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Mon, 9 Sep 2024 22:44:04 +0530 Subject: [PATCH 14/21] chore(synthetics): diffsupress solution final changes --- newrelic/resource_helpers_synthetics.go | 11 ----- .../resource_newrelic_synthetics_monitor.go | 11 ++--- ...urce_newrelic_synthetics_script_monitor.go | 7 ++- ...source_newrelic_synthetics_step_monitor.go | 9 +--- ...thetics_all_monitors_validation_helpers.go | 20 ++++---- ...relic_synthetics_script_browser_monitor.go | 27 +++++------ testing/newrelic.tf | 47 ------------------- 7 files changed, 26 insertions(+), 106 deletions(-) diff --git a/newrelic/resource_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index dc829e439..b46b420fa 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -589,16 +589,6 @@ func syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor(k, oldValue, new return false } -func setBrowsersDevicesIfNotPresent(d *schema.ResourceData) { - // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes to avoid Drift - if _, ok := d.GetOk("browsers"); !ok { - _ = d.Set("browsers", []string{}) - } - if _, ok := d.GetOk("devices"); !ok { - _ = d.Set("devices", []string{}) - } -} - func multiBrowsersDevicesDiffSuppressor(k, oldValue, newValue string, d *schema.ResourceData) bool { rawConfiguration := d.GetRawConfig() runtimeTypeInConfig := rawConfiguration.GetAttr(SyntheticsRuntimeTypeAttrLabel) @@ -623,6 +613,5 @@ func multiBrowsersDevicesDiffSuppressor(k, oldValue, newValue string, d *schema. } isFieldPresent := rawConfiguration.GetAttr(attributeName).IsNull() - return isFieldPresent } diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index eeb2315a9..ff1c1ba95 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -246,8 +246,6 @@ func setAttributesFromCreate(res *synthetics.SyntheticsSimpleBrowserMonitorCreat _ = d.Set("locations_private", res.Monitor.Locations.Private) _ = d.Set("device_orientation", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceOrientation) _ = d.Set("device_type", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceType) - _ = d.Set("browsers", res.Monitor.Browsers) - _ = d.Set("devices", res.Monitor.Devices) if res.Monitor.Runtime.RuntimeType != "" { _ = d.Set("runtime_type", res.Monitor.Runtime.RuntimeType) } @@ -314,7 +312,9 @@ func setCommonSyntheticsMonitorAttributes(v *entities.EntityInterface, d *schema for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { if t.Key == "browsers" || t.Key == "devices" { - _ = d.Set(k, t.Values) + if len(d.Get(t.Key).(*schema.Set).List()) > 0 { + _ = d.Set(k, t.Values) + } } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } @@ -322,9 +322,6 @@ func setCommonSyntheticsMonitorAttributes(v *entities.EntityInterface, d *schema } } - // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes - setBrowsersDevicesIfNotPresent(d) - for _, t := range e.Tags { if t.Key == "responseValidationText" { if len(t.Values) == 1 { @@ -427,8 +424,6 @@ func setSimpleBrowserAttributesFromUpdate(res *synthetics.SyntheticsSimpleBrowse _ = d.Set("locations_private", res.Monitor.Locations.Private) _ = d.Set("device_orientation", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceOrientation) _ = d.Set("device_type", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceType) - _ = d.Set("browsers", res.Monitor.Browsers) - _ = d.Set("devices", res.Monitor.Devices) if res.Monitor.Runtime.RuntimeType != "" { _ = d.Set("runtime_type", res.Monitor.Runtime.RuntimeType) } diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index b587f8b56..83107fad0 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -233,7 +233,9 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { if t.Key == "devices" || t.Key == "browsers" { - _ = d.Set(k, t.Values) + if len(d.Get(t.Key).(*schema.Set).List()) > 0 { + _ = d.Set(k, t.Values) + } } else if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } @@ -241,9 +243,6 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. } } - // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes - //setBrowsersDevicesIfNotPresent(d) - return diag.FromErr(err) } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index 15b697bb4..19acb737e 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -150,8 +150,6 @@ func resourceNewRelicSyntheticsStepMonitorCreate(ctx context.Context, d *schema. if respRuntimeTypeVersion != "" { _ = d.Set("runtime_type_version", respRuntimeTypeVersion) } - _ = d.Set("browsers", resp.Monitor.Browsers) - _ = d.Set("devices", resp.Monitor.Devices) return diag.FromErr(err) } @@ -202,13 +200,10 @@ func resourceNewRelicSyntheticsStepMonitorRead(ctx context.Context, d *schema.Re _ = d.Set("runtime_type_version", runtimeTypeVersion) } for _, t := range e.Tags { - if t.Key == "devices" || t.Key == "browsers" { + if (t.Key == "devices" || t.Key == "browsers") && len(d.Get(t.Key).(*schema.Set).List()) > 0 { _ = d.Set(t.Key, t.Values) } } - - // Ensure Browsers, Devices fields are set to empty if not set, as they are computed type attributes - setBrowsersDevicesIfNotPresent(d) } return diag.FromErr(err) } @@ -252,8 +247,6 @@ func resourceNewRelicSyntheticsStepMonitorUpdate(ctx context.Context, d *schema. if respRuntimeTypeVersion != "" { _ = d.Set("runtime_type_version", respRuntimeTypeVersion) } - _ = d.Set("browsers", resp.Monitor.Browsers) - _ = d.Set("devices", resp.Monitor.Devices) return diag.FromErr(err) } diff --git a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go index bc9ca1e00..8e71086f4 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -18,10 +18,10 @@ func validateSyntheticMonitorAttributes(ctx context.Context, d *schema.ResourceD _, monitorType := d.GetChange("type") isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") if isBrowserMonitor { - err = validateDevicesFields(d) - } - if err != nil { - errorsList = append(errorsList, err...) + err := validateDevicesFields(d) + if err != nil { + errorsList = append(errorsList, err) + } } if len(errorsList) == 0 { @@ -163,7 +163,7 @@ https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/guides/syn // The following function will validate the device fields at the Terraform plan, ensuring that the user specifies // either the devices field alone or both the device_type and device_orientation fields -func validateDevicesFields(d *schema.ResourceDiff) []error { +func validateDevicesFields(d *schema.ResourceDiff) error { rawConfiguration := d.GetRawConfig() // GetAttr func will get below fields corresponding values from raw configuration that is from terraform configuration file @@ -172,17 +172,13 @@ func validateDevicesFields(d *schema.ResourceDiff) []error { deviceOrientationIsNil := rawConfiguration.GetAttr("device_orientation").IsNull() if !devicesIsNil && !(deviceTypeIsNil && deviceOrientationIsNil) { - return []error{ - fmt.Errorf(`Cannot use 'devices', 'device_type', and 'device_orientation' simultaneously. + return fmt.Errorf(`Cannot use 'devices', 'device_type', and 'device_orientation' simultaneously. Use either 'devices' alone or both 'device_type' and 'device_orientation' fields together. - We recommend using the 'devices' field, as it allows you to select multiple combinations of device types and orientations.`), - } + We recommend using the 'devices' field, as it allows you to select multiple combinations of device types and orientations.`) } if deviceTypeIsNil != deviceOrientationIsNil { - return []error{ - fmt.Errorf("you need to specify both 'device_type' and 'device_orientation' fields; you can't use just one of them"), - } + return fmt.Errorf("you need to specify both 'device_type' and 'device_orientation' fields; you can't use just one of them") } return nil } diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index d99917cfc..fb876e487 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -24,14 +24,12 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics if v, ok := d.GetOk("locations_public"); ok { input.Locations.Public = expandSyntheticsPublicLocations(v.(*schema.Set).List()) } - if v, ok := d.GetOk("browsers"); ok { - typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) - input.Browsers = &typedBrowsers - } - if v, ok := d.GetOk("devices"); ok { - typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) - input.Devices = &typedDevices - } + + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + input.Browsers = &typedBrowsers + + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + input.Devices = &typedDevices sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") @@ -97,14 +95,11 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. input.Locations.Private = expandSyntheticsPrivateLocations(v.(*schema.Set).List()) } - if v, ok := d.GetOk("browsers"); ok { - typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) - input.Browsers = &typedBrowsers - } - if v, ok := d.GetOk("devices"); ok { - typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) - input.Devices = &typedDevices - } + typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) + input.Browsers = &typedBrowsers + + typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) + input.Devices = &typedDevices sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") diff --git a/testing/newrelic.tf b/testing/newrelic.tf index 8f2e3ca63..ce4e4816f 100644 --- a/testing/newrelic.tf +++ b/testing/newrelic.tf @@ -9,50 +9,3 @@ terraform { provider "newrelic" { region = "US" # US or EU } - - - -resource "newrelic_synthetics_script_monitor" "monitor" { - status = "DISABLED" - name = "name1236" - type = "SCRIPT_API" - period = "EVERY_HOUR" - script = "$browser.get('https://one.newrelic.com')" -# browsers = ["CHROME", "FIREFOX"] -# devices = ["MOBILE_PORTRAIT","TABLET_LANDSCAPE"] - enable_screenshot_on_failure_and_script = false - locations_public = ["AP_SOUTH_1","US_EAST_1"] - runtime_type_version = "16.10" - runtime_type = "NODE_API" - script_language = "JAVASCRIPT" -# device_orientation = "LANDSCAPE" -# device_type = "MOBILE" -# use_unsupported_legacy_runtime = true - tag { - key = "some_key" - values = ["some_value"] - } -} - - -resource "newrelic_synthetics_script_monitor" "monitor2" { - status = "DISABLED" - name = "name1237" - type = "SCRIPT_BROWSER" - period = "EVERY_HOUR" - script = "$browser.get('https://one.newrelic.com')" -# browsers = ["CHROME", "FIREFOX"] -# devices = ["MOBILE_PORTRAIT","TABLET_LANDSCAPE"] - enable_screenshot_on_failure_and_script = false - locations_public = ["AP_SOUTH_1","US_EAST_1"] - runtime_type_version = "100" - runtime_type = "CHROME_BROWSER" - script_language = "JAVASCRIPT" - device_orientation = "LANDSCAPE" - device_type = "MOBILE" -# use_unsupported_legacy_runtime = true - tag { - key = "some_key" - values = ["some_value"] - } -} From 87090d57417122fb099d902aeae097aa0af8b973 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Mon, 9 Sep 2024 22:52:12 +0530 Subject: [PATCH 15/21] Revert "chore(synthetics): merged facilitate-runtime-downgrade-simple-scripted-monitors into working branch" This reverts commit 803e1e7d6fe91e9e52c9f62c2d91e0a1ed6d18dc, reversing changes made to 8cfbbc3ffb4ea51b17192c70e81b55673259b75f. --- ...uctures_newrelic_synthetics_script_api_monitor.go | 12 ++++-------- ...res_newrelic_synthetics_script_browser_monitor.go | 12 ++++-------- ...res_newrelic_synthetics_simple_browser_monitor.go | 6 ++---- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/newrelic/structures_newrelic_synthetics_script_api_monitor.go b/newrelic/structures_newrelic_synthetics_script_api_monitor.go index e096a61fc..f7bc25ce8 100644 --- a/newrelic/structures_newrelic_synthetics_script_api_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_api_monitor.go @@ -27,8 +27,9 @@ func buildSyntheticsScriptAPIMonitorInput(d *schema.ResourceData) synthetics.Syn _, runtimeTypeOk := d.GetOk("runtime_type") _, runtimeVersionOk := d.GetOk("runtime_type_version") - input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeVersionOk { + input.Runtime = &synthetics.SyntheticsRuntimeInput{} + if v, ok := d.GetOk("script_language"); ok { input.Runtime.ScriptLanguage = v.(string) } @@ -38,9 +39,6 @@ func buildSyntheticsScriptAPIMonitorInput(d *schema.ResourceData) synthetics.Syn if v, ok := d.GetOk("runtime_type_version"); ok { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(v.(string)) } - } else { - input.Runtime.RuntimeType = "" - input.Runtime.RuntimeTypeVersion = "" } return input @@ -68,8 +66,9 @@ func buildSyntheticsScriptAPIMonitorUpdateInput(d *schema.ResourceData) syntheti _, runtimeTypeOk := d.GetOk("runtime_type") _, runtimeVersionOk := d.GetOk("runtime_type_version") - input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeVersionOk { + input.Runtime = &synthetics.SyntheticsRuntimeInput{} + if v, ok := d.GetOk("script_language"); ok { input.Runtime.ScriptLanguage = v.(string) } @@ -79,9 +78,6 @@ func buildSyntheticsScriptAPIMonitorUpdateInput(d *schema.ResourceData) syntheti if v, ok := d.GetOk("runtime_type_version"); ok { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(v.(string)) } - } else { - input.Runtime.RuntimeType = "" - input.Runtime.RuntimeTypeVersion = "" } return input diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index fb876e487..f8c0dc563 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -35,8 +35,9 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") - input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { + input.Runtime = &synthetics.SyntheticsRuntimeInput{} + if scriptLangOk { input.Runtime.ScriptLanguage = sciptLang.(string) } @@ -48,9 +49,6 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics if runtimeTypeVersionOk { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } - } else { - input.Runtime.RuntimeType = "" - input.Runtime.RuntimeTypeVersion = "" } enableScreenshot := d.Get("enable_screenshot_on_failure_and_script").(bool) @@ -104,8 +102,9 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") - input.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { + input.Runtime = &synthetics.SyntheticsRuntimeInput{} + if scriptLangOk { input.Runtime.ScriptLanguage = sciptLang.(string) } @@ -117,9 +116,6 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. if runtimeTypeVersionOk { input.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } - } else { - input.Runtime.RuntimeType = "" - input.Runtime.RuntimeTypeVersion = "" } enableScreenshot := d.Get("enable_screenshot_on_failure_and_script").(bool) diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index 41686a652..e1ad0c257 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -66,8 +66,9 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d *schema.Reso runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") - simpleBrowserMonitorInput.Runtime = &synthetics.SyntheticsRuntimeInput{} if scriptLangOk || runtimeTypeOk || runtimeTypeVersionOk { + simpleBrowserMonitorInput.Runtime = &synthetics.SyntheticsRuntimeInput{} + if scriptLangOk { simpleBrowserMonitorInput.Runtime.ScriptLanguage = scriptLang.(string) } @@ -79,9 +80,6 @@ func buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d *schema.Reso if runtimeTypeVersionOk { simpleBrowserMonitorInput.Runtime.RuntimeTypeVersion = synthetics.SemVer(runtimeTypeVersion.(string)) } - } else { - simpleBrowserMonitorInput.Runtime.RuntimeType = "" - simpleBrowserMonitorInput.Runtime.RuntimeTypeVersion = "" } do, doOk := d.GetOk("device_orientation") From bab7afe0df20553a467b06445499eb6c9817b82a Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 10 Sep 2024 10:49:08 +0530 Subject: [PATCH 16/21] feat(synthetics): multibrowsers final set of changes with native approach --- go.mod | 2 - go.sum | 1 + newrelic/resource_helpers_synthetics.go | 31 ------------- .../resource_newrelic_synthetics_monitor.go | 6 +-- ...source_newrelic_synthetics_monitor_test.go | 18 +++----- ...urce_newrelic_synthetics_script_monitor.go | 11 ++--- ...thetics_script_monitor_integration_test.go | 44 +------------------ ...source_newrelic_synthetics_step_monitor.go | 7 +-- ...e_newrelic_synthetics_step_monitor_test.go | 4 +- ...thetics_all_monitors_validation_helpers.go | 13 +++--- .../docs/r/synthetics_monitor.html.markdown | 4 +- .../r/synthetics_script_monitor.html.markdown | 4 +- .../r/synthetics_step_monitor.html.markdown | 8 ++-- 13 files changed, 36 insertions(+), 117 deletions(-) diff --git a/go.mod b/go.mod index d02352fac..48fc1e9a6 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/newrelic/terraform-provider-newrelic/v2 go 1.21 -replace github.com/newrelic/newrelic-client-go/v2 => ../newrelic-client-go - require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index f2494bcd4..49bc74dfa 100644 --- a/go.sum +++ b/go.sum @@ -270,6 +270,7 @@ 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.44.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= 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_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index b46b420fa..127b894ce 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -137,7 +137,6 @@ var browsersSchema = &schema.Schema{ Optional: true, Description: "The multiple browsers list on which synthetic monitors will run. Valid values are array of CHROME," + "and FIREFOX", - DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, } var devicesSchema = &schema.Schema{ Type: schema.TypeSet, @@ -146,7 +145,6 @@ var devicesSchema = &schema.Schema{ Optional: true, Description: "The multiple devices list on which synthetic monitors will run. Valid values are array of DESKTOP," + " MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE and TABLET_PORTRAIT", - DiffSuppressFunc: multiBrowsersDevicesDiffSuppressor, } var syntheticsMonitorPeriodValueMap = map[int]synthetics.SyntheticsMonitorPeriod{ @@ -546,8 +544,6 @@ var syntheticsMonitorTagKeyToSchemaAttrMap = map[string]string{ "scriptLanguage": "script_language", "deviceOrientation": "device_orientation", "deviceType": "device_type", - "browsers": "browsers", - "devices": "devices", } func getCertCheckMonitorValuesFromEntityTags(tags []entities.EntityTag) (domain string, daysUntilExpiration int) { @@ -588,30 +584,3 @@ func syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor(k, oldValue, new return false } - -func multiBrowsersDevicesDiffSuppressor(k, oldValue, newValue string, d *schema.ResourceData) bool { - rawConfiguration := d.GetRawConfig() - runtimeTypeInConfig := rawConfiguration.GetAttr(SyntheticsRuntimeTypeAttrLabel) - isRuntimeTypeNil := runtimeTypeInConfig.IsNull() || runtimeTypeInConfig.AsString() == "" - - runtimeTypeVersionInConfig := rawConfiguration.GetAttr(SyntheticsRuntimeTypeVersionAttrLabel) - isRuntimeTypeVersionNil := runtimeTypeVersionInConfig.IsNull() || runtimeTypeVersionInConfig.AsString() == "" - - if isRuntimeTypeNil || isRuntimeTypeVersionNil { - return false - } - - _, monitorType := d.GetChange("type") - isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") - attributeName := strings.Split(k, ".")[0] - if attributeName == "devices" && isBrowserMonitor { - deviceTypeIsNil := rawConfiguration.GetAttr("device_type").IsNull() - deviceOrientationIsNil := rawConfiguration.GetAttr("device_orientation").IsNull() - if !deviceTypeIsNil && !deviceOrientationIsNil { - return false - } - } - - isFieldPresent := rawConfiguration.GetAttr(attributeName).IsNull() - return isFieldPresent -} diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index ff1c1ba95..51370dcb1 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -311,11 +311,7 @@ func setCommonSyntheticsMonitorAttributes(v *entities.EntityInterface, d *schema if e.MonitorType == entities.SyntheticMonitorTypeTypes.BROWSER { for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { - if t.Key == "browsers" || t.Key == "devices" { - if len(d.Get(t.Key).(*schema.Set).List()) > 0 { - _ = d.Set(k, t.Values) - } - } else if len(t.Values) == 1 { + if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } } diff --git a/newrelic/resource_newrelic_synthetics_monitor_test.go b/newrelic/resource_newrelic_synthetics_monitor_test.go index f17aad2c1..e60a56c48 100644 --- a/newrelic/resource_newrelic_synthetics_monitor_test.go +++ b/newrelic/resource_newrelic_synthetics_monitor_test.go @@ -30,7 +30,7 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationError(t *testing.T) // Test: Create { Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(rName, string(SyntheticsMonitorTypes.BROWSER)), - ExpectError: regexp.MustCompile(`both device_orientation and device_type should be specified to enable device emulation`), + ExpectError: regexp.MustCompile(`you need to specify both 'device_type' and 'device_orientation' fields`), }, }, }) @@ -54,7 +54,7 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationErrorUpdate(t *testi // Test: Update { Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(rName, string(SyntheticsMonitorTypes.BROWSER)), - ExpectError: regexp.MustCompile(`both device_orientation and device_type should be specified to enable device emulation`), + ExpectError: regexp.MustCompile(`you need to specify both 'device_type' and 'device_orientation'`), }, }, }) @@ -288,8 +288,8 @@ func TestAccNewRelicSyntheticsSimpleBrowserMonitor(t *testing.T) { "device_orientation", "device_type", SyntheticsUseLegacyRuntimeAttrLabel, - "devices", "browsers", + "devices", }, }, }, @@ -307,8 +307,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp name = "customer-header-2" value = "header-value-2" } - devices = ["MOBILE_LANDSCAPE","MOBILE_PORTRAIT"] - browsers = ["CHROME","FIREFOX"] + browsers = ["CHROME", "FIREFOX"] + devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"] enable_screenshot_on_failure_and_script = true validation_string = "success" verify_ssl = true @@ -321,8 +321,6 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp status = "ENABLED" type = "%s" uri = "https://www.one.newrelic.com" - device_orientation = "PORTRAIT" - device_type = "MOBILE" }`, name, monitorType) } @@ -333,8 +331,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfigUpdated(name string, mon name = "name" value = "simple_browser" } - devices = ["MOBILE_LANDSCAPE"] - browsers = ["CHROME"] + browsers = ["CHROME"] + devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] enable_screenshot_on_failure_and_script = false validation_string = "success" verify_ssl = false @@ -347,8 +345,6 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfigUpdated(name string, mon status = "DISABLED" type = "%s" uri = "https://www.one.newrelic.com" - device_orientation = "LANDSCAPE" - device_type = "TABLET" }`, name, monitorType) } diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index 83107fad0..352cc9b56 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -170,8 +170,7 @@ func resourceNewRelicSyntheticsScriptMonitorCreate(ctx context.Context, d *schem d.SetId(string(resp.Monitor.GUID)) _ = d.Set("account_id", accountID) _ = d.Set("period_in_minutes", syntheticsMonitorPeriodInMinutesValueMap[resp.Monitor.Period]) - _ = d.Set("browsers", resp.Monitor.Browsers) - _ = d.Set("devices", resp.Monitor.Devices) + attrs := map[string]string{"guid": string(resp.Monitor.GUID)} if err = setSyntheticsMonitorAttributes(d, attrs); err != nil { return diag.FromErr(err) @@ -229,14 +228,12 @@ func resourceNewRelicSyntheticsScriptMonitorRead(ctx context.Context, d *schema. "period": string(syntheticsMonitorPeriodValueMap[int(e.GetPeriod())]), "status": string(e.MonitorSummary.Status), }) + _ = d.Set("period_in_minutes", int(e.GetPeriod())) + for _, t := range e.Tags { if k, ok := syntheticsMonitorTagKeyToSchemaAttrMap[t.Key]; ok { - if t.Key == "devices" || t.Key == "browsers" { - if len(d.Get(t.Key).(*schema.Set).List()) > 0 { - _ = d.Set(k, t.Values) - } - } else if len(t.Values) == 1 { + if len(t.Values) == 1 { _ = d.Set(k, t.Values[0]) } } diff --git a/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go b/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go index b60b72d6e..8607cd113 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go @@ -122,24 +122,6 @@ func testAccNewRelicSyntheticsScriptAPIMonitorConfig(name string, scriptMonitorT }`, name, scriptMonitorType) } -func testAccNewRelicSyntheticsScriptMonitorConfig(name string) string { - return fmt.Sprintf(` - resource "newrelic_synthetics_script_monitor" "foo" { - locations_public = [ - "EU_WEST_1", - "EU_WEST_2", - ] - name = "%s" - period = "EVERY_DAY" - script = "console.log('script update works!')" - status = "ENABLED" - type = "SCRIPT_BROWSER" - script_language = "JAVASCRIPT" - runtime_type = "`+SyntheticsChromeBrowserRuntimeType+`" - runtime_type_version = "`+SyntheticsChromeBrowserNewRuntimeTypeVersion+`" - }`, name) -} - func testAccNewRelicSyntheticsScriptBrowserMonitorConfig(name string) string { return fmt.Sprintf(` resource "newrelic_synthetics_script_monitor" "bar" { @@ -155,10 +137,8 @@ func testAccNewRelicSyntheticsScriptBrowserMonitorConfig(name string) string { script_language = "JAVASCRIPT" script = "$browser.get('https://one.newrelic.com')" - device_orientation = "PORTRAIT" - device_type = "MOBILE" - browsers = ["CHROME"] - devices = ["MOBILE_PORTRAIT"] + browsers = ["CHROME", "FIREFOX"] + devices = ["DESKTOP", "TABLET_LANDSCAPE", "MOBILE_PORTRAIT", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"] tag { key = "Name" values = ["scriptedMonitor"] @@ -235,23 +215,3 @@ func testAccCheckNewRelicSyntheticsScriptMonitorDestroy(s *terraform.State) erro } return nil } - -func TestAccNewRelicSyntheticsMonitorScriptUpdate(t *testing.T) { - resourceName := "newrelic_synthetics_script_monitor.foo" - rName := generateNameForIntegrationTestResource() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckEnvVars(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNewRelicSyntheticsScriptMonitorDestroy, - Steps: []resource.TestStep{ - - { - Config: testAccNewRelicSyntheticsScriptMonitorConfig(fmt.Sprintf(rName)), - Check: resource.ComposeTestCheckFunc( - testAccCheckNewRelicSyntheticsMonitorScriptUpdate(resourceName), - ), - }, - }, - }) -} diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index 19acb737e..6b8b252c1 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -150,6 +150,7 @@ func resourceNewRelicSyntheticsStepMonitorCreate(ctx context.Context, d *schema. if respRuntimeTypeVersion != "" { _ = d.Set("runtime_type_version", respRuntimeTypeVersion) } + return diag.FromErr(err) } @@ -199,11 +200,7 @@ func resourceNewRelicSyntheticsStepMonitorRead(ctx context.Context, d *schema.Re _ = d.Set("runtime_type", runtimeType) _ = d.Set("runtime_type_version", runtimeTypeVersion) } - for _, t := range e.Tags { - if (t.Key == "devices" || t.Key == "browsers") && len(d.Get(t.Key).(*schema.Set).List()) > 0 { - _ = d.Set(t.Key, t.Values) - } - } + } return diag.FromErr(err) } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor_test.go b/newrelic/resource_newrelic_synthetics_step_monitor_test.go index c09699cf6..42b2bdb55 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor_test.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor_test.go @@ -85,8 +85,8 @@ resource "newrelic_synthetics_step_monitor" "foo" { type = "NAVIGATE" values = ["https://google.com"] } - browsers = ["CHROME"] - devices = ["DESKTOP"] + browsers = ["CHROME", "FIREFOX"] + devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"] %[2]s } diff --git a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go index 8e71086f4..ff6ea1e2e 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -15,12 +15,15 @@ func validateSyntheticMonitorAttributes(ctx context.Context, d *schema.ResourceD if err != nil { errorsList = append(errorsList, err...) } + _, monitorType := d.GetChange("type") - isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") - if isBrowserMonitor { - err := validateDevicesFields(d) - if err != nil { - errorsList = append(errorsList, err) + if monitorType != nil { + isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") + if isBrowserMonitor { + err := validateDevicesFields(d) + if err != nil { + errorsList = append(errorsList, err) + } } } diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index 9fef5b025..961ae09bf 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -53,8 +53,8 @@ resource "newrelic_synthetics_monitor" "monitor" { name = "some_name" value = "some_value" } - devices = ["MOBILE_LANDSCAPE","MOBILE_PORTRAIT"] - browsers = ["CHROME","FIREFOX"] + devices = ["DESKTOP","TABLET_LANDSCAPE","MOBILE_PORTRAIT"] + browsers = ["CHROME"] enable_screenshot_on_failure_and_script = true validation_string = "success" verify_ssl = true diff --git a/website/docs/r/synthetics_script_monitor.html.markdown b/website/docs/r/synthetics_script_monitor.html.markdown index 1f000704c..f75828ae3 100644 --- a/website/docs/r/synthetics_script_monitor.html.markdown +++ b/website/docs/r/synthetics_script_monitor.html.markdown @@ -53,7 +53,7 @@ resource "newrelic_synthetics_script_monitor" "monitor" { runtime_type_version = "100" runtime_type = "CHROME_BROWSER" script_language = "JAVASCRIPT" - devices = ["DESKTOP", "MOBILE_LANDSCAPE", "TABLET_LANDSCAPE"] + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] browsers = ["CHROME"] tag { @@ -174,7 +174,7 @@ resource "newrelic_synthetics_script_monitor" "monitor" { runtime_type_version = "100" runtime_type = "CHROME_BROWSER" script_language = "JAVASCRIPT" - devices = ["DESKTOP", "MOBILE_LANDSCAPE", "TABLET_LANDSCAPE"] + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] browsers = ["CHROME"] tag { diff --git a/website/docs/r/synthetics_step_monitor.html.markdown b/website/docs/r/synthetics_step_monitor.html.markdown index b960a12b6..862cb7971 100644 --- a/website/docs/r/synthetics_step_monitor.html.markdown +++ b/website/docs/r/synthetics_step_monitor.html.markdown @@ -21,6 +21,8 @@ resource "newrelic_synthetics_step_monitor" "foo" { locations_public = ["US_EAST_1", "US_EAST_2"] period = "EVERY_6_HOURS" status = "ENABLED" + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] runtime_type = "CHROME_BROWSER" runtime_type_version = "100" steps { @@ -51,14 +53,14 @@ The following are the common arguments supported for `STEP` monitor: * `runtime_type` - (Optional) The runtime that the monitor will use to run jobs. * `runtime_type_version` - (Optional) The specific version of the runtime type selected. +* `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. +* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. -> **NOTE:** Currently, the values of `runtime_type` and `runtime_type_version` supported by this resource are `CHROME_BROWSER` and `100` respectively. In order to run the monitor in the new runtime, both `runtime_type` and `runtime_type_version` need to be specified; however, specifying neither of these attributes would set this monitor to use the legacy runtime. It may also be noted that the runtime opted for would only be effective with private locations. For public locations, all traffic has been shifted to the new runtime, irrespective of the selection made. -> **WARNING:** Support for using the Synthetics Legacy Runtime (deprecated) with **new** Synthetic monitors **has officially ended as of August 26, 2024**. As a consequence, starting with v3.43.0 of the New Relic Terraform Provider, **new** Synthetic monitors **will no longer be allowed to use the legacy runtime** (this applies to all Synthetic monitor resources). Additionally, as previously communicated by New Relic, the Synthetics Legacy Runtime **will reach its end-of-life (EOL) on October 22, 2024**. In light of the above, we kindly recommend that you upgrade your Synthetic Monitors to the new runtime at the earliest, if they are still using the legacy runtime. Please check out [this guide](https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/guides/synthetics_legacy_runtime_eol_migration_guide) in the documentation of the Terraform Provider and [this announcement](https://forum.newrelic.com/s/hubtopic/aAXPh0000001brxOAA/upcoming-endoflife-legacy-synthetics-runtimes-and-cpm) for more details on the EOL, action needed, relevant resources, and more. * `steps` - (Required) The steps that make up the script the monitor will run. See [Nested steps blocks](#nested-steps-blocks) below for details. -* `browsers` - (Optional) The multiple browsers list on which synthetic monitors will run. Valid values are `CHROME` and `FIREFOX`. -* `devices` - (Optional) The multiple devices list on which synthetic monitors will run. Valid values are `DESKTOP`, `MOBILE_LANDSCAPE`, `MOBILE_PORTRAIT`, `TABLET_LANDSCAPE` and `TABLET_PORTRAIT`. * `tag` - (Optional) The tags that will be associated with the monitor. See [Nested tag blocks](#nested-tag-blocks) below for details. ### Nested `location private` blocks @@ -102,7 +104,7 @@ resource "newrelic_synthetics_step_monitor" "foo" { name = "Sample Step Monitor" period = "EVERY_6_HOURS" status = "ENABLED" - devices = ["DESKTOP", "MOBILE_LANDSCAPE", "TABLET_LANDSCAPE"] + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] browsers = ["CHROME"] location_private { guid = newrelic_synthetics_private_location.foo.id From d65f87d0c5b102cbcfd18fe39f547e8daa8ed71b Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 10 Sep 2024 10:56:04 +0530 Subject: [PATCH 17/21] chore(synthetics): reverted go.sum change --- go.sum | 1 + newrelic/resource_newrelic_synthetics_monitor.go | 2 ++ newrelic/resource_newrelic_synthetics_step_monitor.go | 2 ++ 3 files changed, 5 insertions(+) diff --git a/go.sum b/go.sum index 49bc74dfa..30b796c41 100644 --- a/go.sum +++ b/go.sum @@ -270,6 +270,7 @@ 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.44.0 h1:n4zP64Hfui8pjW/D3tbE1Hi+Acbpz8nBIrI2miEAGiI= github.com/newrelic/newrelic-client-go/v2 v2.44.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= diff --git a/newrelic/resource_newrelic_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index 51370dcb1..d2a4facd2 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -246,6 +246,7 @@ func setAttributesFromCreate(res *synthetics.SyntheticsSimpleBrowserMonitorCreat _ = d.Set("locations_private", res.Monitor.Locations.Private) _ = d.Set("device_orientation", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceOrientation) _ = d.Set("device_type", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceType) + if res.Monitor.Runtime.RuntimeType != "" { _ = d.Set("runtime_type", res.Monitor.Runtime.RuntimeType) } @@ -420,6 +421,7 @@ func setSimpleBrowserAttributesFromUpdate(res *synthetics.SyntheticsSimpleBrowse _ = d.Set("locations_private", res.Monitor.Locations.Private) _ = d.Set("device_orientation", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceOrientation) _ = d.Set("device_type", res.Monitor.AdvancedOptions.DeviceEmulation.DeviceType) + if res.Monitor.Runtime.RuntimeType != "" { _ = d.Set("runtime_type", res.Monitor.Runtime.RuntimeType) } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor.go b/newrelic/resource_newrelic_synthetics_step_monitor.go index 6b8b252c1..1afce2d12 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor.go @@ -202,6 +202,7 @@ func resourceNewRelicSyntheticsStepMonitorRead(ctx context.Context, d *schema.Re } } + return diag.FromErr(err) } @@ -244,6 +245,7 @@ func resourceNewRelicSyntheticsStepMonitorUpdate(ctx context.Context, d *schema. if respRuntimeTypeVersion != "" { _ = d.Set("runtime_type_version", respRuntimeTypeVersion) } + return diag.FromErr(err) } From 1316a16543036a36821b4901bf220488e87d3888 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 10 Sep 2024 15:59:23 +0530 Subject: [PATCH 18/21] fix(synthetics): compilation errors fix --- go.mod | 2 +- go.sum | 4 ++-- ...ructures_newrelic_synthetics_script_browser_monitor.go | 8 ++++---- ...ructures_newrelic_synthetics_simple_browser_monitor.go | 8 ++++---- newrelic/structures_newrelic_synthetics_step_monitor.go | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 48fc1e9a6..7a8e63b84 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,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.44.0 + github.com/newrelic/newrelic-client-go/v2 v2.44.1-0.20240910101818-a331fd8a0d48 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 30b796c41..9d2e731c9 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.44.0 h1:n4zP64Hfui8pjW/D3tbE1Hi+Acbpz8nBIrI2miEAGiI= -github.com/newrelic/newrelic-client-go/v2 v2.44.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= +github.com/newrelic/newrelic-client-go/v2 v2.44.1-0.20240910101818-a331fd8a0d48 h1:cy3B2BULTzfOm93HQC6Fu5QHJJcmO+uUNEtN/5s/jhE= +github.com/newrelic/newrelic-client-go/v2 v2.44.1-0.20240910101818-a331fd8a0d48/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= 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/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index f8c0dc563..e800b8755 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -26,10 +26,10 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics } typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = &typedBrowsers + input.Browsers = typedBrowsers typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = &typedDevices + input.Devices = typedDevices sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") @@ -94,10 +94,10 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. } typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = &typedBrowsers + input.Browsers = typedBrowsers typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = &typedDevices + input.Devices = typedDevices sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index e1ad0c257..97e701116 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -48,10 +48,10 @@ func buildSyntheticsSimpleBrowserMonitor(d *schema.ResourceData) (synthetics.Syn } typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - simpleBrowserMonitorInput.Browsers = &typedBrowsers + simpleBrowserMonitorInput.Browsers = typedBrowsers typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - simpleBrowserMonitorInput.Devices = &typedDevices + simpleBrowserMonitorInput.Devices = typedDevices err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d, simpleBrowserMonitorInput) if err != nil { @@ -144,10 +144,10 @@ func buildSyntheticsSimpleBrowserMonitorUpdateStruct(d *schema.ResourceData) (sy } typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - simpleBrowserMonitorUpdateInput.Browsers = &typedBrowsers + simpleBrowserMonitorUpdateInput.Browsers = typedBrowsers typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - simpleBrowserMonitorUpdateInput.Devices = &typedDevices + simpleBrowserMonitorUpdateInput.Devices = typedDevices err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d, simpleBrowserMonitorUpdateInput) if err != nil { diff --git a/newrelic/structures_newrelic_synthetics_step_monitor.go b/newrelic/structures_newrelic_synthetics_step_monitor.go index 56a1125e9..a547904ae 100644 --- a/newrelic/structures_newrelic_synthetics_step_monitor.go +++ b/newrelic/structures_newrelic_synthetics_step_monitor.go @@ -32,10 +32,10 @@ func buildSyntheticsStepMonitorCreateInput(d *schema.ResourceData) (*synthetics. } typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = &typedBrowsers + input.Browsers = typedBrowsers typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = &typedDevices + input.Devices = typedDevices runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -83,10 +83,10 @@ func buildSyntheticsStepMonitorUpdateInput(d *schema.ResourceData) (*synthetics. } typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = &typedBrowsers + input.Browsers = typedBrowsers typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = &typedDevices + input.Devices = typedDevices runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") From d1c090f9e49c4d0086fb5dd12462e094c4357f09 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 10 Sep 2024 16:11:48 +0530 Subject: [PATCH 19/21] chore(lint): lint issue fix --- ...s_newrelic_synthetics_all_monitors_validation_helpers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go index ff6ea1e2e..22a2309e4 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -175,9 +175,9 @@ func validateDevicesFields(d *schema.ResourceDiff) error { deviceOrientationIsNil := rawConfiguration.GetAttr("device_orientation").IsNull() if !devicesIsNil && !(deviceTypeIsNil && deviceOrientationIsNil) { - return fmt.Errorf(`Cannot use 'devices', 'device_type', and 'device_orientation' simultaneously. - Use either 'devices' alone or both 'device_type' and 'device_orientation' fields together. - We recommend using the 'devices' field, as it allows you to select multiple combinations of device types and orientations.`) + return fmt.Errorf(`cannot use 'devices', 'device_type', and 'device_orientation' simultaneously + use either 'devices' alone or both 'device_type' and 'device_orientation' fields together + we recommend using the 'devices' field, as it allows you to select multiple combinations of device types and orientations`) } if deviceTypeIsNil != deviceOrientationIsNil { From 417555e02608325e475fd944718fcfe8ef745afd Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 10 Sep 2024 23:21:22 +0530 Subject: [PATCH 20/21] chore(synthetics): pointed client-go changes --- go.mod | 2 +- go.sum | 4 ++-- .../resource_newrelic_synthetics_monitor.go | 14 ++++++----- ...urce_newrelic_synthetics_script_monitor.go | 14 ++++++----- ...thetics_all_monitors_validation_helpers.go | 4 ---- ...relic_synthetics_script_browser_monitor.go | 24 ++++++++++++------- ...relic_synthetics_simple_browser_monitor.go | 24 ++++++++++++------- ...ctures_newrelic_synthetics_step_monitor.go | 24 ++++++++++++------- 8 files changed, 67 insertions(+), 43 deletions(-) diff --git a/go.mod b/go.mod index 7a8e63b84..26f1b08c2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,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.44.1-0.20240910101818-a331fd8a0d48 + github.com/newrelic/newrelic-client-go/v2 v2.45.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 9d2e731c9..065b3210d 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.44.1-0.20240910101818-a331fd8a0d48 h1:cy3B2BULTzfOm93HQC6Fu5QHJJcmO+uUNEtN/5s/jhE= -github.com/newrelic/newrelic-client-go/v2 v2.44.1-0.20240910101818-a331fd8a0d48/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= +github.com/newrelic/newrelic-client-go/v2 v2.45.0 h1:3zaJqE4V2n07b8Fx3byV+WeJSdeTeR4sW6yVSXrrNN4= +github.com/newrelic/newrelic-client-go/v2 v2.45.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4= 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_synthetics_monitor.go b/newrelic/resource_newrelic_synthetics_monitor.go index d2a4facd2..6f8e54d23 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -168,14 +168,16 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource { }, }, "device_orientation": { - Type: schema.TypeString, - Optional: true, - Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.", + Type: schema.TypeString, + Optional: true, + RequiredWith: []string{"device_type"}, + Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.", }, "device_type": { - Type: schema.TypeString, - Optional: true, - Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", + Type: schema.TypeString, + Optional: true, + RequiredWith: []string{"device_orientation"}, + Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", }, }, CustomizeDiff: validateSyntheticMonitorAttributes, diff --git a/newrelic/resource_newrelic_synthetics_script_monitor.go b/newrelic/resource_newrelic_synthetics_script_monitor.go index 352cc9b56..81c7b89a6 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor.go @@ -75,14 +75,16 @@ func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Sc "browsers": browsersSchema, "devices": devicesSchema, "device_orientation": { - Type: schema.TypeString, - Optional: true, - Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.", + Type: schema.TypeString, + Optional: true, + RequiredWith: []string{"device_type"}, + Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.", }, "device_type": { - Type: schema.TypeString, - Optional: true, - Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", + Type: schema.TypeString, + Optional: true, + RequiredWith: []string{"device_orientation"}, + Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.", }, } } diff --git a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go index 22a2309e4..254635ffa 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -179,9 +179,5 @@ func validateDevicesFields(d *schema.ResourceDiff) error { use either 'devices' alone or both 'device_type' and 'device_orientation' fields together we recommend using the 'devices' field, as it allows you to select multiple combinations of device types and orientations`) } - - if deviceTypeIsNil != deviceOrientationIsNil { - return fmt.Errorf("you need to specify both 'device_type' and 'device_orientation' fields; you can't use just one of them") - } return nil } diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index e800b8755..7171bc2c4 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -25,11 +25,15 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics input.Locations.Public = expandSyntheticsPublicLocations(v.(*schema.Set).List()) } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = typedBrowsers + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + input.Browsers = typedBrowsers + } - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = typedDevices + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + input.Devices = typedDevices + } sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") @@ -93,11 +97,15 @@ func buildSyntheticsScriptBrowserUpdateInput(d *schema.ResourceData) synthetics. input.Locations.Private = expandSyntheticsPrivateLocations(v.(*schema.Set).List()) } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = typedBrowsers + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + input.Browsers = typedBrowsers + } - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = typedDevices + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + input.Devices = typedDevices + } sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") diff --git a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index 97e701116..f4ee85458 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -47,11 +47,15 @@ func buildSyntheticsSimpleBrowserMonitor(d *schema.ResourceData) (synthetics.Syn simpleBrowserMonitorInput.AdvancedOptions.UseTlsValidation = &vs } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - simpleBrowserMonitorInput.Browsers = typedBrowsers + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + simpleBrowserMonitorInput.Browsers = typedBrowsers + } - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - simpleBrowserMonitorInput.Devices = typedDevices + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + simpleBrowserMonitorInput.Devices = typedDevices + } err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d, simpleBrowserMonitorInput) if err != nil { @@ -143,11 +147,15 @@ func buildSyntheticsSimpleBrowserMonitorUpdateStruct(d *schema.ResourceData) (sy simpleBrowserMonitorUpdateInput.AdvancedOptions.UseTlsValidation = &vs } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - simpleBrowserMonitorUpdateInput.Browsers = typedBrowsers + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + simpleBrowserMonitorUpdateInput.Browsers = typedBrowsers + } - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - simpleBrowserMonitorUpdateInput.Devices = typedDevices + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + simpleBrowserMonitorUpdateInput.Devices = typedDevices + } err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d, simpleBrowserMonitorUpdateInput) if err != nil { diff --git a/newrelic/structures_newrelic_synthetics_step_monitor.go b/newrelic/structures_newrelic_synthetics_step_monitor.go index a547904ae..9353eb09d 100644 --- a/newrelic/structures_newrelic_synthetics_step_monitor.go +++ b/newrelic/structures_newrelic_synthetics_step_monitor.go @@ -31,11 +31,15 @@ func buildSyntheticsStepMonitorCreateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = typedBrowsers + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + input.Browsers = typedBrowsers + } - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = typedDevices + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + input.Devices = typedDevices + } runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -82,11 +86,15 @@ func buildSyntheticsStepMonitorUpdateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } - typedBrowsers := expandSyntheticsBrowsers(d.Get("browsers").(*schema.Set).List()) - input.Browsers = typedBrowsers + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + input.Browsers = typedBrowsers + } - typedDevices := expandSyntheticsDevices(d.Get("devices").(*schema.Set).List()) - input.Devices = typedDevices + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + input.Devices = typedDevices + } runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") From 0adf85987107d28cf3ef2647948390c59a7cafae Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Wed, 11 Sep 2024 10:56:02 +0530 Subject: [PATCH 21/21] fix(tests): integration tests fixed --- ...source_newrelic_synthetics_monitor_test.go | 13 +++-- .../docs/r/synthetics_monitor.html.markdown | 51 +++++++++---------- .../r/synthetics_script_monitor.html.markdown | 49 ++++++++---------- .../r/synthetics_step_monitor.html.markdown | 16 +++--- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/newrelic/resource_newrelic_synthetics_monitor_test.go b/newrelic/resource_newrelic_synthetics_monitor_test.go index e60a56c48..8bd569731 100644 --- a/newrelic/resource_newrelic_synthetics_monitor_test.go +++ b/newrelic/resource_newrelic_synthetics_monitor_test.go @@ -30,7 +30,7 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationError(t *testing.T) // Test: Create { Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(rName, string(SyntheticsMonitorTypes.BROWSER)), - ExpectError: regexp.MustCompile(`you need to specify both 'device_type' and 'device_orientation' fields`), + ExpectError: regexp.MustCompile("all of `device_orientation,device_type` must be\nspecified"), }, }, }) @@ -51,10 +51,17 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationErrorUpdate(t *testi testAccCheckNewRelicSyntheticsMonitorExists(resourceName), ), }, - // Test: Update + // Test: Update ; By removing device_type field { Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(rName, string(SyntheticsMonitorTypes.BROWSER)), - ExpectError: regexp.MustCompile(`you need to specify both 'device_type' and 'device_orientation'`), + ExpectError: regexp.MustCompile("all of `device_orientation,device_type` must be\nspecified"), + }, + // Test: Update ; Added back removed device_type field + { + Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulation(rName, string(SyntheticsMonitorTypes.BROWSER)), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicSyntheticsMonitorExists(resourceName), + ), }, }, }) diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index 961ae09bf..e2219e800 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -42,26 +42,24 @@ resource "newrelic_synthetics_monitor" "monitor" { ```hcl resource "newrelic_synthetics_monitor" "monitor" { - status = "ENABLED" - name = "monitor" - period = "EVERY_MINUTE" - uri = "https://www.one.newrelic.com" - type = "BROWSER" - locations_public = ["AP_SOUTH_1"] - - custom_header { - name = "some_name" - value = "some_value" - } - devices = ["DESKTOP","TABLET_LANDSCAPE","MOBILE_PORTRAIT"] - browsers = ["CHROME"] + status = "ENABLED" + name = "monitor" + period = "EVERY_MINUTE" + uri = "https://www.one.newrelic.com" + type = "BROWSER" + locations_public = ["AP_SOUTH_1"] enable_screenshot_on_failure_and_script = true validation_string = "success" verify_ssl = true runtime_type = "CHROME_BROWSER" runtime_type_version = "100" script_language = "JAVASCRIPT" - + devices = ["DESKTOP", "TABLET_LANDSCAPE", "MOBILE_PORTRAIT"] + browsers = ["CHROME"] + custom_header { + name = "some_name" + value = "some_value" + } tag { key = "some_key" values = ["some_value"] @@ -195,25 +193,24 @@ resource "newrelic_synthetics_private_location" "location" { } resource "newrelic_synthetics_monitor" "monitor" { - status = "ENABLED" - type = "BROWSER" - uri = "https://www.one.newrelic.com" - name = "monitor" - period = "EVERY_MINUTE" - locations_private = [newrelic_synthetics_private_location.location.id] - - custom_header { - name = "some_name" - value = "some_value" - } - + status = "ENABLED" + type = "BROWSER" + uri = "https://www.one.newrelic.com" + name = "monitor" + period = "EVERY_MINUTE" + locations_private = [newrelic_synthetics_private_location.location.id] enable_screenshot_on_failure_and_script = true validation_string = "success" verify_ssl = true runtime_type_version = "100" runtime_type = "CHROME_BROWSER" script_language = "JAVASCRIPT" - + devices = ["DESKTOP", "TABLET_LANDSCAPE", "MOBILE_PORTRAIT"] + browsers = ["CHROME"] + custom_header { + name = "some_name" + value = "some_value" + } tag { key = "some_key" values = ["some_value"] diff --git a/website/docs/r/synthetics_script_monitor.html.markdown b/website/docs/r/synthetics_script_monitor.html.markdown index f75828ae3..a8310ba6c 100644 --- a/website/docs/r/synthetics_script_monitor.html.markdown +++ b/website/docs/r/synthetics_script_monitor.html.markdown @@ -40,22 +40,18 @@ resource "newrelic_synthetics_script_monitor" "monitor" { ```hcl resource "newrelic_synthetics_script_monitor" "monitor" { - status = "ENABLED" - name = "script_monitor" - type = "SCRIPT_BROWSER" - locations_public = ["AP_SOUTH_1", "AP_EAST_1"] - period = "EVERY_HOUR" - + status = "ENABLED" + name = "script_monitor" + type = "SCRIPT_BROWSER" + locations_public = ["AP_SOUTH_1", "AP_EAST_1"] + period = "EVERY_HOUR" + script = "$browser.get('https://one.newrelic.com')" + runtime_type_version = "100" + runtime_type = "CHROME_BROWSER" + script_language = "JAVASCRIPT" + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] enable_screenshot_on_failure_and_script = false - - script = "$browser.get('https://one.newrelic.com')" - - runtime_type_version = "100" - runtime_type = "CHROME_BROWSER" - script_language = "JAVASCRIPT" - devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] - browsers = ["CHROME"] - tag { key = "some_key" values = ["some_value"] @@ -159,24 +155,21 @@ resource "newrelic_synthetics_private_location" "location" { } resource "newrelic_synthetics_script_monitor" "monitor" { - status = "ENABLED" - name = "script_monitor" - type = "SCRIPT_BROWSER" - period = "EVERY_HOUR" - script = "$browser.get('https://one.newrelic.com')" - + status = "ENABLED" + name = "script_monitor" + type = "SCRIPT_BROWSER" + period = "EVERY_HOUR" + script = "$browser.get('https://one.newrelic.com')" + runtime_type_version = "100" + runtime_type = "CHROME_BROWSER" + script_language = "JAVASCRIPT" + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] enable_screenshot_on_failure_and_script = false location_private { guid = newrelic_synthetics_private_location.location.id vse_password = "secret" } - - runtime_type_version = "100" - runtime_type = "CHROME_BROWSER" - script_language = "JAVASCRIPT" - devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] - browsers = ["CHROME"] - tag { key = "some_key" values = ["some_value"] diff --git a/website/docs/r/synthetics_step_monitor.html.markdown b/website/docs/r/synthetics_step_monitor.html.markdown index 862cb7971..e015a4f31 100644 --- a/website/docs/r/synthetics_step_monitor.html.markdown +++ b/website/docs/r/synthetics_step_monitor.html.markdown @@ -21,10 +21,10 @@ resource "newrelic_synthetics_step_monitor" "foo" { locations_public = ["US_EAST_1", "US_EAST_2"] period = "EVERY_6_HOURS" status = "ENABLED" - devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] - browsers = ["CHROME"] runtime_type = "CHROME_BROWSER" runtime_type_version = "100" + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] steps { ordinal = 0 type = "NAVIGATE" @@ -101,11 +101,13 @@ resource "newrelic_synthetics_private_location" "foo" { } resource "newrelic_synthetics_step_monitor" "foo" { - name = "Sample Step Monitor" - period = "EVERY_6_HOURS" - status = "ENABLED" - devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] - browsers = ["CHROME"] + name = "Sample Step Monitor" + period = "EVERY_6_HOURS" + status = "ENABLED" + runtime_type = "CHROME_BROWSER" + runtime_type_version = "100" + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] location_private { guid = newrelic_synthetics_private_location.foo.id vse_password = "secret"