{"record":{"id":"8612e4d54d603bfb","repo":"hashicorp/terraform","slug":"newinstanceinfo-cannot-convert-resource-instance-w","errorCode":null,"errorMessage":"NewInstanceInfo cannot convert resource instance with %T instance key","messagePattern":"NewInstanceInfo cannot convert resource instance with %T instance key","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/legacy/terraform/resource.go","lineNumber":81,"sourceCode":"\t\t}\n\t\tpath[i] = step.Name\n\t}\n\n\t// This is a funny old meaning of \"id\" that is no longer current. It should\n\t// not be used for anything users might see. Note that it does not include\n\t// a representation of the resource mode, and so it's impossible to\n\t// determine from an InstanceInfo alone whether it is a managed or data\n\t// resource that is being referred to.\n\tid := fmt.Sprintf(\"%s.%s\", addr.Resource.Resource.Type, addr.Resource.Resource.Name)\n\tif addr.Resource.Resource.Mode == addrs.DataResourceMode {\n\t\tid = \"data.\" + id\n\t}\n\tif addr.Resource.Key != addrs.NoKey {\n\t\tswitch k := addr.Resource.Key.(type) {\n\t\tcase addrs.IntKey:\n\t\t\tid = id + fmt.Sprintf(\".%d\", int(k))\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"NewInstanceInfo cannot convert resource instance with %T instance key\", addr.Resource.Key))\n\t\t}\n\t}\n\n\treturn &InstanceInfo{\n\t\tId:         id,\n\t\tModulePath: path,\n\t\tType:       addr.Resource.Resource.Type,\n\t}\n}\n\n// ResourceConfig is a legacy type that was formerly used to represent\n// interpolatable configuration blocks. It is now only used to shim to old\n// APIs that still use this type, via NewResourceConfigShimmed.\ntype ResourceConfig struct {\n\tComputedKeys []string\n\tRaw          map[string]interface{}\n\tConfig       map[string]interface{}\n}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/legacy/terraform/resource.go#L63-L99","documentation":"Panics in NewInstanceInfo (resource.go:81). The legacy type can only represent resource instances with NoKey or IntKey (count); a string key produced by for_each hits the default branch and panics.","triggerScenarios":"A resource created with `for_each` (string keys) is routed through the legacy InstanceInfo path.","commonSituations":"An older provider/SDK used with for_each on a managed resource that exercises legacy code paths.","solutions":["Upgrade the provider/SDK so the resource no longer goes through legacy InstanceInfo.","Replace for_each with count (integer keys) on the affected resource.","Reorganize the config so the resource is not in a for_each block."],"exampleFix":"// before\nresource \"x\" \"y\" { for_each = toset([\"a\",\"b\"]) }\n// after\nresource \"x\" \"y\" { count = 2 }","handlingStrategy":"validation","validationCode":"func resourceKeyLegacyOk(addr addrs.AbsResourceInstance) error {\n    switch k := addr.Resource.Key.(type) {\n    case addrs.NoKey, addrs.IntKey: return nil\n    default: return fmt.Errorf(\"resource instance key %T unsupported by legacy InstanceInfo\", k)\n    }\n}","typeGuard":"func isLegacyCompatibleKey(k addrs.InstanceKey) bool {\n    switch k.(type) {\n    case addrs.NoKey, addrs.IntKey: return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Use count (IntKey) instead of for_each (string keys) where legacy paths are involved.","Upgrade provider/SDK.","Reorganize resources out of for_each blocks."],"tags":["terraform","resource","instance-key","for-each","legacy","panic"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}