Merge pull request #19114 from hashicorp/jbardin/provider-defaults

don't set defaults for deprecated or removed
This commit is contained in:
James Bardin 2018-10-18 13:01:02 -04:00 committed by GitHub
commit 47921bddb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -115,6 +115,11 @@ func (s *GRPCProviderServer) PrepareProviderConfig(_ context.Context, req *proto
return val, nil return val, nil
} }
// this is deprecated, so don't set it
if attrSchema.Deprecated != "" || attrSchema.Removed != "" {
return val, nil
}
// find a default value if it exists // find a default value if it exists
def, err := attrSchema.DefaultValue() def, err := attrSchema.DefaultValue()
if err != nil { if err != nil {
@ -129,6 +134,7 @@ func (s *GRPCProviderServer) PrepareProviderConfig(_ context.Context, req *proto
// create a cty.Value and make sure it's the correct type // create a cty.Value and make sure it's the correct type
tmpVal := hcl2shim.HCL2ValueFromConfigValue(def) tmpVal := hcl2shim.HCL2ValueFromConfigValue(def)
val, err = ctyconvert.Convert(tmpVal, val.Type()) val, err = ctyconvert.Convert(tmpVal, val.Type())
return val, err return val, err
}) })

View File

@ -533,6 +533,23 @@ func TestPrepareProviderConfig(t *testing.T) {
"foo": cty.StringVal("true"), "foo": cty.StringVal("true"),
}), }),
}, },
{
Name: "test deprecated default",
Schema: map[string]*schema.Schema{
"foo": &schema.Schema{
Type: schema.TypeString,
Required: true,
Default: "do not use",
Removed: "don't use this",
},
},
ConfigVal: cty.ObjectVal(map[string]cty.Value{
"foo": cty.NullVal(cty.String),
}),
ExpectConfig: cty.ObjectVal(map[string]cty.Value{
"foo": cty.NullVal(cty.String),
}),
},
} { } {
t.Run(tc.Name, func(t *testing.T) { t.Run(tc.Name, func(t *testing.T) {
server := &GRPCProviderServer{ server := &GRPCProviderServer{