helper/schema: show in diff when no config is going to empty set

This commit is contained in:
Mitchell Hashimoto 2015-02-17 14:45:18 -08:00
parent cc3c03d3b3
commit dbfb95fcd5
2 changed files with 33 additions and 1 deletions

View File

@ -702,6 +702,7 @@ func (m schemaMap) diffSet(
return nil
}
oRaw := o
if o == nil {
o = &Set{F: schema.Set}
}
@ -750,7 +751,7 @@ func (m schemaMap) diffSet(
// If the counts are not the same, then record that diff
changed := oldLen != newLen
if changed || all {
if changed || all || oRaw == nil {
countSchema := &Schema{
Type: TypeInt,
Computed: schema.Computed,

View File

@ -2032,6 +2032,37 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
// #51 - A set computed element shouldn't cause a diff
{
Schema: map[string]*Schema{
"instances": &Schema{
Type: TypeSet,
Elem: &Schema{Type: TypeString},
Optional: true,
ForceNew: true,
Set: func(v interface{}) int {
return len(v.(string))
},
},
},
State: nil,
Config: map[string]interface{}{},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"instances.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "0",
RequiresNew: true,
},
},
},
Err: false,
},
}
for i, tc := range cases {