{"record":{"id":"7ca6e342d9621874","repo":"hashicorp/terraform","slug":"invalid-collection-type","errorCode":null,"errorMessage":"invalid collection type","messagePattern":"invalid collection type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/legacy/helper/schema/core_schema.go","lineNumber":223,"sourceCode":"\t\tdefault:\n\t\t\tif set != nil {\n\t\t\t\t// Should never happen for a valid schema\n\t\t\t\tpanic(fmt.Errorf(\"invalid Schema.Elem %#v; need *Schema or *Resource\", s.Elem))\n\t\t\t}\n\t\t\t// Some pre-existing schemas assume string as default, so we need\n\t\t\t// to be compatible with them.\n\t\t\telemType = cty.String\n\t\t}\n\t\tswitch s.Type {\n\t\tcase TypeList:\n\t\t\treturn cty.List(elemType)\n\t\tcase TypeSet:\n\t\t\treturn cty.Set(elemType)\n\t\tcase TypeMap:\n\t\t\treturn cty.Map(elemType)\n\t\tdefault:\n\t\t\t// can never get here in practice, due to the case we're inside\n\t\t\tpanic(\"invalid collection type\")\n\t\t}\n\tdefault:\n\t\t// should never happen for a valid schema\n\t\tpanic(fmt.Errorf(\"invalid Schema.Type %s\", s.Type))\n\t}\n}\n\n// CoreConfigSchema is a convenient shortcut for calling CoreConfigSchema on\n// the resource's schema. CoreConfigSchema adds the implicitly required \"id\"\n// attribute for top level resources if it doesn't exist.\nfunc (r *Resource) CoreConfigSchema() *configschema.Block {\n\tblock := r.coreConfigSchema()\n\n\tif block.Attributes == nil {\n\t\tblock.Attributes = map[string]*configschema.Attribute{}\n\t}\n\n\t// Add the implicitly required \"id\" field if it doesn't exist","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/legacy/helper/schema/core_schema.go#L205-L241","documentation":"A panic in `Schema.coreConfigSchemaType` (internal/legacy/helper/schema/core_schema.go:223). The outer switch already matched `TypeList`/`TypeSet`/`TypeMap`, and an inner switch over the same `s.Type` returns the corresponding cty collection type; the default branch (line 223) is annotated 'can never get here in practice'. Hitting it means the ValueType was mutated or a new collection ValueType was added without updating the inner switch — a provider-SDK internal bug.","triggerScenarios":"A Terraform provider built with the legacy helper/schema (SDK v1 style) defines a schema whose `Type` field is one of the collection type constants at the outer switch but then does not match inside the inner switch — only possible if the ValueType constants were corrupted or a custom fork redefined them.","commonSituations":"A forked/modified helper/schema package that added a new collection ValueType without updating coreConfigSchemaType; memory corruption; extremely rare in stock SDK usage. Standard SDK v1 providers never hit this.","solutions":["If you maintain a fork of helper/schema, ensure the inner switch in coreConfigSchemaType covers every collection ValueType in the outer switch.","Report against the provider SDK if using an unmodified SDK that triggers this.","Pin to a known-good version of the provider and SDK.","Audit custom ValueType constants for accidental shadowing of TypeList/TypeSet/TypeMap."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Go (provider): assert schema collection types are valid at build time\nfor name, s := range resource.Schema {\n    switch s.Type {\n    case schema.TypeList, schema.TypeSet, schema.TypeMap:\n    default:\n        if s.Elem != nil {\n            log.Panicf(\"schema %q has non-collection Type %d with Elem set\", name, s.Type)\n        }\n    }\n}","typeGuard":"// Go: confirm a ValueType is a known collection type\nfunc isCollectionType(t schema.ValueType) bool {\n    switch t { case schema.TypeList, schema.TypeSet, schema.TypeMap: return true }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Do not fork/modify the helper/schema ValueType constants without updating coreConfigSchemaType.","Add schema self-tests in providers to catch invalid types early.","Pin the helper/schema SDK version.","Treat this unreachable panic as a hard bug in any SDK fork."],"tags":["terraform","provider-sdk","legacy-schema","panic","schema-type","unreachable","internal-bug"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}