Skip to content

Commit

Permalink
feat(synthetics): changes to disallow usage legacy runtime usage Aug …
Browse files Browse the repository at this point in the history
…26 2024 EOL
  • Loading branch information
pranav-new-relic authored Aug 26, 2024
1 parent a4fa318 commit e434794
Show file tree
Hide file tree
Showing 21 changed files with 1,308 additions and 211 deletions.
39 changes: 39 additions & 0 deletions newrelic/resource_helpers_synthetics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ func syntheticsMonitorLocationsAsStringsSchema() map[string]*schema.Schema {
}
}

const SyntheticsRuntimeTypeAttrLabel string = "runtime_type"
const SyntheticsRuntimeTypeVersionAttrLabel string = "runtime_type_version"
const SyntheticsUseLegacyRuntimeAttrLabel string = "use_unsupported_legacy_runtime"

const SyntheticsNodeRuntimeType string = "NODE_API"
const SyntheticsNodeLegacyRuntimeTypeVersion string = "10"
const SyntheticsNodeNewRuntimeTypeVersion string = "16.10"

const SyntheticsChromeBrowserRuntimeType string = "CHROME_BROWSER"
const SyntheticsChromeBrowserLegacyRuntimeTypeVersion string = "72"
const SyntheticsChromeBrowserNewRuntimeTypeVersion string = "100"

var SyntheticsUseLegacyRuntimeSchema = &schema.Schema{
Type: schema.TypeBool,
Description: "A boolean attribute to be set true by the customer, if they would like to use the unsupported legacy runtime of Synthetic Monitors by means of an exemption given until the October 22, 2024 Legacy Runtime EOL. Setting this attribute to true would allow skipping validation performed by the the New Relic Terraform Provider starting v3.43.0 to disallow using the legacy runtime with new monitors. This would, hence, allow creation of monitors in the legacy runtime until the October 22, 2024 Legacy Runtime EOL, if exempt by the API.",
Default: false,
Optional: true,
DiffSuppressFunc: syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor,
}

