mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
Merge pull request #984 from hashicorp/b-zero-diffs
helper/schema: Diff should be empty if the zero value is in the state
This commit is contained in:
commit
1a39903fe2
@ -810,6 +810,9 @@ func (m schemaMap) diffString(
|
||||
originalN = n
|
||||
n = schema.StateFunc(n)
|
||||
}
|
||||
if n == nil {
|
||||
n = schema.Type.Zero()
|
||||
}
|
||||
if err := mapstructure.WeakDecode(o, &os); err != nil {
|
||||
return fmt.Errorf("%s: %s", k, err)
|
||||
}
|
||||
|
@ -1943,6 +1943,72 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||
Diff: nil,
|
||||
Err: false,
|
||||
},
|
||||
|
||||
// #48 - Zero value in state shouldn't result in diff
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"port": &Schema{
|
||||
Type: TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"port": "false",
|
||||
},
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{},
|
||||
|
||||
Diff: nil,
|
||||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
// #49 Set - Same as #47 but for sets
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"route": &Schema{
|
||||
Type: TypeSet,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"index": &Schema{
|
||||
Type: TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"gateway": &Schema{
|
||||
Type: TypeSet,
|
||||
Optional: true,
|
||||
Elem: &Schema{Type: TypeInt},
|
||||
Set: func(a interface{}) int {
|
||||
return a.(int)
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: func(v interface{}) int {
|
||||
m := v.(map[string]interface{})
|
||||
return m["index"].(int)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"route.#": "0",
|
||||
},
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{},
|
||||
|
||||
Diff: nil,
|
||||
|
||||
Err: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user