Merge pull request #661 from svanharmelen/f-fix-difflist-logic-error

core: fixing a small logic bug in diffList
This commit is contained in:
Sander van Harmelen 2014-12-12 15:31:22 +01:00
commit db640cb1dc
2 changed files with 55 additions and 3 deletions

View File

@ -459,9 +459,10 @@ func (m schemaMap) diffList(
o, n, _, computedList := d.diffChange(k)
nSet := n != nil
// 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 {
// If we have an old value and no new value is set or will be
// computed once all variables can be interpolated and we're
// computed, then nothing has changed.
if o != nil && n == nil && !computedList && schema.Computed {
return nil
}

View File

@ -1466,6 +1466,57 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
{
Schema: map[string]*Schema{
"internal": &Schema{
Type: TypeBool,
Required: true,
},
"instances": &Schema{
Type: TypeSet,
Elem: &Schema{Type: TypeString},
Optional: true,
Computed: true,
Set: func(v interface{}) int {
return len(v)
},
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"internal": "false",
"instances.#": "0",
},
},
Config: map[string]interface{}{
"internal": true,
"instances": []interface{}{"${var.foo}"},
},
ConfigVariables: map[string]string{
"var.foo": config.UnknownVariableValue,
},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"internal": &terraform.ResourceAttrDiff{
Old: "0",
New: "1",
},
"instances.#": &terraform.ResourceAttrDiff{
Old: "0",
NewComputed: true,
},
},
},
Err: false,
},
}
for i, tc := range cases {