remove usage of MinItems/MaxItems
MinItems and MaxItems are not used on nested types in the protocol, so remove their usage in Terraform to prevent future confusion.
This commit is contained in:
parent
24a2bd6301
commit
9847eaa9cf
|
@ -22,8 +22,6 @@ type attribute struct {
|
|||
type nestedType struct {
|
||||
Attributes map[string]*attribute `json:"attributes,omitempty"`
|
||||
NestingMode string `json:"nesting_mode,omitempty"`
|
||||
MinItems uint64 `json:"min_items,omitempty"`
|
||||
MaxItems uint64 `json:"max_items,omitempty"`
|
||||
}
|
||||
|
||||
func marshalStringKind(sk configschema.StringKind) string {
|
||||
|
@ -55,8 +53,6 @@ func marshalAttribute(attr *configschema.Attribute) *attribute {
|
|||
|
||||
if attr.NestedType != nil {
|
||||
nestedTy := nestedType{
|
||||
MinItems: uint64(attr.NestedType.MinItems),
|
||||
MaxItems: uint64(attr.NestedType.MaxItems),
|
||||
NestingMode: nestingModeString(attr.NestedType.Nesting),
|
||||
}
|
||||
attrs := make(map[string]*attribute, len(attr.NestedType.Attributes))
|
||||
|
|
|
@ -187,17 +187,13 @@ func (a *Attribute) decoderSpec(name string) hcldec.Spec {
|
|||
}
|
||||
|
||||
if a.NestedType != nil {
|
||||
// FIXME: a panic() is a bad UX. InternalValidate() can check Attribute
|
||||
// schemas as well so a fix might be to call it when we get the schema
|
||||
// from the provider in Context(). Since this could be a breaking
|
||||
// change, we'd need to communicate well before adding that call.
|
||||
if a.Type != cty.NilType {
|
||||
panic("Invalid attribute schema: NestedType and Type cannot both be set. This is a bug in the provider.")
|
||||
}
|
||||
|
||||
ty := a.NestedType.specType()
|
||||
ret.Type = ty
|
||||
ret.Required = a.Required || a.NestedType.MinItems > 0
|
||||
ret.Required = a.Required
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
|
@ -131,17 +131,9 @@ func (a *Attribute) internalValidate(name, prefix string) error {
|
|||
|
||||
if a.NestedType != nil {
|
||||
switch a.NestedType.Nesting {
|
||||
case NestingSingle:
|
||||
switch {
|
||||
case a.NestedType.MinItems != a.NestedType.MaxItems:
|
||||
err = multierror.Append(err, fmt.Errorf("%s%s: MinItems and MaxItems must match in NestingSingle mode", prefix, name))
|
||||
case a.NestedType.MinItems < 0 || a.NestedType.MinItems > 1:
|
||||
err = multierror.Append(err, fmt.Errorf("%s%s: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode", prefix, name))
|
||||
}
|
||||
case NestingSingle, NestingMap:
|
||||
// no validations to perform
|
||||
case NestingList, NestingSet:
|
||||
if a.NestedType.MinItems > a.NestedType.MaxItems && a.NestedType.MaxItems != 0 {
|
||||
err = multierror.Append(err, fmt.Errorf("%s%s: MinItems must be less than or equal to MaxItems in %s mode", prefix, name, a.NestedType.Nesting))
|
||||
}
|
||||
if a.NestedType.Nesting == NestingSet {
|
||||
ety := a.NestedType.ImpliedType()
|
||||
if ety.HasDynamicTypes() {
|
||||
|
@ -151,10 +143,6 @@ func (a *Attribute) internalValidate(name, prefix string) error {
|
|||
err = multierror.Append(err, fmt.Errorf("%s%s: NestingSet blocks may not contain attributes of cty.DynamicPseudoType", prefix, name))
|
||||
}
|
||||
}
|
||||
case NestingMap:
|
||||
if a.NestedType.MinItems != 0 || a.NestedType.MaxItems != 0 {
|
||||
err = multierror.Append(err, fmt.Errorf("%s%s: MinItems and MaxItems must both be 0 in NestingMap mode", prefix, name))
|
||||
}
|
||||
default:
|
||||
err = multierror.Append(err, fmt.Errorf("%s%s: invalid nesting mode %s", prefix, name, a.NestedType.Nesting))
|
||||
}
|
||||
|
|
|
@ -143,21 +143,6 @@ func TestBlockInternalValidate(t *testing.T) {
|
|||
[]string{"fooBar: name may contain only lowercase letters, digits and underscores"},
|
||||
},
|
||||
*/
|
||||
"attribute with invalid NestedType nesting": {
|
||||
&Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"foo": {
|
||||
NestedType: &Object{
|
||||
Nesting: NestingSingle,
|
||||
MinItems: 10,
|
||||
MaxItems: 10,
|
||||
},
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
[]string{"foo: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode"},
|
||||
},
|
||||
"attribute with invalid NestedType attribute": {
|
||||
&Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
|
|
|
@ -87,13 +87,6 @@ type Object struct {
|
|||
// many instances of the Object are allowed, how many labels it expects, and
|
||||
// how the resulting data will be converted into a data structure.
|
||||
Nesting NestingMode
|
||||
|
||||
// MinItems and MaxItems set, for the NestingList and NestingSet nesting
|
||||
// modes, lower and upper limits on the number of child blocks allowed
|
||||
// of the given type. If both are left at zero, no limit is applied.
|
||||
// These fields are ignored for other nesting modes and must both be left
|
||||
// at zero.
|
||||
MinItems, MaxItems int
|
||||
}
|
||||
|
||||
// NestedBlock represents the embedding of one block within another.
|
||||
|
|
|
@ -199,8 +199,6 @@ func protoObjectToConfigSchema(b *proto.Schema_Object) *configschema.Object {
|
|||
object := &configschema.Object{
|
||||
Attributes: make(map[string]*configschema.Attribute),
|
||||
Nesting: nesting,
|
||||
MinItems: int(b.MinItems),
|
||||
MaxItems: int(b.MaxItems),
|
||||
}
|
||||
|
||||
for _, a := range b.Attributes {
|
||||
|
@ -295,7 +293,5 @@ func configschemaObjectToProto(b *configschema.Object) *proto.Schema_Object {
|
|||
return &proto.Schema_Object{
|
||||
Attributes: attributes,
|
||||
Nesting: nesting,
|
||||
MinItems: int64(b.MinItems),
|
||||
MaxItems: int64(b.MaxItems),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,6 @@ func TestConvertSchemaBlocks(t *testing.T) {
|
|||
Computed: true,
|
||||
},
|
||||
},
|
||||
MinItems: 3,
|
||||
},
|
||||
Required: true,
|
||||
},
|
||||
|
@ -246,7 +245,6 @@ func TestConvertSchemaBlocks(t *testing.T) {
|
|||
Computed: true,
|
||||
},
|
||||
},
|
||||
MinItems: 3,
|
||||
},
|
||||
Required: true,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue