mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
Relax diff on maintenance_policy.daily_maintenance_window.start_time (#726)
* Relax diff on maintenance_policy.daily_maintenance_window.start_time If the maintenance window has been set outside of Terraform to a time with a single-digit hour (such as 1:00), and the terraform definition is set to the same hour but with a leading zero as per validation (i.e. 01:00), do not consider the time to be changed (as we currently don't support update on this property). Fixes #719 * Generalise rfc3339TimeDiffSuppress and add more test cases
This commit is contained in:
parent
df247070e0
commit
ee641e0b1f
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user