{"record":{"id":"f7523de60768a7a5","repo":"hashicorp/terraform","slug":"attribute-schema-is-nil","errorCode":null,"errorMessage":"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":133,"sourceCode":"\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: Computed cannot be used when MinItems > 0\", prefix, name))\n\t\t\t}\n\t\tdefault:\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: invalid nesting mode %s\", prefix, name, blockS.Nesting))\n\t\t}\n\n\t\tsubPrefix := prefix + name + \".\"\n\t\tmultiErr = errors.Join(multiErr, blockS.Block.internalValidate(subPrefix))\n\t}\n\n\treturn multiErr\n}\n\n// InternalValidate returns an error if the receiving attribute and its child\n// schema definitions have any inconsistencies with the documented rules for\n// valid schema.\nfunc (a *Attribute) InternalValidate(name string) error {\n\tif a == nil {\n\t\treturn fmt.Errorf(\"attribute schema is nil\")\n\t}\n\treturn a.internalValidate(name, \"\")\n}\n\nfunc (a *Attribute) internalValidate(name, prefix string) error {\n\tvar err error\n\n\t/* FIXME: this validation breaks certain existing providers and cannot be enforced without coordination.\n\tif !validName.MatchString(name) {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: name may contain only lowercase letters, digits and underscores\", prefix, name))\n\t}\n\t*/\n\tif !a.Optional && !a.Required && !a.Computed {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: must set Optional, Required or Computed\", prefix, name))\n\t}\n\tif a.Optional && a.Required {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: cannot set both Optional and Required\", prefix, name))\n\t}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L115-L151","documentation":"Raised by Attribute.InternalValidate when called on a nil *Attribute receiver. This is the public entry point at internal_validate.go:131; a nil receiver means the caller asked to validate an attribute that was never constructed.","triggerScenarios":"Code calls someAttr.InternalValidate(name) where someAttr is a nil *Attribute. The nil check at line 132 returns the error before any field access.","commonSituations":"Lookups like attrs[\"missing_key\"] returning nil and being validated without a nil check; refactoring that moved attribute construction into a helper returning nil on an error path; deserialization producing nil pointers for omitted keys.","solutions":["Guard the call site: if attr != nil { attr.InternalValidate(name) }.","Fix the upstream construction so the *Attribute is always populated before validation.","Prefer validating the whole Block via Block.InternalValidate, which already skips nil entries with a clearer per-name message (error 838)."],"exampleFix":"// before\nattr := attrs[key]   // nil if absent\nif err := attr.InternalValidate(key); err != nil { return err }\n\n// after\nattr, ok := attrs[key]\nif !ok || attr == nil { continue }\nif err := attr.InternalValidate(key); err != nil { return err }","handlingStrategy":"type-guard","validationCode":"if attr == nil {\n    return fmt.Errorf(\"attribute %q is nil before validate\", name)\n}\nreturn attr.InternalValidate(name)","typeGuard":"func isNonNilAttribute(a *configschema.Attribute) bool { return a != nil }","tryCatchPattern":null,"preventionTips":["Prefer Block.InternalValidate, which skips nil attribute entries with a clearer per-name message.","Nil-check any *Attribute retrieved from a map before calling methods on it.","Construct attributes via helpers that return an error rather than nil on failure."],"tags":["configschema","nil-pointer","attribute","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}