diff --git a/helper/schema/schema.go b/helper/schema/schema.go index d8b4e8166..d781da282 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -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) } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index bb32374f3..8f6119490 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -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 {