helper/schema: ResourceData.Get can get the full object

This commit is contained in:
Mitchell Hashimoto 2014-08-16 13:55:10 -07:00
parent 43e4921bd9
commit bf6ad07505
2 changed files with 35 additions and 1 deletions

View File

@ -21,7 +21,11 @@ type ResourceData struct {
// Primitives will be their respective types in Go, lists will always be
// []interface{}, and sub-resources will be map[string]interface{}.
func (d *ResourceData) Get(key string) interface{} {
parts := strings.Split(key, ".")
var parts []string
if key != "" {
parts = strings.Split(key, ".")
}
return d.getObject("", parts, d.schema)
}

View File

@ -270,6 +270,36 @@ func TestResourceDataGet(t *testing.T) {
Value: "foo",
},
// Full object
{
Schema: map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
State: nil,
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
New: "foo",
RequiresNew: true,
},
},
},
Key: "",
Value: map[string]interface{}{
"availability_zone": "foo",
},
},
}
for i, tc := range cases {