From bf6ad0750587d91cf065f726b1708b00d0c59c69 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 16 Aug 2014 13:55:10 -0700 Subject: [PATCH] helper/schema: ResourceData.Get can get the full object --- helper/schema/resource_data.go | 6 +++++- helper/schema/resource_data_test.go | 30 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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 {