helper/schema: detect no change computed for sets/lists properly

This commit is contained in:
Mitchell Hashimoto 2014-08-27 15:03:42 -07:00
parent eac01c2ac8
commit 9d239eea60
2 changed files with 33 additions and 0 deletions

View File

@ -287,6 +287,13 @@ func (m schemaMap) diffList(
diff *terraform.ResourceDiff,
d *ResourceData) error {
o, n, _ := d.diffChange(k)
// If we have an old value, but no new value set but we're computed,
// then nothing has changed.
if o != nil && n == nil && schema.Computed {
return nil
}
if o == nil {
o = []interface{}{}
}

View File

@ -500,6 +500,32 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeSet,
Optional: true,
Computed: true,
Elem: &Schema{Type: TypeInt},
Set: func(v interface{}) int { return v.(int) },
},
},
State: &terraform.ResourceState{
Attributes: map[string]string{
"availability_zone": "bar",
"ports.#": "1",
"ports.0": "80",
},
},
Config: map[string]interface{}{},
Diff: nil,
Err: false,
},
/*
* List of structure decode
*/