{"record":{"id":"b1204a8c0a851a7c","repo":"opentofu/opentofu","slug":"ephemeral-resources-are-not-meant-to-be-processed","errorCode":null,"errorMessage":"ephemeral resources are not meant to be processed by this function. Are you sure that this code should be reused?","messagePattern":"ephemeral resources are not meant to be processed by this function\\. Are you sure that this code should be reused\\?","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/legacy/tofu/resource.go","lineNumber":130,"sourceCode":"\tpath := make([]string, len(addr.Module))\n\tfor i, step := range addr.Module {\n\t\tif step.InstanceKey != addrs.NoKey {\n\t\t\tpanic(\"NewInstanceInfo cannot convert module instance with key\")\n\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.Resource.Mode == addrs.EphemeralResourceMode {\n\t\tpanic(\"ephemeral resources are not meant to be processed by this function. Are you sure that this code should be reused?\")\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// ResourceAddress returns the address of the resource that the receiver is describing.","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/legacy/tofu/resource.go#L112-L148","documentation":"NewInstanceInfo panics when given a resource in addrs.EphemeralResourceMode. Ephemeral resources postdate the legacy provider protocols that InstanceInfo serves and never flow through legacy diff/state machinery; the panic message itself asks whether the code path should be reused for them.","triggerScenarios":"Passing an AbsResourceInstance whose Resource.Resource.Mode is addrs.EphemeralResourceMode into NewInstanceInfo — typically generic address-formatting or logging code that handles all resource modes uniformly.","commonSituations":"Adding ephemeral resource support to a codebase that already calls NewInstanceInfo; refactoring shared helpers that enumerate resources of every mode; new provider features routed through legacy plumbing by mistake.","solutions":["Branch on addr.Resource.Resource.Mode before calling and handle ephemeral resources on modern code paths only","Do not route ephemeral resources through legacy tofu types; use providers/addrs modern APIs instead","If the panic fired, treat it as a design signal: this legacy function must not be reused for the new mode"],"exampleFix":"// before\ninfo := NewInstanceInfo(instAddr)\n\n// after\nif instAddr.Resource.Resource.Mode == addrs.EphemeralResourceMode {\n\treturn nil, fmt.Errorf(\"ephemeral resource %s must not use legacy InstanceInfo\", instAddr)\n}\ninfo := NewInstanceInfo(instAddr)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isEphemeralResource(a addrs.AbsResourceInstance) bool {\n\treturn a.Resource.Resource.Mode == addrs.EphemeralResourceMode\n}","tryCatchPattern":null,"preventionTips":["Branch on ResourceMode before calling NewInstanceInfo; ephemeral resources must stay on modern paths","Never reuse legacy provider-facing helpers for ephemeral resources — the panic is by design","Add a mode check to generic address-formatting utilities"],"tags":["go","opentofu","ephemeral-resources","legacy-shim","panic"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}