{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/configs/configschema/internal_validate.go#L20-L56","documentation":"During schema validation, an entry in the Block's Attributes map has a nil value. Every attribute name must map to a non-nil *Attribute schema. A nil attribute pointer indicates a programming error in schema construction — a developer added an attribute key but never populated its schema definition.","triggerScenarios":"Block.Attributes map contains a key mapped to nil. Triggered when a provider (or Terraform internal code) constructs a schema with an incompletely initialized Attributes map — e.g., assigning attributes[\"foo\"] = nil instead of a populated *Attribute struct.","commonSituations":"Provider developer uses a map literal or loop that conditionally leaves entries nil. Schema generation tool produces incomplete output. terraform-plugin-sdk/schema-to-framework migration left gaps. Code path that adds attribute keys dynamically but skips some values.","solutions":["Audit the provider's schema construction code for the resource or data source named in the error.","Ensure every key in the Attributes map maps to a fully populated *configschema.Attribute (or schema.Attribute in the framework).","If using conditional attribute inclusion, use a filter step that removes keys entirely rather than setting them to nil.","Add unit tests calling InternalValidate() on the schema to catch this before release."],"exampleFix":"// before — nil attribute value in map\nAttributes: map[string]*Attribute{\n    \"name\":  {Type: String, Optional: true},\n    \"size\":  nil,  // ← bug\n}\n\n// after — all attributes populated or omitted\nAttributes: map[string]*Attribute{\n    \"name\": {Type: String, Optional: true},\n    \"size\": {Type: Int, Optional: true},\n}","handlingStrategy":"validation","validationCode":"// Provider developers: ensure no nil attribute values in schema\nfunc sanitizeAttributeMap(attrs map[string]*configschema.Attribute) map[string]*configschema.Attribute {\n    clean := make(map[string]*configschema.Attribute, len(attrs))\n    for k, v := range attrs {\n        if v == nil {\n            log.Printf(\"WARN: attribute %q has nil schema, removing\", k)\n            continue\n        }\n        clean[k] = v\n    }\n    return clean\n}\n\n// Unit test gate:\nfunc TestNoNilAttributes(t *testing.T) {\n    if err := myResourceSchema().InternalValidate(); err != nil {\n        t.Fatal(err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never add a key to the Attributes map without a fully populated *Attribute value.","Use conditional omission (skip the key) rather than nil assignment.","Gate every schema change behind an InternalValidate() unit test."],"tags":["schema","validation","provider-development","nil-pointer","attributes","internal"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}