helper/schema: ResourceData.Get can get the full object
This commit is contained in:
parent
43e4921bd9
commit
bf6ad07505
|
@ -21,7 +21,11 @@ type ResourceData struct {
|
||||||
// Primitives will be their respective types in Go, lists will always be
|
// Primitives will be their respective types in Go, lists will always be
|
||||||
// []interface{}, and sub-resources will be map[string]interface{}.
|
// []interface{}, and sub-resources will be map[string]interface{}.
|
||||||
func (d *ResourceData) Get(key 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)
|
return d.getObject("", parts, d.schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,36 @@ func TestResourceDataGet(t *testing.T) {
|
||||||
|
|
||||||
Value: "foo",
|
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 {
|
for i, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue