diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 7ef4d96a..0dc33990 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -187,10 +187,11 @@ func resourceContainerCluster() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "start_time": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validateRFC3339Time, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateRFC3339Time, + DiffSuppressFunc: rfc3339TimeDiffSuppress, }, "duration": { Type: schema.TypeString, diff --git a/google/utils.go b/google/utils.go index 39439e6d..66f89150 100644 --- a/google/utils.go +++ b/google/utils.go @@ -293,6 +293,15 @@ func portRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool { return false } +// Single-digit hour is equivalent to hour with leading zero e.g. suppress diff 1:00 => 01:00. +// Assume either value could be in either format. +func rfc3339TimeDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + if (len(old) == 4 && "0"+old == new) || (len(new) == 4 && "0"+new == old) { + return true + } + return false +} + // expandLabels pulls the value of "labels" out of a schema.ResourceData as a map[string]string. func expandLabels(d *schema.ResourceData) map[string]string { return expandStringMap(d, "labels") diff --git a/google/utils_test.go b/google/utils_test.go index 68beb60f..3d88225e 100644 --- a/google/utils_test.go +++ b/google/utils_test.go @@ -93,3 +93,46 @@ func TestIpCidrRangeDiffSuppress(t *testing.T) { } } } + +func TestRfc3339TimeDiffSuppress(t *testing.T) { + cases := map[string]struct { + Old, New string + ExpectDiffSupress bool + }{ + "same time, format changed to have leading zero": { + Old: "2:00", + New: "02:00", + ExpectDiffSupress: true, + }, + "same time, format changed not to have leading zero": { + Old: "02:00", + New: "2:00", + ExpectDiffSupress: true, + }, + "different time, both without leading zero": { + Old: "2:00", + New: "3:00", + ExpectDiffSupress: false, + }, + "different time, old with leading zero, new without": { + Old: "02:00", + New: "3:00", + ExpectDiffSupress: false, + }, + "different time, new with leading zero, oldwithout": { + Old: "2:00", + New: "03:00", + ExpectDiffSupress: false, + }, + "different time, both with leading zero": { + Old: "02:00", + New: "03:00", + ExpectDiffSupress: false, + }, + } + for tn, tc := range cases { + if rfc3339TimeDiffSuppress("time", tc.Old, tc.New, nil) != tc.ExpectDiffSupress { + t.Errorf("bad: %s, '%s' => '%s' expect DiffSuppress to return %t", tn, tc.Old, tc.New, tc.ExpectDiffSupress) + } + } +}