From d9596fa4d0215e0584f8cad6ff8ac1176f320072 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Sep 2014 11:16:19 -0700 Subject: [PATCH] helper/schema: don't ask for input on fields that have a value --- helper/schema/schema.go | 5 +++++ helper/schema/schema_test.go | 31 +++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 1f7b9c49d..9cd952930 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -282,6 +282,11 @@ func (m schemaMap) Input( continue } + // Skip things that have a value of some sort already + if _, ok := c.Raw[k]; ok { + continue + } + var value interface{} var err error switch v.Type { diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 2f8abfac4..876393a9b 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -1055,10 +1055,6 @@ func TestSchemaMap_Input(t *testing.T) { }, }, - Config: map[string]interface{}{ - "availability_zone": "bar", - }, - Input: map[string]string{ "availability_zone": "foo", }, @@ -1069,9 +1065,36 @@ func TestSchemaMap_Input(t *testing.T) { Err: false, }, + + { + Schema: map[string]*Schema{ + "availability_zone": &Schema{ + Type: TypeString, + Optional: true, + }, + }, + + Config: map[string]interface{}{ + "availability_zone": "bar", + }, + + Input: map[string]string{ + "availability_zone": "foo", + }, + + Result: map[string]interface{}{ + "availability_zone": "bar", + }, + + Err: false, + }, } for i, tc := range cases { + if tc.Config == nil { + tc.Config = make(map[string]interface{}) + } + c, err := config.NewRawConfig(tc.Config) if err != nil { t.Fatalf("err: %s", err)