{"record":{"id":"2ab403f0516db978","repo":"hashicorp/terraform","slug":"s-s-invalid-nesting-mode-s","errorCode":null,"errorMessage":"%s%s: invalid nesting mode %s","messagePattern":"(.+?)(.+?): invalid nesting mode (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":118,"sourceCode":"\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.\nfunc (a *Attribute) InternalValidate(name string) error {\n\tif a == nil {\n\t\treturn fmt.Errorf(\"attribute schema is nil\")\n\t}\n\treturn a.internalValidate(name, \"\")\n}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L100-L136","documentation":"Raised for a NestedBlock whose Nesting field is not one of the defined NestingMode constants (NestingSingle, NestingGroup, NestingList, NestingSet, NestingMap). This usually means the zero value nestingModeInvalid (0) was left in place, or a custom/integer value was assigned incorrectly. The default branch at internal_validate.go:117 catches it and prints the offending value.","triggerScenarios":"A NestedBlock struct constructed without setting Nesting, leaving it as the zero value (nestingModeInvalid == 0), or assigned an out-of-range integer cast to NestingMode. The switch at line 73 falls through to default at line 117.","commonSituations":"Initializing a NestedBlock with a struct literal that omits the Nesting field; partially unmarshalling a schema from JSON/YAML where the nesting key was absent; copying a constant from a different fork whose iota ordering differs.","solutions":["Set Nesting to an explicit valid NestingMode constant (NestingSingle, NestingGroup, NestingList, NestingSet, or NestingMap).","If the schema is deserialized, validate the incoming nesting value against the known constants before constructing the NestedBlock.","Add a go vet / linter rule or unit test asserting every BlockTypes entry has a non-zero, valid Nesting."],"exampleFix":"// before\nBlockTypes: map[string]*NestedBlock{\n    \"thing\": {Block: Block{Attributes: ...}}, // Nesting omitted -> 0\n}\n\n// after\nBlockTypes: map[string]*NestedBlock{\n    \"thing\": {Nesting: NestingList, Block: Block{Attributes: ...}},\n}","handlingStrategy":"validation","validationCode":"func assertValidNesting(nb *configschema.NestedBlock) error {\n    switch nb.Nesting {\n    case configschema.NestingSingle, configschema.NestingGroup,\n        configschema.NestingList, configschema.NestingSet, configschema.NestingMap:\n        return nil\n    default:\n        return fmt.Errorf(\"invalid nesting mode %d\", nb.Nesting)\n    }\n}","typeGuard":"func hasValidNesting(nb *configschema.NestedBlock) bool {\n    switch nb.Nesting {\n    case configschema.NestingSingle, configschema.NestingGroup,\n        configschema.NestingList, configschema.NestingSet, configschema.NestingMap:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Always set Nesting explicitly in every NestedBlock literal — never rely on the zero value.","If deserializing schemas, validate the nesting key against the known constants before constructing.","Add a go vet-style test that iterates BlockTypes and fails on any zero Nesting."],"tags":["configschema","nesting-mode","zero-value","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}