{"record":{"id":"7ca1258dfd9ee0b7","repo":"hashicorp/terraform","slug":"s-s-minitems-and-maxitems-must-both-be-greater-t","errorCode":null,"errorMessage":"%s%s: MinItems and MaxItems must both be greater than zero","messagePattern":"(.+?)(.+?): MinItems and MaxItems must both be greater than zero","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":65,"sourceCode":"\t}\n\n\tfor name, blockS := range b.BlockTypes {\n\t\tif blockS == nil {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: block schema is nil\", prefix, name))\n\t\t\tcontinue\n\t\t}\n\n\t\tif _, isAttr := b.Attributes[name]; isAttr {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: name defined as both attribute and child block type\", prefix, name))\n\t\t} else if !validName.MatchString(name) {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: name may contain only lowercase letters, digits and underscores\", prefix, name))\n\t\t}\n\t\tif !blockS.Deprecated && blockS.DeprecationMessage != \"\" {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: DeprecationMessage must not be set when Deprecated is false\", prefix, name))\n\t\t}\n\n\t\tif blockS.MinItems < 0 || blockS.MaxItems < 0 {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems must both be greater than zero\", prefix, name))\n\t\t}\n\n\t\t// any nested blocks within a computed block must also be computed\n\t\tif b.Computed && !blockS.Computed {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: all nested blocks within computed blocks must also be computed\", prefix, name))\n\t\t}\n\n\t\tswitch blockS.Nesting {\n\t\tcase NestingSingle:\n\t\t\tswitch {\n\t\t\tcase blockS.MinItems != blockS.MaxItems:\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems must match in NestingSingle mode\", prefix, name))\n\t\t\tcase blockS.MinItems < 0 || blockS.MinItems > 1:\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode\", prefix, name))\n\t\t\t}\n\t\tcase NestingGroup:\n\t\t\tif blockS.MinItems != 0 || blockS.MaxItems != 0 {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems cannot be used in NestingGroup mode\", prefix, name))","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L47-L83","documentation":"MinItems or MaxItems is negative (< 0, checked at line 64). The message wording ('must both be greater than zero') is slightly imprecise - the actual check only forbids negatives; zero is allowed and is the default meaning 'no limit'. It catches schemas that set, e.g., MinItems: -1 by mistake.","triggerScenarios":"Assigning a sentinel like -1, an underflow, or a computed MinItems expression that yields a negative value.","commonSituations":"Trying to express 'optional' with -1, copying another field's value incorrectly, off-by-one bugs in schema generation.","solutions":["Set MinItems/MaxItems to 0 (no limit) or a positive integer.","For 'required single', use NestingSingle with MinItems=MaxItems=1."],"exampleFix":"// before\n\"items\": {Nesting: configschema.NestingList, MinItems: -1, MaxItems: 0}\n\n// after\n\"items\": {Nesting: configschema.NestingList, MinItems: 0, MaxItems: 0}","handlingStrategy":"validation","validationCode":"if nb.MinItems < 0 || nb.MaxItems < 0 {\n    return fmt.Errorf(\"MinItems/MaxItems must not be negative\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 0 as the default/no-limit sentinel; never use negatives.","Use NestingSingle with 1/1 for 'required single', not negative counts."],"tags":["configschema","provider-sdk","minitems-maxitems","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}