{"record":{"id":"519476bf79511273","repo":"hashicorp/terraform","slug":"s-s-minitems-and-maxitems-cannot-be-used-in-nest","errorCode":null,"errorMessage":"%s%s: MinItems and MaxItems cannot be used in NestingGroup mode","messagePattern":"(.+?)(.+?): MinItems and MaxItems cannot be used in NestingGroup mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":83,"sourceCode":"\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.\n\t\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: NestingSet blocks may not contain attributes of cty.DynamicPseudoType\", prefix, name))\n\t\t\t\t}\n\t\t\t\tif blockS.Block.ContainsWriteOnly() {\n\t\t\t\t\t// This is not permitted because any marks within sets will","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L65-L101","documentation":"In NestingGroup mode, MinItems and MaxItems are not used - a group block is always a single, non-null group with its own defaults (the schema docs note NestingGroup guarantees a non-null result). The validator (lines 82-83) requires both to be 0; setting either to non-zero is rejected. (NestingGroup is also separately checked: it cannot be Computed, line 85-87.)","triggerScenarios":"Setting MinItems or MaxItems on a NestingGroup nested block, typically treating it like NestingList.","commonSituations":"Treating NestingGroup like NestingList, generated schemas that fill MinItems/MaxItems by default for every block.","solutions":["Leave MinItems=0 and MaxItems=0 for NestingGroup blocks (the zero value).","If you need item counting, use NestingList/NestingSet instead."],"exampleFix":"// before\n\"defaults\": {Nesting: configschema.NestingGroup, MinItems: 1, MaxItems: 1}\n\n// after\n\"defaults\": {Nesting: configschema.NestingGroup}  // MinItems=MaxItems=0 (zero value)","handlingStrategy":"validation","validationCode":"if nb.Nesting == configschema.NestingGroup && (nb.MinItems != 0 || nb.MaxItems != 0) {\n    return fmt.Errorf(\"NestingGroup must leave MinItems/MaxItems at 0\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember NestingGroup ignores item counts; only NestingList/NestingSet use them.","Default generated schemas to leave MinItems/MaxItems at zero for group blocks."],"tags":["configschema","provider-sdk","nesting-group","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}