{"record":{"id":"2b473d9a726db318","repo":"hashicorp/terraform","slug":"s-attribute-schema-is-nil","errorCode":null,"errorMessage":"%s: attribute schema is nil","messagePattern":"(.+?): attribute schema is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":213,"sourceCode":"\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":195,"sourceCodeEnd":221,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/configs/configschema/internal_validate.go#L195-L221","documentation":"Sibling of [844] but on the Object validator: while iterating Object.Attributes, a nil *Attribute was found for some name. The error is reported as just the attribute name (no prefix), and the loop continues so the rest of the schema is still validated. It is a structural defect in the Object's attribute map.","triggerScenarios":"Object.Attributes map containing a key mapped to nil — same shape as [844] but at the Object (typically top-level resource) layer rather than inside a NestedType. Common when assembling the root resource schema and leaving placeholder nils for attributes filled in elsewhere.","commonSituations":"Provider resource schema builders that allocate the map with all expected keys then conditionally populate them; schema merge operations that fail to delete a key when its value was removed; deserialization that maps unknown attribute names to nil.","solutions":["Remove nil-valued entries from Object.Attributes so every key has a concrete *Attribute.","Replace each nil with a minimal valid *Attribute ({Type: cty.X, Optional: true}) or delete the key.","Centralize Object construction behind a builder that rejects nil values at insert time."],"exampleFix":"// before\nschema := &configschema.Block{\n    Attributes: map[string]*configschema.Attribute{\n        \"id\": {Type: cty.String, Computed: true},\n        \"name\": nil,\n    },\n}\n\n// after\nschema := &configschema.Block{\n    Attributes: map[string]*configschema.Attribute{\n        \"id\":   {Type: cty.String, Computed: true},\n        \"name\": {Type: cty.String, Optional: true},\n    },\n}","handlingStrategy":"validation","validationCode":"func stripNilObjectAttributes(o *configschema.Object) {\n    if o == nil { return }\n    for name, a := range o.Attributes {\n        if a == nil { delete(o.Attributes, name) }\n    }\n}","typeGuard":"func objectHasNoNilAttrs(o *configschema.Object) bool {\n    if o == nil { return true }\n    for _, a := range o.Attributes {\n        if a == nil { return false }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Build the Object.Attributes map in one pass with all values populated.","Use helper functions that always return a non-nil *Attribute.","Sweep for nils in a test helper before InternalValidate."],"tags":["schema-validation","configschema","nil-guard","go"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}