Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/schema: Remove PromoteSingle from Schema #337

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 0 additions & 24 deletions helper/schema/field_reader_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ func (r *ConfigFieldReader) readField(
k := strings.Join(address, ".")
schema := schemaList[len(schemaList)-1]

// If we're getting the single element of a promoted list, then
// check to see if we have a single element we need to promote.
if address[len(address)-1] == "0" && len(schemaList) > 1 {
lastSchema := schemaList[len(schemaList)-2]
if lastSchema.Type == TypeList && lastSchema.PromoteSingle {
k := strings.Join(address[:len(address)-1], ".")
result, err := r.readPrimitive(k, schema)
if err == nil {
return result, nil
}
}
}

if protoVersion5 {
switch schema.Type {
case TypeList, TypeSet, TypeMap, typeObject:
Expand All @@ -115,17 +102,6 @@ func (r *ConfigFieldReader) readField(
case TypeBool, TypeFloat, TypeInt, TypeString:
return r.readPrimitive(k, schema)
case TypeList:
// If we support promotion then we first check if we have a lone
// value that we must promote.
// a value that is alone.
if schema.PromoteSingle {
result, err := r.readPrimitive(k, schema.Elem.(*Schema))
if err == nil && result.Exists {
result.Value = []interface{}{result.Value}
return result, nil
}
}

return readListField(&nestedConfigFieldReader{r}, address, schema)
case TypeMap:
return r.readMap(k, schema)
Expand Down
15 changes: 0 additions & 15 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ type Schema struct {
MaxItems int
MinItems int

// PromoteSingle originally allowed for a single element to be assigned
// where a primitive list was expected, but this no longer works from
// Terraform v0.12 onwards (Terraform Core will require a list to be set
// regardless of what this is set to) and so only applies to Terraform v0.11
// and earlier, and so should be used only to retain this functionality
// for those still using v0.11 with a provider that formerly used this.
PromoteSingle bool

// The following fields are only valid for a TypeSet type.
//
// Set defines a function to determine the unique ID of an item so that
Expand Down Expand Up @@ -1497,13 +1489,6 @@ func (m schemaMap) validateList(
// case to []interface{} unless the slice is exactly that type.
rawV := reflect.ValueOf(raw)

// If we support promotion and the raw value isn't a slice, wrap
// it in []interface{} and check again.
if schema.PromoteSingle && rawV.Kind() != reflect.Slice {
raw = []interface{}{raw}
rawV = reflect.ValueOf(raw)
}

if rawV.Kind() != reflect.Slice {
return nil, []error{fmt.Errorf(
"%s: should be a list", k)}
Expand Down
100 changes: 0 additions & 100 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,72 +543,6 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},

{
Name: "List decode with promotion",
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Required: true,
Elem: &Schema{Type: TypeInt},
PromoteSingle: true,
},
},

State: nil,

Config: map[string]interface{}{
"ports": "5",
},

Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "1",
},
"ports.0": &terraform.ResourceAttrDiff{
Old: "",
New: "5",
},
},
},

Err: false,
},

{
Name: "List decode with promotion with list",
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Required: true,
Elem: &Schema{Type: TypeInt},
PromoteSingle: true,
},
},

State: nil,

Config: map[string]interface{}{
"ports": []interface{}{"5"},
},

Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "1",
},
"ports.0": &terraform.ResourceAttrDiff{
Old: "",
New: "5",
},
},
},

Err: false,
},

{
Schema: map[string]*Schema{
"ports": &Schema{
Expand Down Expand Up @@ -3992,40 +3926,6 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true,
},

"List with promotion": {
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Elem: &Schema{Type: TypeInt},
PromoteSingle: true,
Optional: true,
},
},

Config: map[string]interface{}{
"ingress": "5",
},

Err: false,
},

"List with promotion set as list": {
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Elem: &Schema{Type: TypeInt},
PromoteSingle: true,
Optional: true,
},
},

Config: map[string]interface{}{
"ingress": []interface{}{"5"},
},

Err: false,
},

"Optional sub-resource": {
Schema: map[string]*Schema{
"ingress": &Schema{
Expand Down
33 changes: 0 additions & 33 deletions helper/schema/shims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,39 +913,6 @@ func TestShimSchemaMap_Diff(t *testing.T) {
Err: false,
},

{
Name: "List decode with promotion with list",
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Required: true,
Elem: &Schema{Type: TypeInt},
PromoteSingle: true,
},
},

State: nil,

Config: map[string]interface{}{
"ports": []interface{}{"5"},
},

Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
New: "1",
},
"ports.0": &terraform.ResourceAttrDiff{
Old: "",
New: "5",
},
},
},

Err: false,
},

{
Schema: map[string]*Schema{
"ports": &Schema{
Expand Down