{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L195-L221","documentation":"Thrown by Object.InternalValidate (internal_validate.go:213) when iterating over an Object schema's Attributes map and encountering a nil value for an attribute. InternalValidate is designed to catch provider schema construction bugs before the schema is used; a nil attribute pointer means the provider code built an incomplete or malformed NestedType/Object schema. This is a developer-time invariant check, not a user-input error.","triggerScenarios":"A provider plugin or schema-building code path constructs a configschema.Object (or NestedType with Nesting mode) whose Attributes map contains a key mapped to a nil *Attribute. Calling InternalValidate() on that object, or loading provider schemas during NewContext, triggers the check at line 211-214.","commonSituations":"Provider developers programmatically building block types with NestedType objects and forgetting to populate one attribute, or copy-paste schema construction that leaves a placeholder nil. Using cty.DynamicPseudoType in contexts where a concrete attribute should be. Schema generated from reflection or code-gen that omits a field.","solutions":["Inspect the InternalValidate error message: the %s placeholder names the attribute key whose value is nil — find that key in your schema construction code and ensure a non-nil *Attribute is assigned.","Add a nil check in your schema builder before inserting into the Attributes map, or use a helper that never leaves attributes unset.","Run InternalValidate inside provider unit tests (the doc comment says it is designed for that) so this surfaces in CI rather than at runtime.","If generating schemas dynamically, validate the generator output with InternalValidate before returning it from the provider server."],"exampleFix":"// before\nobj := &configschema.Object{\n    Nesting: configschema.NestingModeSingle,\n    Attributes: map[string]*configschema.Attribute{\n        \"name\": {Type: cty.String, Optional: true},\n        \"tags\": nil, // bug: left nil\n    },\n}\n\n// after\nobj := &configschema.Object{\n    Nesting: configschema.NestingModeSingle,\n    Attributes: map[string]*configschema.Attribute{\n        \"name\": {Type: cty.String, Optional: true},\n        \"tags\": {Type: cty.Map(cty.String), Optional: true},\n    },\n}","handlingStrategy":"validation","validationCode":"// Before exposing a schema, validate it; nil attribute pointers fail fast here\nif err := block.InternalValidate(); err != nil {\n    return nil, fmt.Errorf(\"provider schema is invalid: %w\", err)\n}\n// Guard during construction so InternalValidate never sees nil:\nfor name, attr := range obj.Attributes {\n    if attr == nil {\n        return fmt.Errorf(\"attribute %q must not be nil\", name)\n    }\n}","typeGuard":"func isCompleteObject(o *configschema.Object) bool {\n    if o == nil || o.Attributes == nil {\n        return false\n    }\n    for _, attr := range o.Attributes {\n        if attr == nil {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Always call InternalValidate() on provider schemas inside unit tests (the doc comment recommends this).","Never insert nil into an Attributes map; use a helper that constructs fully-populated *Attribute values.","If generating schemas dynamically, assert every attribute is non-nil before returning the schema."],"tags":["schema","configschema","provider-development","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}