Merge pull request #987 from hashicorp/b-bad-diff
helper/schema: computed fields in state shouldn't cause diff to zero value
This commit is contained in:
commit
dee1071cf4
|
@ -810,13 +810,14 @@ func (m schemaMap) diffString(
|
|||
originalN = n
|
||||
n = schema.StateFunc(n)
|
||||
}
|
||||
if n == nil {
|
||||
n = schema.Type.Zero()
|
||||
nraw := n
|
||||
if nraw == nil {
|
||||
nraw = schema.Type.Zero()
|
||||
}
|
||||
if err := mapstructure.WeakDecode(o, &os); err != nil {
|
||||
return fmt.Errorf("%s: %s", k, err)
|
||||
}
|
||||
if err := mapstructure.WeakDecode(n, &ns); err != nil {
|
||||
if err := mapstructure.WeakDecode(nraw, &ns); err != nil {
|
||||
return fmt.Errorf("%s: %s", k, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -2009,6 +2009,29 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
// #50 - A set computed element shouldn't cause a diff
|
||||
{
|
||||
Schema: map[string]*Schema{
|
||||
"active": &Schema{
|
||||
Type: TypeBool,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"active": "true",
|
||||
},
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{},
|
||||
|
||||
Diff: nil,
|
||||
|
||||
Err: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue