diff --git a/helper/schema/resource_data.go b/helper/schema/resource_data.go index 52582e542..f5353145e 100644 --- a/helper/schema/resource_data.go +++ b/helper/schema/resource_data.go @@ -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) } diff --git a/helper/schema/resource_data_test.go b/helper/schema/resource_data_test.go index 969e8b65f..efd4a6c8e 100644 --- a/helper/schema/resource_data_test.go +++ b/helper/schema/resource_data_test.go @@ -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 {