{"record":{"id":"dd55d8c2e18c9cfc","repo":"hashicorp/terraform","slug":"invalid-set-element-type","errorCode":null,"errorMessage":"invalid set element type","messagePattern":"invalid set element type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/legacy/helper/schema/schema.go","lineNumber":352,"sourceCode":"\treturn nil, nil\n}\n\n// Returns a zero value for the schema.\nfunc (s *Schema) ZeroValue() interface{} {\n\t// If it's a set then we'll do a bit of extra work to provide the\n\t// right hashing function in our empty value.\n\tif s.Type == TypeSet {\n\t\tsetFunc := s.Set\n\t\tif setFunc == nil {\n\t\t\t// Default set function uses the schema to hash the whole value\n\t\t\telem := s.Elem\n\t\t\tswitch t := elem.(type) {\n\t\t\tcase *Schema:\n\t\t\t\tsetFunc = HashSchema(t)\n\t\t\tcase *Resource:\n\t\t\t\tsetFunc = HashResource(t)\n\t\t\tdefault:\n\t\t\t\tpanic(\"invalid set element type\")\n\t\t\t}\n\t\t}\n\t\treturn &Set{F: setFunc}\n\t} else {\n\t\treturn s.Type.Zero()\n\t}\n}\n\nfunc (s *Schema) finalizeDiff(d *terraform.ResourceAttrDiff, customized bool) *terraform.ResourceAttrDiff {\n\tif d == nil {\n\t\treturn d\n\t}\n\n\tif s.Type == TypeBool {\n\t\tnormalizeBoolString := func(s string) string {\n\t\t\tswitch s {\n\t\t\tcase \"0\":\n\t\t\t\treturn \"false\"","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/legacy/helper/schema/schema.go#L334-L370","documentation":"Panics in Schema.ZeroValue (schema.go:352) when building a zero-value Set for a TypeSet that has no custom Set function. It hashes elements using s.Elem and only handles *Schema and *Resource; any other concrete Elem (nil, a ValueType, a struct) panics with 'invalid set element type'.","triggerScenarios":"Declaring a TypeSet Schema with Elem set to a non-Schema/non-Resource value (commonly `Elem: schema.TypeString` instead of `Elem: &schema.Schema{Type: schema.TypeString}`), or Elem left nil with no custom Set func, then accessing ZeroValue (e.g. GetOk/Get on an empty set).","commonSituations":"Provider authors confuse Elem (which must be &schema.Schema/&schema.Resource) with Type; or omit Elem entirely on a TypeSet.","solutions":["Set Elem to &schema.Schema{Type: ...} or &schema.Resource{Schema: ...}.","Alternatively provide a custom Set (hash) function, which bypasses this code path entirely.","Lint provider schemas for TypeSet entries lacking a valid Elem."],"exampleFix":"// before\n\"roles\": { Type: schema.TypeSet, Elem: schema.TypeString },\n// after\n\"roles\": { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString} },","handlingStrategy":"type-guard","validationCode":"for k, s := range r.Schema {\n    if s.Type == schema.TypeSet && s.Set == nil && !isSchemaOrResource(s.Elem) {\n        return fmt.Errorf(\"%s: TypeSet Elem must be *Schema or *Resource\", k)\n    }\n}","typeGuard":"func isSchemaOrResource(v interface{}) bool {\n    switch v.(type) {\n    case *schema.Schema, *schema.Resource: return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Never set Elem to a bare ValueType on a TypeSet.","Provide a custom Set func if Elem cannot be a *Schema/*Resource.","Lint provider schemas for TypeSet with invalid Elem."],"tags":["terraform","provider-sdk","schema","set","panic"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}