{"record":{"id":"66434e03c823803b","repo":"hashicorp/terraform","slug":"s-s-minitems-and-maxitems-must-be-set-to-either","errorCode":null,"errorMessage":"%s%s: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode","messagePattern":"(.+?)(.+?): MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":79,"sourceCode":"\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))\n\t\t\t}\n\t\t\tif blockS.Computed {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: NestingGroup blocks cannot be computed\", prefix, name))\n\t\t\t}\n\t\tcase NestingList, NestingSet:\n\t\t\tif blockS.MinItems > blockS.MaxItems && blockS.MaxItems != 0 {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems must be less than or equal to MaxItems in %s mode\", prefix, name, blockS.Nesting))\n\t\t\t}\n\t\t\tif blockS.Nesting == NestingSet {\n\t\t\t\tety := blockS.Block.ImpliedType()\n\t\t\t\tif ety.HasDynamicTypes() {\n\t\t\t\t\t// This is not permitted because the HCL (cty) set implementation\n\t\t\t\t\t// needs to know the exact type of set elements in order to\n\t\t\t\t\t// properly hash them, and so can't support mixed types.","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L61-L97","documentation":"In NestingSingle mode (and after 817 passed, i.e. Min==Max), the common value must be 0 or 1 (checked at lines 78-79). A single block can be optional (0/0) or required (1/1); anything else is nonsensical for single nesting. Values >1 imply you want multiple, which is NestingList territory.","triggerScenarios":"Setting MinItems=MaxItems=2 (or any value >1) on a NestingSingle block, e.g. trying to require 'exactly 2' of a single block.","commonSituations":"Misusing NestingSingle as a list, generated schemas that emit a required-count onto a single block.","solutions":["Use 0/0 (optional single) or 1/1 (required single).","For multiple required blocks, switch to NestingList with MinItems=2."],"exampleFix":"// before\n\"replicas\": {Nesting: configschema.NestingSingle, MinItems: 2, MaxItems: 2}\n\n// after\n\"replicas\": {Nesting: configschema.NestingList, MinItems: 2, MaxItems: 2}","handlingStrategy":"validation","validationCode":"if nb.Nesting == configschema.NestingSingle && (nb.MinItems < 0 || nb.MinItems > 1) {\n    return fmt.Errorf(\"NestingSingle MinItems/MaxItems must be 0 or 1\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["NestingSingle means at most one instance; use list/set nesting for counts > 1.","Remember 0/0 = optional single, 1/1 = required single."],"tags":["configschema","provider-sdk","nesting-single","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}