var syntheticsMonitorPeriodValueMap = map[int]synthetics.SyntheticsMonitorPeriod{
1: synthetics.SyntheticsMonitorPeriodTypes.EVERY_MINUTE,
5: synthetics.SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES,
Expand Down Expand Up @@ -509,3 +529,22 @@ func getCertCheckMonitorValuesFromEntityTags(tags []entities.EntityTag) (domain

return domain, daysUntilExpiration
}

func syntheticMonitorConfigHasObsoleteRuntime(
runtimeTypeInConfig interface{},
runtimeTypeVersionInConfig interface{},
) bool {
return (runtimeTypeInConfig == SyntheticsNodeRuntimeType && runtimeTypeVersionInConfig == SyntheticsNodeLegacyRuntimeTypeVersion) || (runtimeTypeInConfig == SyntheticsChromeBrowserRuntimeType && runtimeTypeVersionInConfig == SyntheticsChromeBrowserLegacyRuntimeTypeVersion)
}

func syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor(k, oldValue, newValue string, d *schema.ResourceData) bool {
rawConfiguration := d.GetRawConfig()
isUseUnsupportedLegacyRuntimeNotSpecifiedInConfiguration := rawConfiguration.GetAttr(k).IsNull()
isUseUnsupportedLegacyRuntimeFalse := newValue == "false"

if isUseUnsupportedLegacyRuntimeNotSpecifiedInConfiguration && isUseUnsupportedLegacyRuntimeFalse {
return true
}

return false
}
2 changes: 1 addition & 1 deletion newrelic/resource_newrelic_account_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAccNewRelicAccountManagementInvalidRegion(t *testing.T) {
}
func TestAccNewRelicAccountManagementInCorrectRegion(t *testing.T) {
rName := acctest.RandString(7)
expectedErrorMsg := regexp.MustCompile(`An error occurred resolving this field`)
expectedErrorMsg := regexp.MustCompile(`An error occurred resolving this field|cannot create account -- no configured parent account`)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
6 changes: 2 additions & 4 deletions newrelic/resource_newrelic_nrql_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers"
)

func TestAccNewRelicNrqlAlertCondition_Basic(t *testing.T) {
Expand Down Expand Up @@ -569,9 +570,6 @@ func TestAccNewRelicNrqlAlertCondition_StaticConditionDataAccountId(t *testing.T
resourceName := "newrelic_nrql_alert_condition.foo"
rName := acctest.RandString(5)

providerConfig := testAccProvider.Meta().(*ProviderConfig)
dataAccountId := providerConfig.AccountID

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
Expand All @@ -581,7 +579,7 @@ func TestAccNewRelicNrqlAlertCondition_StaticConditionDataAccountId(t *testing.T
{
Config: testAccNewRelicNrqlAlertConditionStaticWithDataAccountId(
rName,
dataAccountId,
testhelpers.IntegrationTestAccountID,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNrqlAlertConditionExists(resourceName),
Expand Down
2 changes: 2 additions & 0 deletions newrelic/resource_newrelic_synthetics_broken_links_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func resourceNewRelicSyntheticsBrokenLinksMonitor() *schema.Resource {
syntheticsMonitorLocationsAsStringsSchema(),
syntheticsMonitorRuntimeOptions(),
),
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
}
}

Expand All @@ -36,6 +37,7 @@ func syntheticsBrokenLinksMonitorSchema() map[string]*schema.Schema {
Description: "The URI the monitor runs against.",
Required: true,
},
SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestAccNewRelicSyntheticsBrokenLinksMonitor(t *testing.T) {
{
Config: testAccNewRelicSyntheticsBrokenLinksMonitorConfig(
rName,
"",
"",
SyntheticsNodeRuntimeType,
SyntheticsNodeNewRuntimeTypeVersion,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicSyntheticsMonitorEntityExists(resourceName),
Expand All @@ -36,8 +36,8 @@ func TestAccNewRelicSyntheticsBrokenLinksMonitor(t *testing.T) {
{
Config: testAccNewRelicSyntheticsBrokenLinksMonitorConfig(
fmt.Sprintf("%s-updated", rName),
"NODE_API",
"16.10",
SyntheticsNodeRuntimeType,
SyntheticsNodeNewRuntimeTypeVersion,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicSyntheticsMonitorEntityExists(resourceName),
Expand All @@ -51,6 +51,7 @@ func TestAccNewRelicSyntheticsBrokenLinksMonitor(t *testing.T) {
ImportStateVerifyIgnore: []string{
"locations_private",
"tag",
SyntheticsUseLegacyRuntimeAttrLabel,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions newrelic/resource_newrelic_synthetics_cert_check_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func resourceNewRelicSyntheticsCertCheckMonitor() *schema.Resource {
Optional: true,
Description: "The specific semver version of the runtime type.",
},
SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema,
},
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
}
}

Expand Down
9 changes: 5 additions & 4 deletions newrelic/resource_newrelic_synthetics_cert_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestAccNewRelicSyntheticsCertCheckMonitor(t *testing.T) {
"EVERY_5_MINUTES",
"ENABLED",
30,
"",
"",
SyntheticsNodeRuntimeType,
SyntheticsNodeNewRuntimeTypeVersion,
),
Check: resource.ComposeTestCheckFunc(
testAccNewRelicSyntheticsCertCheckMonitorExists(resourceName),
Expand All @@ -42,8 +42,8 @@ func TestAccNewRelicSyntheticsCertCheckMonitor(t *testing.T) {
"EVERY_10_MINUTES",
"DISABLED",
20,
"NODE_API",
"16.10",
SyntheticsNodeRuntimeType,
SyntheticsNodeNewRuntimeTypeVersion,
),
Check: resource.ComposeTestCheckFunc(
testAccNewRelicSyntheticsCertCheckMonitorExists(resourceName),
Expand All @@ -59,6 +59,7 @@ func TestAccNewRelicSyntheticsCertCheckMonitor(t *testing.T) {
"certificate_expiration",
"domain",
"tag",
SyntheticsUseLegacyRuntimeAttrLabel,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions newrelic/resource_newrelic_synthetics_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource {
Optional: true,
Description: "The programing language that should execute the script",
},
SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema,
"tag": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -175,6 +176,7 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource {
Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.",
},
},
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
}
}

Expand Down
43 changes: 2 additions & 41 deletions newrelic/resource_newrelic_synthetics_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,6 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationErrorUpdate(t *testi
})
}

func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationLegacyRuntimeError(t *testing.T) {
rName := generateNameForIntegrationTestResource()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNewRelicSyntheticsMonitorDestroy,
Steps: []resource.TestStep{
// Test: Create
{
Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationLegacyRuntimeError(rName, string(SyntheticsMonitorTypes.BROWSER)),
ExpectError: regexp.MustCompile(`device emulation is not supported by legacy runtime`),
},
},
})
}

func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationLegacyRuntimeErrorUpdate(t *testing.T) {
rName := generateNameForIntegrationTestResource()
resourceName := "newrelic_synthetics_monitor.foo"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNewRelicSyntheticsMonitorDestroy,
Steps: []resource.TestStep{
// Test: Create
{
Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulation(rName, string(SyntheticsMonitorTypes.BROWSER)),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicSyntheticsMonitorExists(resourceName),
),
},
// Test: Update
{
Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationLegacyRuntimeError(rName, string(SyntheticsMonitorTypes.BROWSER)),
ExpectError: regexp.MustCompile(`device emulation is not supported by legacy runtime`),
},
},
})
}
func testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(name string, monitorType string) string {
return fmt.Sprintf(`
resource "newrelic_synthetics_monitor" "foo" {
Expand Down Expand Up @@ -231,6 +190,7 @@ func TestAccNewRelicSyntheticsSimpleMonitor(t *testing.T) {
"custom_header",
"device_orientation",
"device_type",
SyntheticsUseLegacyRuntimeAttrLabel,
},
},
},
Expand Down Expand Up @@ -327,6 +287,7 @@ func TestAccNewRelicSyntheticsSimpleBrowserMonitor(t *testing.T) {
"script_language",
"device_orientation",
"device_type",
SyntheticsUseLegacyRuntimeAttrLabel,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions newrelic/resource_newrelic_synthetics_script_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func resourceNewRelicSyntheticsScriptMonitor() *schema.Resource {
syntheticsScriptMonitorLocationsSchema(),
syntheticsScriptBrowserMonitorAdvancedOptionsSchema(),
),
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
}
}

Expand Down Expand Up @@ -116,6 +117,7 @@ func syntheticsScriptMonitorCommonSchema() map[string]*schema.Schema {
Optional: true,
Description: "The specific semver version of the runtime type.",
},
SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema,
}
}

Expand Down
Loading

0 comments on commit e434794

Please sign in to comment.