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:
Mitchell Hashimoto 2015-02-17 13:18:33 -08:00
commit dee1071cf4
2 changed files with 27 additions and 3 deletions

View File

@ -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)
}

View File

@ -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 {