diff --git a/helper/schema/resource_data_test.go b/helper/schema/resource_data_test.go index af3c52288..969e8b65f 100644 --- a/helper/schema/resource_data_test.go +++ b/helper/schema/resource_data_test.go @@ -250,6 +250,26 @@ func TestResourceDataGet(t *testing.T) { }, }, }, + + // Computed get + { + Schema: map[string]*Schema{ + "availability_zone": &Schema{ + Type: TypeString, + Computed: true, + }, + }, + + State: &terraform.ResourceState{ + Attributes: map[string]string{ + "availability_zone": "foo", + }, + }, + + Key: "availability_zone", + + Value: "foo", + }, } for i, tc := range cases { diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 9c4b83378..35f4597ec 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -112,12 +112,17 @@ func (m schemaMap) Diff( } } + // Remove any nil diffs just to keep things clean for k, v := range result.Attributes { if v == nil { delete(result.Attributes, k) } } + // Go through and detect all of the ComputedWhens now that we've + // finished the diff. + // TODO + if result.Empty() { // If we don't have any diff elements, just return nil return nil, nil diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 4ff8607c2..0a22a6d62 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -505,6 +505,49 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + + /* TODO + { + Schema: map[string]*Schema{ + "availability_zone": &Schema{ + Type: TypeString, + Computed: true, + ComputedWhen: []string{"port"}, + }, + + "port": &Schema{ + Type: TypeInt, + Optional: true, + }, + }, + + State: &terraform.ResourceState{ + Attributes: map[string]string{ + "availability_zone": "foo", + "port": "80", + }, + }, + + Config: map[string]interface{}{ + "port": 8080, + }, + + Diff: &terraform.ResourceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "availability_zone": &terraform.ResourceAttrDiff{ + Old: "foo", + NewComputed: true, + }, + "port": &terraform.ResourceAttrDiff{ + Old: "80", + New: "8080", + }, + }, + }, + + Err: false, + }, + */ } for i, tc := range cases {