From 39edc5dc044999d5486cc342c8df79f39593aaf2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 20 Oct 2014 14:23:06 -0700 Subject: [PATCH] helper/schema: diffing maps that are computed should not result in change --- helper/schema/schema.go | 5 +++++ helper/schema/schema_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 3650123d36..6905325288 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -580,6 +580,11 @@ func (m schemaMap) diffMap( return fmt.Errorf("%s: %s", k, err) } + // If the new map is nil and we're computed, then ignore it. + if n == nil && schema.Computed { + return nil + } + // Now we compare, preferring values from the config map for k, v := range configMap { old := stateMap[k] diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 70388f5690..d5ee09a6c5 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -1191,6 +1191,27 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + { + Schema: map[string]*Schema{ + "vars": &Schema{ + Type: TypeMap, + Computed: true, + }, + }, + + State: &terraform.InstanceState{ + Attributes: map[string]string{ + "vars.foo": "bar", + }, + }, + + Config: nil, + + Diff: nil, + + Err: false, + }, + { Schema: map[string]*Schema{ "config_vars": &Schema{