{"record":{"id":"bef7e587fe612b01","repo":"hashicorp/terraform","slug":"s-s-minitems-and-maxitems-must-match-in-nestings","errorCode":null,"errorMessage":"%s%s: MinItems and MaxItems must match in NestingSingle mode","messagePattern":"(.+?)(.+?): MinItems and MaxItems must match in NestingSingle mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":77,"sourceCode":"\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))\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","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L59-L95","documentation":"In NestingSingle mode, MinItems and MaxItems must be equal (checked at lines 76-77): a single block is either present once or not, so there is no range. The validator first requires MinItems == MaxItems; only when they match does it then check they are 0 or 1 (rule 818).","triggerScenarios":"Setting MinItems=0, MaxItems=1 (or any unequal pair) on a NestingSingle block.","commonSituations":"Confusing NestingSingle with NestingList semantics, generating schemas with a default MaxItems=0 paired with MinItems=1.","solutions":["Set MinItems == MaxItems (both 0 for optional-single, or both 1 for required-single).","If you need a 0..N range, use NestingList/NestingSet instead of NestingSingle."],"exampleFix":"// before\n\"settings\": {Nesting: configschema.NestingSingle, MinItems: 0, MaxItems: 1}\n\n// after\n\"settings\": {Nesting: configschema.NestingSingle, MinItems: 1, MaxItems: 1}  // required single","handlingStrategy":"validation","validationCode":"if nb.Nesting == configschema.NestingSingle && nb.MinItems != nb.MaxItems {\n    return fmt.Errorf(\"NestingSingle requires MinItems == MaxItems\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["For NestingSingle always set MinItems and MaxItems to the same value.","Switch to NestingList/NestingSet when a 0..N range is needed."],"tags":["configschema","provider-sdk","nesting-single","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}