Skip to content

Commit

Permalink
make uptime check period updatable (#8266) (#15315)
Browse files Browse the repository at this point in the history
* uptime check period updatable

* add tests

* fix

* fix

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jul 27, 2023
1 parent fe9db9c commit 61a7436
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/8266.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
monitoring: added update support for `period` in `google_monitoring_uptime_check_config`
```
15 changes: 8 additions & 7 deletions google/resource_monitoring_uptime_check_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) {
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "mypath", "password1", project, host),
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "60s", "mypath", "password1", project, host),
},
{
ResourceName: "google_monitoring_uptime_check_config.http",
Expand All @@ -31,7 +31,7 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) {
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"},
},
{
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "", "password2", project, host),
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "60s", "", "password2", project, host),
},
{
ResourceName: "google_monitoring_uptime_check_config.http",
Expand All @@ -55,7 +55,7 @@ func TestAccMonitoringUptimeCheckConfig_changeNonUpdatableFields(t *testing.T) {
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "mypath", "password1", project, "192.168.1.1"),
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "60s", "mypath", "password1", project, "192.168.1.1"),
},
{
ResourceName: "google_monitoring_uptime_check_config.http",
Expand All @@ -64,7 +64,7 @@ func TestAccMonitoringUptimeCheckConfig_changeNonUpdatableFields(t *testing.T) {
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"},
},
{
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "mypath", "password1", project, "192.168.1.2"),
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "300s", "mypath", "password1", project, "192.168.1.2"),
},
{
ResourceName: "google_monitoring_uptime_check_config.http",
Expand All @@ -73,7 +73,7 @@ func TestAccMonitoringUptimeCheckConfig_changeNonUpdatableFields(t *testing.T) {
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"},
},
{
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "mypath", "password2", project, "192.168.1.2"),
Config: testAccMonitoringUptimeCheckConfig_update(acctest.RandString(t, 4), "60s", "mypath", "password2", project, "192.168.1.2"),
},
{
ResourceName: "google_monitoring_uptime_check_config.http",
Expand Down Expand Up @@ -116,11 +116,12 @@ func TestAccMonitoringUptimeCheckConfig_jsonPathUpdate(t *testing.T) {
})
}

func testAccMonitoringUptimeCheckConfig_update(suffix, path, pwd, project, host string) string {
func testAccMonitoringUptimeCheckConfig_update(suffix, period, path, pwd, project, host string) string {
return fmt.Sprintf(`
resource "google_monitoring_uptime_check_config" "http" {
display_name = "http-uptime-check-%s"
timeout = "60s"
period = "%s"
http_check {
path = "/%s"
Expand All @@ -145,7 +146,7 @@ resource "google_monitoring_uptime_check_config" "http" {
matcher = "CONTAINS_STRING"
}
}
`, suffix, path, pwd, project, host,
`, suffix, period, path, pwd, project, host,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func ResourceMonitoringUptimeCheckConfig() *schema.Resource {
"period": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `How often, in seconds, the uptime check is performed. Currently, the only supported values are 60s (1 minute), 300s (5 minutes), 600s (10 minutes), and 900s (15 minutes). Optional, defaults to 300s.`,
Default: "300s",
},
Expand Down Expand Up @@ -576,6 +575,12 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) {
obj["displayName"] = displayNameProp
}
periodProp, err := expandMonitoringUptimeCheckConfigPeriod(d.Get("period"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("period"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, periodProp)) {
obj["period"] = periodProp
}
timeoutProp, err := expandMonitoringUptimeCheckConfigTimeout(d.Get("timeout"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -626,6 +631,10 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
updateMask = append(updateMask, "displayName")
}

if d.HasChange("period") {
updateMask = append(updateMask, "period")
}

if d.HasChange("timeout") {
updateMask = append(updateMask, "timeout")
}
Expand Down

0 comments on commit 61a7436

Please sign in to comment.