{"record":{"id":"11d4b1feb22ec6a8","repo":"hashicorp/terraform","slug":"object-schema-nesting-mode-is-invalid","errorCode":null,"errorMessage":"object schema nesting mode is invalid","messagePattern":"object schema nesting mode is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":208,"sourceCode":"\t\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: invalid nesting mode %s\", prefix, name, a.NestedType.Nesting))\n\t\t}\n\t\tfor name, attrS := range a.NestedType.Attributes {\n\t\t\tif attrS == nil {\n\t\t\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: attribute schema is nil\", prefix, name))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\terr = errors.Join(err, attrS.internalValidate(name, prefix))\n\t\t}\n\t}\n\n\treturn err\n}\n\nfunc (o *Object) InternalValidate() error {\n\tvar err error\n\n\tif o.Nesting == nestingModeInvalid {\n\t\treturn fmt.Errorf(\"object schema nesting mode is invalid\")\n\t}\n\n\tfor name, attrS := range o.Attributes {\n\t\tif attrS == nil {\n\t\t\terr = errors.Join(err, fmt.Errorf(\"%s: attribute schema is nil\", name))\n\t\t\tcontinue\n\t\t}\n\t\terr = errors.Join(err, attrS.internalValidate(name, \"\"))\n\t}\n\n\treturn err\n}\n","sourceCodeStart":190,"sourceCodeEnd":221,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L190-L221","documentation":"Raised by Object.InternalValidate when the Object's Nesting field equals nestingModeInvalid (the zero value). Every Object must declare a valid NestingMode so the decoder knows how to interpret the structure; the zero value means the field was never set. The check at internal_validate.go:207 short-circuits the whole validation.","triggerScenarios":"Code constructs an Object literal without setting Nesting (leaving it as nestingModeInvalid == 0) and calls InternalValidate on it. The nil/zero check at line 207 returns immediately.","commonSituations":"Building an Object programmatically and forgetting the Nesting field; deserializing an Object from a format where the nesting key was absent; refactoring that constructs the Object in a helper not setting all required fields.","solutions":["Set Object.Nesting to a valid NestingMode constant (NestingSingle, NestingGroup, NestingList, NestingSet, NestingMap).","If the Object is deserialized, validate the incoming nesting value before constructing it.","Add a unit test that calls InternalValidate on every Object the provider defines."],"exampleFix":"// before\nobj := &Object{Attributes: map[string]*Attribute{...}}\n\n// after\nobj := &Object{Nesting: NestingSingle, Attributes: map[string]*Attribute{...}}","handlingStrategy":"validation","validationCode":"func assertObjectNestingValid(o *configschema.Object) error {\n    if o.Nesting == configschema.nestingModeInvalid {\n        return fmt.Errorf(\"object schema nesting mode is invalid\")\n    }\n    return nil\n}","typeGuard":"func hasValidNestingMode(o *configschema.Object) bool {\n    return o.Nesting != configschema.nestingModeInvalid\n}","tryCatchPattern":null,"preventionTips":["Always set Object.Nesting to a valid constant when constructing an Object.","Validate deserialized Objects before registering them in a schema.","Call Object.InternalValidate in unit tests covering every Object the provider defines."],"tags":["configschema","object","nesting-mode","zero-value","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}