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 {
|
type nestedType struct {
|
||||||
Attributes map[string]*attribute `json:"attributes,omitempty"`
|
Attributes map[string]*attribute `json:"attributes,omitempty"`
|
||||||
NestingMode string `json:"nesting_mode,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 {
|
func marshalStringKind(sk configschema.StringKind) string {
|
||||||
|
@ -55,8 +53,6 @@ func marshalAttribute(attr *configschema.Attribute) *attribute {
|
||||||
|
|
||||||
if attr.NestedType != nil {
|
if attr.NestedType != nil {
|
||||||
nestedTy := nestedType{
|
nestedTy := nestedType{
|
||||||
MinItems: uint64(attr.NestedType.MinItems),
|
|
||||||
MaxItems: uint64(attr.NestedType.MaxItems),
|
|
||||||
NestingMode: nestingModeString(attr.NestedType.Nesting),
|
NestingMode: nestingModeString(attr.NestedType.Nesting),
|
||||||
}
|
}
|
||||||
attrs := make(map[string]*attribute, len(attr.NestedType.Attributes))
|
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 {
|
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 {
|
if a.Type != cty.NilType {
|
||||||
panic("Invalid attribute schema: NestedType and Type cannot both be set. This is a bug in the provider.")
|
panic("Invalid attribute schema: NestedType and Type cannot both be set. This is a bug in the provider.")
|
||||||
}
|
}
|
||||||
|
|
||||||
ty := a.NestedType.specType()
|
ty := a.NestedType.specType()
|
||||||
ret.Type = ty
|
ret.Type = ty
|
||||||
ret.Required = a.Required || a.NestedType.MinItems > 0
|
ret.Required = a.Required
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,17 +131,9 @@ func (a *Attribute) internalValidate(name, prefix string) error {
|
||||||
|
|
||||||
if a.NestedType != nil {
|
if a.NestedType != nil {
|
||||||
switch a.NestedType.Nesting {
|
switch a.NestedType.Nesting {
|
||||||
case NestingSingle:
|
case NestingSingle, NestingMap:
|
||||||
switch {
|
// no validations to perform
|
||||||
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 NestingList, NestingSet:
|
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 {
|
if a.NestedType.Nesting == NestingSet {
|
||||||
ety := a.NestedType.ImpliedType()
|
ety := a.NestedType.ImpliedType()
|
||||||
if ety.HasDynamicTypes() {
|
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))
|
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:
|
default:
|
||||||
err = multierror.Append(err, fmt.Errorf("%s%s: invalid nesting mode %s", prefix, name, a.NestedType.Nesting))
|
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"},
|
[]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": {
|
"attribute with invalid NestedType attribute": {
|
||||||
&Block{
|
&Block{
|
||||||
Attributes: map[string]*Attribute{
|
Attributes: map[string]*Attribute{
|
||||||
|
|
|
@ -87,13 +87,6 @@ type Object struct {
|
||||||
// many instances of the Object are allowed, how many labels it expects, and
|
// many instances of the Object are allowed, how many labels it expects, and
|
||||||
// how the resulting data will be converted into a data structure.
|
// how the resulting data will be converted into a data structure.
|
||||||
Nesting NestingMode
|
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.
|
// NestedBlock represents the embedding of one block within another.
|
||||||
|
|
|
@ -199,8 +199,6 @@ func protoObjectToConfigSchema(b *proto.Schema_Object) *configschema.Object {
|
||||||
object := &configschema.Object{
|
object := &configschema.Object{
|
||||||
Attributes: make(map[string]*configschema.Attribute),
|
Attributes: make(map[string]*configschema.Attribute),
|
||||||
Nesting: nesting,
|
Nesting: nesting,
|
||||||
MinItems: int(b.MinItems),
|
|
||||||
MaxItems: int(b.MaxItems),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range b.Attributes {
|
for _, a := range b.Attributes {
|
||||||
|
@ -295,7 +293,5 @@ func configschemaObjectToProto(b *configschema.Object) *proto.Schema_Object {
|
||||||
return &proto.Schema_Object{
|
return &proto.Schema_Object{
|
||||||
Attributes: attributes,
|
Attributes: attributes,
|
||||||
Nesting: nesting,
|
Nesting: nesting,
|
||||||
MinItems: int64(b.MinItems),
|
|
||||||
MaxItems: int64(b.MaxItems),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,6 @@ func TestConvertSchemaBlocks(t *testing.T) {
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MinItems: 3,
|
|
||||||
},
|
},
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
@ -246,7 +245,6 @@ func TestConvertSchemaBlocks(t *testing.T) {
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MinItems: 3,
|
|
||||||
},
|
},
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue