diff --git a/go.mod b/go.mod index 48fc1e9a6..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.0 + 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 30b796c41..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.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.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_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index 66ab04cec..127b894ce 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -130,6 +130,23 @@ var SyntheticsUseLegacyRuntimeSchema = &schema.Schema{ DiffSuppressFunc: syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor, } +var browsersSchema = &schema.Schema{ + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Optional: 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, + 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, @@ -256,6 +273,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_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 f92f27275..6f8e54d23 100644 --- a/newrelic/resource_newrelic_synthetics_monitor.go +++ b/newrelic/resource_newrelic_synthetics_monitor.go @@ -146,6 +146,8 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource { Description: "Capture a screenshot during job execution", Optional: true, }, + "browsers": browsersSchema, + "devices": devicesSchema, "custom_header": { Type: schema.TypeSet, Description: "Custom headers to use in monitor job", @@ -166,17 +168,19 @@ 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: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } diff --git a/newrelic/resource_newrelic_synthetics_monitor_test.go b/newrelic/resource_newrelic_synthetics_monitor_test.go index c8b6fe0a7..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(`both device_orientation and device_type should be specified to enable device emulation`), + 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(`both device_orientation and device_type should be specified to enable device emulation`), + 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), + ), }, }, }) @@ -288,6 +295,8 @@ func TestAccNewRelicSyntheticsSimpleBrowserMonitor(t *testing.T) { "device_orientation", "device_type", SyntheticsUseLegacyRuntimeAttrLabel, + "browsers", + "devices", }, }, }, @@ -305,6 +314,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp name = "customer-header-2" value = "header-value-2" } + 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 @@ -317,8 +328,6 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp status = "ENABLED" type = "%s" uri = "https://www.one.newrelic.com" - device_orientation = "PORTRAIT" - device_type = "MOBILE" }`, name, monitorType) } @@ -329,6 +338,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfigUpdated(name string, mon name = "name" value = "simple_browser" } + browsers = ["CHROME"] + devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] enable_screenshot_on_failure_and_script = false validation_string = "success" verify_ssl = false @@ -341,8 +352,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 6d8d3f1d4..81c7b89a6 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 { @@ -28,7 +26,7 @@ func resourceNewRelicSyntheticsScriptMonitor() *schema.Resource { syntheticsScriptMonitorLocationsSchema(), syntheticsScriptBrowserMonitorAdvancedOptionsSchema(), ), - CustomizeDiff: validateSyntheticMonitorRuntimeAttributes, + CustomizeDiff: validateSyntheticMonitorAttributes, } } @@ -66,7 +64,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": { @@ -74,15 +72,19 @@ 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, - 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/resource_newrelic_synthetics_script_monitor_integration_test.go b/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go index a5d130237..8607cd113 100644 --- a/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go +++ b/newrelic/resource_newrelic_synthetics_script_monitor_integration_test.go @@ -95,6 +95,8 @@ func TestAccNewRelicSyntheticsScriptBrowserMonitor(t *testing.T) { "device_orientation", "device_type", SyntheticsUseLegacyRuntimeAttrLabel, + "browsers", + "devices", }, }, }, @@ -120,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" { @@ -153,9 +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", "FIREFOX"] + devices = ["DESKTOP", "TABLET_LANDSCAPE", "MOBILE_PORTRAIT", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"] tag { key = "Name" values = ["scriptedMonitor"] @@ -232,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 ff568bf75..1afce2d12 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, } } @@ -103,6 +103,8 @@ func syntheticsStepMonitorSchema() map[string]*schema.Schema { Description: "The specific semver version of the runtime type.", }, SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema, + "browsers": browsersSchema, + "devices": devicesSchema, } } diff --git a/newrelic/resource_newrelic_synthetics_step_monitor_test.go b/newrelic/resource_newrelic_synthetics_step_monitor_test.go index 2fb12ba02..42b2bdb55 100644 --- a/newrelic/resource_newrelic_synthetics_step_monitor_test.go +++ b/newrelic/resource_newrelic_synthetics_step_monitor_test.go @@ -57,6 +57,8 @@ func TestAccNewRelicSyntheticsStepMonitor(t *testing.T) { "tag", "enable_screenshot_on_failure_and_script", SyntheticsUseLegacyRuntimeAttrLabel, + "browsers", + "devices", }, }, }, @@ -83,7 +85,9 @@ resource "newrelic_synthetics_step_monitor" "foo" { type = "NAVIGATE" values = ["https://google.com"] } - + 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 685f01dbc..254635ffa 100644 --- a/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go +++ b/newrelic/structures_newrelic_synthetics_all_monitors_validation_helpers.go @@ -4,11 +4,11 @@ import ( "context" "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) @@ -16,6 +16,17 @@ func validateSyntheticMonitorRuntimeAttributes(ctx context.Context, d *schema.Re errorsList = append(errorsList, err...) } + _, monitorType := d.GetChange("type") + if monitorType != nil { + isBrowserMonitor := strings.Contains(monitorType.(string), "BROWSER") + if isBrowserMonitor { + err := validateDevicesFields(d) + if err != nil { + errorsList = append(errorsList, err) + } + } + } + if len(errorsList) == 0 { return nil } @@ -152,3 +163,21 @@ 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 + devicesIsNil := rawConfiguration.GetAttr("devices").IsNull() + deviceTypeIsNil := rawConfiguration.GetAttr("device_type").IsNull() + 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 nil +} diff --git a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go index a587a3f97..3b1f14cbe 100644 --- a/newrelic/structures_newrelic_synthetics_script_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_script_browser_monitor.go @@ -25,6 +25,16 @@ func buildSyntheticsScriptBrowserMonitorInput(d *schema.ResourceData) synthetics 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 + } + sciptLang, scriptLangOk := d.GetOk("script_language") runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -89,6 +99,16 @@ 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 + } + 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_simple_browser_monitor.go b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go index 42520fa2d..7f47e1bf0 100644 --- a/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go +++ b/newrelic/structures_newrelic_synthetics_simple_browser_monitor.go @@ -47,6 +47,16 @@ func buildSyntheticsSimpleBrowserMonitor(d *schema.ResourceData) (synthetics.Syn simpleBrowserMonitorInput.AdvancedOptions.UseTlsValidation = &vs } + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + simpleBrowserMonitorInput.Browsers = typedBrowsers + } + + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + simpleBrowserMonitorInput.Devices = typedDevices + } + err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulation(d, simpleBrowserMonitorInput) if err != nil { return *simpleBrowserMonitorInput, err @@ -139,6 +149,16 @@ func buildSyntheticsSimpleBrowserMonitorUpdateStruct(d *schema.ResourceData) (sy simpleBrowserMonitorUpdateInput.AdvancedOptions.UseTlsValidation = &vs } + if v, ok := d.GetOk("browsers"); ok { + typedBrowsers := expandSyntheticsBrowsers(v.(*schema.Set).List()) + simpleBrowserMonitorUpdateInput.Browsers = typedBrowsers + } + + if v, ok := d.GetOk("devices"); ok { + typedDevices := expandSyntheticsDevices(v.(*schema.Set).List()) + simpleBrowserMonitorUpdateInput.Devices = typedDevices + } + err := buildSyntheticsSimpleBrowserMonitorRuntimeAndDeviceEmulationUpdateStruct(d, simpleBrowserMonitorUpdateInput) if err != nil { return *simpleBrowserMonitorUpdateInput, err diff --git a/newrelic/structures_newrelic_synthetics_step_monitor.go b/newrelic/structures_newrelic_synthetics_step_monitor.go index 01d70463d..9353eb09d 100644 --- a/newrelic/structures_newrelic_synthetics_step_monitor.go +++ b/newrelic/structures_newrelic_synthetics_step_monitor.go @@ -31,6 +31,16 @@ func buildSyntheticsStepMonitorCreateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } + 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 + } + runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") @@ -76,6 +86,16 @@ func buildSyntheticsStepMonitorUpdateInput(d *schema.ResourceData) (*synthetics. input.AdvancedOptions.EnableScreenshotOnFailureAndScript = &v } + 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 + } + runtimeType, runtimeTypeOk := d.GetOk("runtime_type") runtimeTypeVersion, runtimeTypeVersionOk := d.GetOk("runtime_type_version") diff --git a/website/docs/r/synthetics_monitor.html.markdown b/website/docs/r/synthetics_monitor.html.markdown index 0771935e6..e2219e800 100644 --- a/website/docs/r/synthetics_monitor.html.markdown +++ b/website/docs/r/synthetics_monitor.html.markdown @@ -42,27 +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" - } - + 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" - device_type = "MOBILE" - device_orientation = "LANDSCAPE" - + devices = ["DESKTOP", "TABLET_LANDSCAPE", "MOBILE_PORTRAIT"] + browsers = ["CHROME"] + custom_header { + name = "some_name" + value = "some_value" + } tag { key = "some_key" values = ["some_value"] @@ -101,8 +98,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) 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`, `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 @@ -194,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 1b250cc51..a8310ba6c 100644 --- a/website/docs/r/synthetics_script_monitor.html.markdown +++ b/website/docs/r/synthetics_script_monitor.html.markdown @@ -40,20 +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" - tag { key = "some_key" values = ["some_value"] @@ -84,8 +82,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`, `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 @@ -155,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" - device_type = "MOBILE" - device_orientation = "LANDSCAPE" - 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 01cc8d36a..e015a4f31 100644 --- a/website/docs/r/synthetics_step_monitor.html.markdown +++ b/website/docs/r/synthetics_step_monitor.html.markdown @@ -23,6 +23,8 @@ resource "newrelic_synthetics_step_monitor" "foo" { status = "ENABLED" runtime_type = "CHROME_BROWSER" runtime_type_version = "100" + devices = ["DESKTOP", "MOBILE_PORTRAIT", "TABLET_LANDSCAPE"] + browsers = ["CHROME"] steps { ordinal = 0 type = "NAVIGATE" @@ -51,6 +53,8 @@ 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. @@ -97,9 +101,13 @@ 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" + 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"