Skip to content

Commit

Permalink
helper/schema: skip provider input for deprecated fields
Browse files Browse the repository at this point in the history
There's no reason that a field that's been deprecated should ever
prompt.

fixes #4033
  • Loading branch information
phinze committed Dec 7, 2015
1 parent 7e2c8d2 commit 99244c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ func (m schemaMap) Input(
continue
}

// Deprecated fields should never prompt
if v.Deprecated != "" {
continue
}

// Skip things that have a value of some sort already
if _, ok := c.Raw[k]; ok {
continue
Expand Down
34 changes: 34 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,40 @@ func TestSchemaMap_InputDefault(t *testing.T) {
}
}

func TestSchemaMap_InputDeprecated(t *testing.T) {
emptyConfig := make(map[string]interface{})
c, err := config.NewRawConfig(emptyConfig)
if err != nil {
t.Fatalf("err: %s", err)
}
rc := terraform.NewResourceConfig(c)
rc.Config = make(map[string]interface{})

input := new(terraform.MockUIInput)
input.InputFn = func(opts *terraform.InputOpts) (string, error) {
t.Fatalf("InputFn should not be called on: %#v", opts)
return "", nil
}

schema := map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Deprecated: "long gone",
Optional: true,
},
}
actual, err := schemaMap(schema).Input(input, rc)
if err != nil {
t.Fatalf("err: %s", err)
}

expected := map[string]interface{}{}

if !reflect.DeepEqual(expected, actual.Config) {
t.Fatalf("got: %#v\nexpected: %#v", actual.Config, expected)
}
}

func TestSchemaMap_InternalValidate(t *testing.T) {
cases := map[string]struct {
In map[string]*Schema
Expand Down

0 comments on commit 99244c5

Please sign in to comment.