{"record":{"id":"cc71a4d74560f7a0","repo":"hashicorp/terraform","slug":"s-s-attribute-schema-is-nil","errorCode":null,"errorMessage":"%s%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":38,"sourceCode":"// This can be used within unit tests to detect when a given schema is invalid,\n// and is run when terraform loads provider schemas during NewContext.\nfunc (b *Block) InternalValidate() error {\n\tif b == nil {\n\t\treturn fmt.Errorf(\"top-level block schema is nil\")\n\t}\n\treturn b.internalValidate(\"\")\n}\n\nfunc (b *Block) internalValidate(prefix string) error {\n\tvar multiErr error\n\n\tif prefix == \"\" && !b.Deprecated && b.DeprecationMessage != \"\" {\n\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"top-level block: DeprecationMessage must not be set when Deprecated is false\"))\n\t}\n\n\tfor name, attrS := range b.Attributes {\n\t\tif attrS == nil {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: attribute schema is nil\", prefix, name))\n\t\t\tcontinue\n\t\t}\n\t\tmultiErr = errors.Join(multiErr, attrS.internalValidate(name, prefix))\n\n\t\t// all attributes within a computed block must also be computed\n\t\tif b.Computed && !attrS.Computed {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: all attributes within computed blocks must also be computed\", prefix, name))\n\t\t}\n\t}\n\n\tfor name, blockS := range b.BlockTypes {\n\t\tif blockS == nil {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: block schema is nil\", prefix, name))\n\t\t\tcontinue\n\t\t}\n\n\t\tif _, isAttr := b.Attributes[name]; isAttr {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: name defined as both attribute and child block type\", prefix, name))","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L20-L56","documentation":"A nil entry exists in a Block's Attributes map (b.Attributes[name] == nil, checked at line 37). The validator cannot recurse into a nil attribute, so it records the error and `continue`s with other attributes. Indicates a schema map built with an explicit nil value, usually a typo or an unfilled placeholder.","triggerScenarios":"Constructing Attributes with `\"foo\": nil`, appending a pointer that was never assigned, or a helper returning nil that gets stored directly (e.g. `attrs[name] = maybeAttr()` where maybeAttr returns nil).","commonSituations":"Schema builders with conditional attributes, refactor leftovers, generated schemas with an empty slot.","solutions":["Ensure every map value is a fully-populated *Attribute.","Guard builders: only insert when the attribute is non-nil.","Run InternalValidate in tests to catch it before release."],"exampleFix":"// before\nAttributes: map[string]*configschema.Attribute{\n    \"name\": nil,\n}\n\n// after\nAttributes: map[string]*configschema.Attribute{\n    \"name\": {Type: cty.String, Optional: true},\n}","handlingStrategy":"validation","validationCode":"// Strip/flag nil attributes when building a schema map.\nfor k, v := range attrs {\n    if v == nil { return fmt.Errorf(\"attribute %q is nil\", k) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assign nil into an Attributes map; omit the key instead.","When a helper may return nil, guard with `if a != nil { attrs[name] = a }`."],"tags":["configschema","provider-sdk","nil-pointer","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}