From a1503a8d2d4e870942ccaeb7130bb97f1b70d9c3 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 9 Jan 2020 22:24:58 +0000 Subject: [PATCH] Explicitly set labels to nil for Alert Policy Signed-off-by: Modular Magician --- google/resource_monitoring_alert_policy.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/google/resource_monitoring_alert_policy.go b/google/resource_monitoring_alert_policy.go index 3458e08a87d..173fd14ff78 100644 --- a/google/resource_monitoring_alert_policy.go +++ b/google/resource_monitoring_alert_policy.go @@ -827,6 +827,18 @@ func resourceMonitoringAlertPolicyRead(d *schema.ResourceData, meta interface{}) return handleNotFoundError(err, d, fmt.Sprintf("MonitoringAlertPolicy %q", d.Id())) } + res, err = resourceMonitoringAlertPolicyDecoder(d, meta, res) + if err != nil { + return err + } + + if res == nil { + // Decoding the object has resulted in it being gone. It may be marked deleted + log.Printf("[DEBUG] Removing MonitoringAlertPolicy because it no longer exists.") + d.SetId("") + return nil + } + if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading AlertPolicy: %s", err) } @@ -1849,3 +1861,10 @@ func expandMonitoringAlertPolicyDocumentationContent(v interface{}, d TerraformR func expandMonitoringAlertPolicyDocumentationMimeType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } + +func resourceMonitoringAlertPolicyDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { + if err := d.Set("labels", nil); err != nil { + return res, fmt.Errorf("Error ignoring Removed fields for AlertPolicy: %s", err) + } + return res, nil +}