mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
add diff suppress for empty network policy in container cluster
This commit is contained in:
parent
97cc6fb404
commit
5f3070e223
|
@ -310,6 +310,7 @@ func resourceContainerCluster() *schema.Resource {
|
|||
},
|
||||
},
|
||||
},
|
||||
DiffSuppressFunc: emptyOrDefaultStringSuppress("PROVIDER_UNSPECIFIED"),
|
||||
},
|
||||
|
||||
"node_config": schemaNodeConfig,
|
||||
|
|
|
@ -184,6 +184,12 @@ func optionalPrefixSuppress(prefix string) schema.SchemaDiffSuppressFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func emptyOrDefaultStringSuppress(defaultVal string) schema.SchemaDiffSuppressFunc {
|
||||
return func(k, old, new string, d *schema.ResourceData) bool {
|
||||
return (old == "" && new == defaultVal) || (new == "" && old == defaultVal)
|
||||
}
|
||||
}
|
||||
|
||||
func ipCidrRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
|
||||
// The range may be a:
|
||||
// A) single IP address (e.g. 10.2.3.4)
|
||||
|
|
|
@ -404,3 +404,43 @@ func TestDatasourceSchemaFromResourceSchema(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyOrDefaultStringSuppress(t *testing.T) {
|
||||
testFunc := emptyOrDefaultStringSuppress("default value")
|
||||
|
||||
cases := map[string]struct {
|
||||
Old, New string
|
||||
ExpectDiffSupress bool
|
||||
}{
|
||||
"same value, format changed from empty to default": {
|
||||
Old: "",
|
||||
New: "default value",
|
||||
ExpectDiffSupress: true,
|
||||
},
|
||||
"same value, format changed from default to empty": {
|
||||
Old: "default value",
|
||||
New: "",
|
||||
ExpectDiffSupress: true,
|
||||
},
|
||||
"different value, format changed from empty to non-default": {
|
||||
Old: "",
|
||||
New: "not default new",
|
||||
ExpectDiffSupress: false,
|
||||
},
|
||||
"different value, format changed from non-default to empty": {
|
||||
Old: "not default old",
|
||||
New: "",
|
||||
ExpectDiffSupress: false,
|
||||
},
|
||||
"different value, format changed from non-default to non-default": {
|
||||
Old: "not default 1",
|
||||
New: "not default 2",
|
||||
ExpectDiffSupress: false,
|
||||
},
|
||||
}
|
||||
for tn, tc := range cases {
|
||||
if testFunc("", 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