diff --git a/newrelic/resource_newrelic_monitor_downtime.go b/newrelic/resource_newrelic_monitor_downtime.go index f233e39e0..b4a240a66 100644 --- a/newrelic/resource_newrelic_monitor_downtime.go +++ b/newrelic/resource_newrelic_monitor_downtime.go @@ -168,7 +168,7 @@ func resourceNewRelicMonitorDowntimeCreate(ctx context.Context, d *schema.Resour } switch commonArgumentsObject.Mode { - case "ONE_TIME": + case SyntheticsMonitorDowntimeModes.ONE_TIME: oneTimeCreateObject, err := getMonitorDowntimeOneTimeValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -182,7 +182,7 @@ func resourceNewRelicMonitorDowntimeCreate(ctx context.Context, d *schema.Resour d.SetId(guid) break - case "DAILY": + case SyntheticsMonitorDowntimeModes.DAILY: dailyCreateObject, err := getMonitorDowntimeDailyValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -196,7 +196,7 @@ func resourceNewRelicMonitorDowntimeCreate(ctx context.Context, d *schema.Resour d.SetId(guid) break - case "WEEKLY": + case SyntheticsMonitorDowntimeModes.WEEKLY: weeklyCreateObject, err := getMonitorDowntimeWeeklyValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -210,7 +210,7 @@ func resourceNewRelicMonitorDowntimeCreate(ctx context.Context, d *schema.Resour d.SetId(guid) break - case "MONTHLY": + case SyntheticsMonitorDowntimeModes.MONTHLY: monthlyCreateObject, err := getMonitorDowntimeMonthlyValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -261,22 +261,21 @@ func resourceNewRelicMonitorDowntimeRead(ctx context.Context, d *schema.Resource mode := setMonitorDowntimeMode(tags) timezone := setMonitorDowntimeTimezone(tags) _ = d.Set("name", entity.GetName()) - _ = d.Set("monitor_guids", setMonitorDowntimeMonitorGUIDs(entity.GetRelationships(), common.EntityGUID(d.Id()))) _ = d.Set("account_id", setMonitorDowntimeAccountId(tags)) _ = d.Set("mode", mode) _ = d.Set("start_time", setMonitorDowntimeStartTime(tags)) _ = d.Set("end_time", setMonitorDowntimeEndTime(tags)) _ = d.Set("time_zone", timezone) - if mode != "ONE_TIME" { + if mode != SyntheticsMonitorDowntimeModes.ONE_TIME { setMonitorDowntimeEndRepeat(d, tags, timezone) } - if mode == "WEEKLY" { + if mode == SyntheticsMonitorDowntimeModes.WEEKLY { setMonitorDowntimeMaintenanceDays(d, tags) } - if mode == "MONTHLY" { + if mode == SyntheticsMonitorDowntimeModes.MONTHLY { setMonitorDowntimeFrequency(d, tags) } return nil @@ -292,7 +291,7 @@ func resourceNewRelicMonitorDowntimeUpdate(ctx context.Context, d *schema.Resour } switch commonArgumentsObject.Mode { - case "ONE_TIME": + case SyntheticsMonitorDowntimeModes.ONE_TIME: oneTimeUpdateObject, err := getMonitorDowntimeOneTimeValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -306,7 +305,7 @@ func resourceNewRelicMonitorDowntimeUpdate(ctx context.Context, d *schema.Resour d.SetId(guid) break - case "DAILY": + case SyntheticsMonitorDowntimeModes.DAILY: dailyUpdateObject, err := getMonitorDowntimeDailyValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -320,7 +319,7 @@ func resourceNewRelicMonitorDowntimeUpdate(ctx context.Context, d *schema.Resour d.SetId(guid) break - case "WEEKLY": + case SyntheticsMonitorDowntimeModes.WEEKLY: weeklyUpdateObject, err := getMonitorDowntimeWeeklyValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) @@ -334,7 +333,7 @@ func resourceNewRelicMonitorDowntimeUpdate(ctx context.Context, d *schema.Resour d.SetId(guid) break - case "MONTHLY": + case SyntheticsMonitorDowntimeModes.MONTHLY: monthlyUpdateObject, err := getMonitorDowntimeMonthlyValues(d, commonArgumentsObject) if err != nil { return diag.FromErr(err) diff --git a/newrelic/resource_newrelic_monitor_downtime_test.go b/newrelic/resource_newrelic_monitor_downtime_test.go new file mode 100644 index 000000000..f74b9d534 --- /dev/null +++ b/newrelic/resource_newrelic_monitor_downtime_test.go @@ -0,0 +1,424 @@ +//go:build integration +// +build integration + +package newrelic + +import ( + "fmt" + "math/rand" + "regexp" + "strings" + "testing" + "time" + + "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/common" + "github.com/newrelic/newrelic-client-go/v2/pkg/entities" +) + +var resourceName = fmt.Sprintf("tf-test-%s", acctest.RandString(5)) + +// TestAccNewRelicMonitorDowntime_Once tests create, update operations of a one time monitor downtime +func TestAccNewRelicMonitorDowntime_Once(t *testing.T) { + rName := fmt.Sprintf("%s-once", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Create + { + Config: testAccCheckNewRelicMonitorDowntime_OnceConfiguration(rName, SyntheticsMonitorDowntimeModes.ONE_TIME), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Update + { + Config: testAccCheckNewRelicMonitorDowntime_OnceConfigurationUpdated(rName, SyntheticsMonitorDowntimeModes.ONE_TIME), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Import + { + ResourceName: "newrelic_monitor_downtime.foo", + ImportState: true, + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_Daily tests create, update operations of a daily monitor downtime +func TestAccNewRelicMonitorDowntime_Daily(t *testing.T) { + rName := fmt.Sprintf("%s-daily", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Create + { + Config: testAccCheckNewRelicMonitorDowntime_DailyConfiguration(rName, SyntheticsMonitorDowntimeModes.DAILY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Update + { + Config: testAccCheckNewRelicMonitorDowntime_DailyConfigurationUpdated(rName, SyntheticsMonitorDowntimeModes.DAILY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Import + { + ResourceName: "newrelic_monitor_downtime.foo", + ImportState: true, + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_Weekly tests create, update operations of a weekly monitor downtime +func TestAccNewRelicMonitorDowntime_Weekly(t *testing.T) { + rName := fmt.Sprintf("%s-weekly", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Create + { + Config: testAccCheckNewRelicMonitorDowntime_WeeklyConfiguration(rName, SyntheticsMonitorDowntimeModes.WEEKLY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Update + { + Config: testAccCheckNewRelicMonitorDowntime_WeeklyConfigurationUpdated(rName, SyntheticsMonitorDowntimeModes.WEEKLY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Import + { + ResourceName: "newrelic_monitor_downtime.foo", + ImportState: true, + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_Monthly tests create, update operations of a monthly monitor downtime +func TestAccNewRelicMonitorDowntime_Monthly(t *testing.T) { + rName := fmt.Sprintf("%s-monthly", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Create + { + Config: testAccCheckNewRelicMonitorDowntime_MonthlyConfiguration(rName, SyntheticsMonitorDowntimeModes.MONTHLY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Update + { + Config: testAccCheckNewRelicMonitorDowntime_MonthlyConfigurationUpdated(rName, SyntheticsMonitorDowntimeModes.MONTHLY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Import + { + ResourceName: "newrelic_monitor_downtime.foo", + ImportState: true, + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_MultiMode tests creating a monthly downtime and updating it as a daily downtime +func TestAccNewRelicMonitorDowntime_MultiMode(t *testing.T) { + rName := fmt.Sprintf("%s-multimode", resourceName) + resource.ParallelTest(t, resource.TestCase{ + //PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Create + { + Config: testAccCheckNewRelicMonitorDowntime_MonthlyConfiguration(rName, SyntheticsMonitorDowntimeModes.MONTHLY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Update + { + Config: testAccCheckNewRelicMonitorDowntime_DailyConfigurationUpdated(rName, SyntheticsMonitorDowntimeModes.DAILY), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicMonitorDowntimeExists("newrelic_monitor_downtime.foo"), + ), + }, + // Import + { + ResourceName: "newrelic_monitor_downtime.foo", + ImportState: true, + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_Once_IncorrectConfig tests the creation of a once time monitor downtime with incorrect configuration +func TestAccNewRelicMonitorDowntime_Once_IncorrectConfig(t *testing.T) { + rName := fmt.Sprintf("%s-once-incorrect", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckNewRelicMonitorDowntime_DailyConfiguration(rName, SyntheticsMonitorDowntimeModes.ONE_TIME), + ExpectError: regexp.MustCompile(`validation errors`), + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_Weekly_IncorrectConfig tests the creation of a weekly monitor downtime with incorrect configuration +func TestAccNewRelicMonitorDowntime_Weekly_IncorrectConfig(t *testing.T) { + rName := fmt.Sprintf("%s-weekly-incorrect", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckNewRelicMonitorDowntime_MonthlyConfiguration(rName, SyntheticsMonitorDowntimeModes.WEEKLY), + ExpectError: regexp.MustCompile(`validation errors`), + }, + }, + }) +} + +// TestAccNewRelicMonitorDowntime_Monthly_IncorrectConfig tests the creation of a monthly monitor downtime with incorrect configuration +func TestAccNewRelicMonitorDowntime_Monthly_IncorrectConfig(t *testing.T) { + rName := fmt.Sprintf("%s-monthly-incorrect", resourceName) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckNewRelicMonitorDowntime_WeeklyConfiguration(rName, SyntheticsMonitorDowntimeModes.MONTHLY), + ExpectError: regexp.MustCompile(`validation errors`), + }, + }, + }) +} + +func testAccCheckNewRelicMonitorDowntimeExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("not found: %s", resourceName) + } + if rs.Primary.ID == "" { + return fmt.Errorf("no monitor downtime ID is set") + } + + client := testAccProvider.Meta().(*ProviderConfig).NewClient + + found, err := client.Entities.GetEntity(common.EntityGUID(rs.Primary.ID)) + if err != nil { + return fmt.Errorf(err.Error()) + } + + x := (*found).(*entities.GenericEntity) + if x.GUID != common.EntityGUID(rs.Primary.ID) { + return fmt.Errorf("monitor downtime not found") + } + + return nil + } +} + +func testAccCheckNewRelicMonitorDowntime_BaseConfiguration(name string, monitorGUIDsConverted string, mode string) string { + return ` + name = "` + name + `" + monitor_guids = ` + monitorGUIDsConverted + ` + mode = "` + mode + `" + start_time = "` + generateRandomStartTime() + `" + end_time = "` + generateRandomEndTime() + `" + time_zone = "` + generateRandomTimeZone() + `" + ` +} +func testAccCheckNewRelicMonitorDowntime_OnceConfiguration(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(name, monitorGUIDsAsString, mode) + ` + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_OnceConfigurationUpdated(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(fmt.Sprintf("%s-updated", name), monitorGUIDsUpdatedAsString, mode) + ` + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_DailyConfiguration(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(name, monitorGUIDsAsString, mode) + ` + end_repeat { + on_repeat = 3 + } + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_DailyConfigurationUpdated(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(fmt.Sprintf("%s-updated", name), monitorGUIDsUpdatedAsString, mode) + ` + end_repeat { + on_date = "` + generateRandomEndRepeatDate() + `" + } + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_WeeklyConfiguration(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(name, monitorGUIDsAsString, mode) + ` + maintenance_days = ` + generateRandomMaintenanceDays() + ` + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_WeeklyConfigurationUpdated(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(fmt.Sprintf("%s-updated", name), monitorGUIDsUpdatedAsString, mode) + ` + maintenance_days = ` + generateRandomMaintenanceDays() + ` + end_repeat { + on_date = "` + generateRandomEndRepeatDate() + `" + } + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_MonthlyConfiguration(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(name, monitorGUIDsAsString, mode) + ` + end_repeat { + on_date = "` + generateRandomEndRepeatDate() + `" + } + frequency { + days_of_month = [5, 15, 25] + } + } + ` +} + +func testAccCheckNewRelicMonitorDowntime_MonthlyConfigurationUpdated(name string, mode string) string { + return ` + resource "newrelic_monitor_downtime" "foo" { + ` + testAccCheckNewRelicMonitorDowntime_BaseConfiguration(fmt.Sprintf("%s-updated", name), monitorGUIDsUpdatedAsString, mode) + ` + frequency { + days_of_week { + ordinal_day_of_month = "SECOND" + week_day = "SATURDAY" + } + } + } + ` +} + +// helpers for all the tests written above +var fewValidTimeZones = []string{ + "Asia/Kolkata", + "America/Los_Angeles", + "Europe/Madrid", + "Asia/Tokyo", + "America/Vancouver", + "Asia/Tel_Aviv", + "Europe/Dublin", + "Asia/Tashkent", + "Europe/London", + "Asia/Riyadh", + "America/Chicago", + "Australia/Sydney", +} + +// monitors with the below GUIDs belong to the v2 Integration Tests Account +var monitorGUIDsAsString = convertStringListToString([]string{ + "MzgwNjUyNnxTWU5USHxNT05JVE9SfGFmZmM0MTRiLTVhNmMtNGI5NS1iMzYwLThhNmQ2ZTkzOTM3Yw", +}) +var monitorGUIDsUpdatedAsString = convertStringListToString([]string{ + "MzgwNjUyNnxTWU5USHxNT05JVE9SfDhkYmMyYmIwLTQwZjgtNDA5NC05OTA1LTdhZGE2ZGViMmEwNg", + "MzgwNjUyNnxTWU5USHxNT05JVE9SfDViZDNmYTk4LTA2NjgtNGQ1Yy05ODU2LTk3MzlmNWViY2JlNg", + "MzgwNjUyNnxTWU5USHxNT05JVE9SfGFmZmM0MTRiLTVhNmMtNGI5NS1iMzYwLThhNmQ2ZTkzOTM3Yw", +}) + +func convertStringListToString(list []string) string { + return fmt.Sprintf("[\"%s\"]", strings.Join(list, "\", \"")) +} +func generateRandomTimeZone() string { + rand.Seed(time.Now().Unix()) + return fewValidTimeZones[rand.Intn(len(fewValidTimeZones))] +} + +func generateRandomStartTime() string { + rand.Seed(time.Now().Unix()) + + now := time.Now() + hourLater := now.Add(time.Hour * 2) + + return hourLater.Format("2006-01-02T15:04:05") +} + +func generateRandomEndTime() string { + rand.Seed(time.Now().Unix()) + + now := time.Now() + + // "5 +" to make sure end_time exceeds start_time by a minimum of 5 days + randomDays := 5 + rand.Intn(25) + daysLater := now.AddDate(0, 0, randomDays) + + return daysLater.Format("2006-01-02T15:04:05") +} + +func generateRandomEndRepeatDate() string { + rand.Seed(time.Now().Unix()) + + now := time.Now() + + // "31 +" so that end_repeat > on_date can succeed the date in endTime by 30 days - endRepeat needs to be after endTime + randomDays := 31 + rand.Intn(30) + daysLater := now.AddDate(0, 0, randomDays) + + return daysLater.Format("2006-01-02") +} + +func generateRandomMaintenanceDays() string { + source := rand.NewSource(time.Now().UnixNano()) + r := rand.New(source) + + originalList := listSyntheticsMonitorDowntimeValidMaintenanceDays() + + // minimum 1, maximum 3 + randomLength := 1 + r.Intn(3) + newList := make([]string, randomLength) + + for i := range newList { + randomIndex := r.Intn(len(originalList)) + newList[i] = originalList[randomIndex] + } + + return convertStringListToString(newList) +} diff --git a/newrelic/structures_newrelic_monitor_downtime.go b/newrelic/structures_newrelic_monitor_downtime.go index d54311e90..8d2e420be 100644 --- a/newrelic/structures_newrelic_monitor_downtime.go +++ b/newrelic/structures_newrelic_monitor_downtime.go @@ -17,7 +17,6 @@ import ( "golang.org/x/exp/slices" ) -// validate functions func listValidOrdinalDayOfMonthValues() []string { return []string{ string(synthetics.SyntheticsMonitorDowntimeDayOfMonthOrdinalTypes.FIRST), @@ -60,10 +59,7 @@ func listSyntheticsMonitorDowntimeValidMaintenanceDays() []string { return keys } -// ################# -// Validate functions -// ################# - +// validate functions which perform custom validation func validateMonitorDowntimeAttributes(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { var errorsList []string @@ -167,7 +163,6 @@ func validateMonitorDowntimeEndRepeatStructure(d *schema.ResourceDiff) error { _, mode := d.GetChange("mode") _, endRepeatObtained := d.GetChange("end_repeat") endRepeat := endRepeatObtained.([]interface{}) - // validModesWithEndRepeat := []string{"DAILY", "MONTHLY", "WEEKLY"} if len(endRepeat) != 0 && mode == SyntheticsMonitorDowntimeModes.ONE_TIME { return errors.New("the argument `end_repeat` may only be used with the modes `DAILY`, `MONTHLY` and `WEEKLY`") @@ -207,10 +202,7 @@ var SyntheticsMonitorDowntimeModes = struct { WEEKLY: "WEEKLY", } -// ################# -// Classes whose objects would be used in create/update requests -// ################# - +// classes whose objects would be used in create/update requests type SyntheticsMonitorDowntimeCommonArgumentsInput struct { AccountID int Name string @@ -240,10 +232,7 @@ type SyntheticsMonitorDowntimeMonthlyInput struct { Frequency synthetics.SyntheticsMonitorDowntimeMonthlyFrequency } -// ################# // GET functions used to fetch values from the configuration -// ################# - func getMonitorDowntimeValuesOfCommonArguments(d *schema.ResourceData) (*SyntheticsMonitorDowntimeCommonArgumentsInput, error) { commonArgumentsObject := &SyntheticsMonitorDowntimeCommonArgumentsInput{} @@ -395,10 +384,7 @@ func getMonitorDowntimeMonitorGUIDsFromConfiguration(d *schema.ResourceData) ([] return []synthetics.EntityGUID{}, nil } -// ################# // GET functions used by create methods -// ################# - func getMonitorDowntimeOneTimeValues(d *schema.ResourceData, commonArgumentsObject *SyntheticsMonitorDowntimeCommonArgumentsInput) (*SyntheticsMonitorDowntimeOneTimeInput, error) { return &SyntheticsMonitorDowntimeOneTimeInput{ SyntheticsMonitorDowntimeCommonArgumentsInput: *commonArgumentsObject, @@ -498,10 +484,7 @@ func getMonitorDowntimeMonthlyValues(d *schema.ResourceData, commonArgumentsObje return monitorDowntimeMonthlyInput, nil } -// ################# // Methods which assist create methods -// ################# - func (obj *SyntheticsMonitorDowntimeOneTimeInput) createMonitorDowntimeOneTime(ctx context.Context, client *newrelic.NewRelic) (string, error) { resp, err := client.Synthetics.SyntheticsCreateOnceMonitorDowntimeWithContext( ctx, @@ -586,10 +569,7 @@ func (obj *SyntheticsMonitorDowntimeMonthlyInput) createMonitorDowntimeMonthly(c return string(resp.GUID), nil } -// ################# // Methods which assist update methods -// ################# - func (obj *SyntheticsMonitorDowntimeOneTimeInput) updateMonitorDowntimeOneTime(ctx context.Context, client *newrelic.NewRelic, guid synthetics.EntityGUID) (string, error) { resp, err := client.Synthetics.SyntheticsEditOneTimeMonitorDowntimeWithContext( ctx, @@ -682,10 +662,7 @@ func (obj *SyntheticsMonitorDowntimeMonthlyInput) updateMonitorDowntimeMonthly(c return string(resp.GUID), nil } -// ################# // Other Helper Functions -// ################# - func getMaintenanceDaysList(d *schema.ResourceData) ([]string, error) { val, ok := d.GetOk("maintenance_days") if !ok { @@ -751,10 +728,7 @@ func getStringEntityTag(tags []entities.EntityTag, attributeName string) string return out[0] } -// ################# // Functions which help set values in the state -// ################# - func setMonitorDowntimeFrequency(d *schema.ResourceData, tags []entities.EntityTag) { daysOfMonthTag := "monthDay" daysOfWeekTag := "specificWeekDay" @@ -762,8 +736,6 @@ func setMonitorDowntimeFrequency(d *schema.ResourceData, tags []entities.EntityT var daysOfMonthValue []int var daysOfWeekValue string = "" - // TODO: is there a better way to do this? (not initialise with -1 but something like nil which I am not able to do) - for _, t := range tags { if t.Key == daysOfMonthTag { for _, v := range t.Values { @@ -830,7 +802,7 @@ func setMonitorDowntimeEndRepeat(d *schema.ResourceData, tags []entities.EntityT onDateValue := "" - // TODO: is there a better way to do this? (not initialise with -1 but something like nil which I am not able to do) + // TODO: is there a better way to do this? (not initialise with -1 but something like nil)? Cannot initialise with 0 as it can be a valid end_repeat onRepeatValue := -1 for _, t := range tags {