From 88f50a50cf418810a28fa12fca16c251827ae736 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Sun, 10 Mar 2019 18:34:46 +0000 Subject: [PATCH] resource/pagerduty_maintenance_window: Suppress spurious diff --- .../resource_pagerduty_maintenance_window.go | 14 ++++++++------ pagerduty/util.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/pagerduty/resource_pagerduty_maintenance_window.go b/pagerduty/resource_pagerduty_maintenance_window.go index c493f2f68..77087c67e 100644 --- a/pagerduty/resource_pagerduty_maintenance_window.go +++ b/pagerduty/resource_pagerduty_maintenance_window.go @@ -18,14 +18,16 @@ func resourcePagerDutyMaintenanceWindow() *schema.Resource { }, Schema: map[string]*schema.Schema{ "start_time": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validateRFC3339, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateRFC3339, + DiffSuppressFunc: suppressRFC3339Diff, }, "end_time": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validateRFC3339, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateRFC3339, + DiffSuppressFunc: suppressRFC3339Diff, }, "services": { diff --git a/pagerduty/util.go b/pagerduty/util.go index bcb1fafe9..c4fac1b68 100644 --- a/pagerduty/util.go +++ b/pagerduty/util.go @@ -2,6 +2,7 @@ package pagerduty import ( "fmt" + "log" "time" "github.com/hashicorp/terraform/helper/schema" @@ -26,6 +27,20 @@ func validateRFC3339(v interface{}, k string) (we []string, errors []error) { return } +func suppressRFC3339Diff(k, oldTime, newTime string, d *schema.ResourceData) bool { + oldT, err := time.Parse(time.RFC3339, oldTime) + if err != nil { + log.Printf("[ERROR] Failed to parse %q (old %q). Expected format: %s (RFC3339)", oldTime, k, time.RFC3339) + return false + } + newT, err := time.Parse(time.RFC3339, newTime) + if err != nil { + log.Printf("[ERROR] Failed to parse %q (new %q). Expected format: %s (RFC3339)", newTime, k, time.RFC3339) + return false + } + return oldT.Equal(newT) +} + // Validate a value against a set of possible values func validateValueFunc(values []string) schema.SchemaValidateFunc { return func(v interface{}, k string) (we []string, errors []error) {