helper/schema: can diff complex resource

This commit is contained in:
Mitchell Hashimoto 2014-08-15 10:25:25 -07:00
parent 878d844f5c
commit d05b9d6193
2 changed files with 55 additions and 0 deletions

View File

@ -169,6 +169,15 @@ func (m schemaMap) diffList(
} }
case *Resource: case *Resource:
// This is a complex resource // This is a complex resource
for i, _ := range vs {
for k2, schema := range t.Schema {
subK := fmt.Sprintf("%s.%d.%s", k, i, k2)
err := m.diff(subK, schema, diff, s, c)
if err != nil {
return err
}
}
}
default: default:
return fmt.Errorf("%s: unknown element type (internal)", k) return fmt.Errorf("%s: unknown element type (internal)", k)
} }

View File

@ -309,6 +309,52 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false, Err: false,
}, },
/*
* List of structure decode
*/
{
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Required: true,
Elem: &Resource{
Schema: map[string]*Schema{
"from": &Schema{
Type: TypeInt,
Required: true,
},
},
},
},
},
State: nil,
Config: map[string]interface{}{
"ingress": []interface{}{
map[string]interface{}{
"from": 8080,
},
},
},
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{
Old: "",
New: "1",
},
"ingress.0.from": &terraform.ResourceAttrDiff{
Old: "",
New: "8080",
},
},
},
Err: false,
},
} }
for i, tc := range cases { for i, tc := range cases {