{"record":{"id":"f1860f07b2234e32","repo":"hashicorp/terraform","slug":"s-s-minitems-and-maxitems-must-both-be-0-in-nest","errorCode":null,"errorMessage":"%s%s: MinItems and MaxItems must both be 0 in NestingMap mode","messagePattern":"(.+?)(.+?): MinItems and MaxItems must both be 0 in NestingMap mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":112,"sourceCode":"\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\n\t\t\t\t\t// be hoisted up the outer set value, so only the set itself\n\t\t\t\t\t// can be WriteOnly.\n\t\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: NestingSet blocks may not contain WriteOnly attributes\", prefix, name))\n\t\t\t\t}\n\t\t\t}\n\t\t\tif blockS.MinItems > 0 && blockS.Computed {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: Computed cannot be used when MinItems > 0\", prefix, name))\n\t\t\t}\n\t\tcase NestingMap:\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 must both be 0 in NestingMap mode\", prefix, name))\n\t\t\t}\n\t\t\tif blockS.MinItems > 0 && blockS.Computed {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: Computed cannot be used when MinItems > 0\", prefix, name))\n\t\t\t}\n\t\tdefault:\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: invalid nesting mode %s\", prefix, name, blockS.Nesting))\n\t\t}\n\n\t\tsubPrefix := prefix + name + \".\"\n\t\tmultiErr = errors.Join(multiErr, blockS.Block.internalValidate(subPrefix))\n\t}\n\n\treturn multiErr\n}\n\n// InternalValidate returns an error if the receiving attribute and its child\n// schema definitions have any inconsistencies with the documented rules for\n// valid schema.","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L94-L130","documentation":"Raised for NestingMap blocks when MinItems or MaxItems is non-zero. NestingMap derives its cardinality from the map keys the user supplies, so explicit item counts are meaningless and ignored by the decoder; the validator at internal_validate.go:111 enforces that both are zero.","triggerScenarios":"A NestedBlock with Nesting=NestingMap and MinItems != 0 or MaxItems != 0. The NestingMap case at line 110 reaches line 111 and the inequality holds.","commonSituations":"Changing a NestingList to NestingMap without clearing inherited MinItems/MaxItems; schema generators that populate cardinality for every block uniformly; copy-pasting a list block and only flipping the Nesting constant.","solutions":["Set both MinItems and MaxItems to 0 for the NestingMap block.","If you truly need a minimum number of named entries, enforce it in plan-time resource logic rather than schema cardinality.","Lint schemas in CI with InternalValidate so stray counts fail the build, not runtime."],"exampleFix":"// before\n&NestedBlock{Nesting: NestingMap, MinItems: 1, MaxItems: 5}\n\n// after\n&NestedBlock{Nesting: NestingMap, MinItems: 0, MaxItems: 0}","handlingStrategy":"validation","validationCode":"func assertMapZeroCardinality(nb *configschema.NestedBlock) error {\n    if nb.Nesting == configschema.NestingMap && (nb.MinItems != 0 || nb.MaxItems != 0) {\n        return fmt.Errorf(\"NestingMap requires MinItems==0 and MaxItems==0\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["NestingMap cardinality is derived from user-supplied keys — never set Min/MaxItems.","When changing Nesting modes, clear all mode-incompatible fields in the same edit.","Lint schemas to reject non-zero cardinality on map blocks."],"tags":["configschema","nesting-map","minitems","maxitems","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}