Skip to content

Commit

Permalink
Merge pull request #987 from hashicorp/b-bad-diff
Browse files Browse the repository at this point in the history
helper/schema: computed fields in state shouldn't cause diff to zero value
  • Loading branch information
mitchellh committed Feb 17, 2015
2 parents 72a35cb + fd274d7 commit dee1071
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
23 changes: 23 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit dee1071

Please sign in to comment.