From 9d239eea6070868e6a66464403f383f50ae37e26 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 27 Aug 2014 15:03:42 -0700 Subject: [PATCH] helper/schema: detect no change computed for sets/lists properly --- helper/schema/schema.go | 7 +++++++ helper/schema/schema_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 62ca204a1..6de1407d3 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -287,6 +287,13 @@ func (m schemaMap) diffList( diff *terraform.ResourceDiff, d *ResourceData) error { o, n, _ := d.diffChange(k) + + // If we have an old value, but no new value set but we're computed, + // then nothing has changed. + if o != nil && n == nil && schema.Computed { + return nil + } + if o == nil { o = []interface{}{} } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index ce2d3c8e7..5b32c985a 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -500,6 +500,32 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + { + Schema: map[string]*Schema{ + "ports": &Schema{ + Type: TypeSet, + Optional: true, + Computed: true, + Elem: &Schema{Type: TypeInt}, + Set: func(v interface{}) int { return v.(int) }, + }, + }, + + State: &terraform.ResourceState{ + Attributes: map[string]string{ + "availability_zone": "bar", + "ports.#": "1", + "ports.0": "80", + }, + }, + + Config: map[string]interface{}{}, + + Diff: nil, + + Err: false, + }, + /* * List of structure decode */