{"record":{"id":"377536a424386dcf","repo":"pulumi/pulumi","slug":"resource-id-is-required-for-lookup-and-cannot-be-e","errorCode":null,"errorMessage":"resource ID is required for lookup and cannot be empty","messagePattern":"resource ID is required for lookup and cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/pulumi/context.go","lineNumber":1377,"sourceCode":"// And invoke ReadPackageResource like so:\n//\n//\tvar resource MyResource\n//\terr := ctx.ReadPackageResource(tok, name, id, nil, &resource, opts...)\nfunc (ctx *Context) ReadPackageResource(\n\tt, name string, id IDInput, props Input, resource CustomResource, packageRef string, opts ...ResourceOption,\n) error {\n\treturn ctx.readPackageResource(t, name, id, props, resource, packageRef, opts...)\n}\n\nfunc (ctx *Context) readPackageResource(\n\tt, name string, id IDInput, props Input, resource CustomResource, packageRef string, opts ...ResourceOption,\n) error {\n\tif t == \"\" {\n\t\treturn errors.New(\"resource type argument cannot be empty\")\n\t} else if name == \"\" {\n\t\treturn errors.New(\"resource name argument (for URN creation) cannot be empty\")\n\t} else if id == nil {\n\t\treturn errors.New(\"resource ID is required for lookup and cannot be empty\")\n\t}\n\n\tif props != nil {\n\t\tpropsType := reflect.TypeOf(props)\n\t\tif propsType.Kind() == reflect.Pointer {\n\t\t\tpropsType = propsType.Elem()\n\t\t}\n\t\t//nolint:staticcheck // Not applying de-morgens law right now\n\t\tif !(propsType.Kind() == reflect.Struct ||\n\t\t\t(propsType.Kind() == reflect.Map && propsType.Key().Kind() == reflect.String)) {\n\t\t\treturn errors.New(\"props must be a struct or map or a pointer to a struct or map\")\n\t\t}\n\t}\n\n\toptions := merge(opts...)\n\tparent := options.Parent\n\tif options.Parent == nil {\n\t\toptions.Parent = ctx.state.stack","sourceCodeStart":1359,"sourceCodeEnd":1395,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi/context.go#L1359-L1395","documentation":"A resource lookup (readPackageResource, exposed via ctx.GetResource) requires the ID of the existing resource to look up. Passing a nil IDInput means there is nothing to search for, so the SDK errors immediately: \"resource ID is required for lookup and cannot be empty\". Lookups are read-only operations against the engine and are meaningless without an identifier.","triggerScenarios":"Calling ctx.GetResource(token, name, nil), or passing an ID variable that is a nil pulumi.IDInput (zero value of an interface), e.g. an uninitialized *pulumi.String.","commonSituations":"Declaring `var id pulumi.IDInput` and forgetting to assign it; passing an output whose wrapped value is nil instead of an ID; converting code from RegisterResource (ID optional) to GetResource (ID required).","solutions":["Pass a concrete ID, e.g. ctx.GetResource(tok, name, pulumi.ID(\"i-abc123\")) or the .ID() output of an existing resource reference.","If the ID comes from an output, await/ensure it is non-nil before the lookup.","If you don't know the ID, use ctx.GetResource with a provider-specific lookup or RegisterResource-style import instead."],"exampleFix":"// before\nvar id pulumi.IDInput\nres, err := ctx.GetResource(\"aws:ec2/instance:Instance\", \"web\", id)\n// after\nres, err := ctx.GetResource(\"aws:ec2/instance:Instance\", \"web\", pulumi.ID(\"i-0abcd1234efgh5678\"))","handlingStrategy":"type-guard","validationCode":"if id == nil {\n    return fmt.Errorf(\"GetResource requires a non-nil ID\")\n}","typeGuard":"func hasID(id pulumi.IDInput) bool { return id != nil }","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"resource ID is required\") {\n        return fmt.Errorf(\"cannot look up %s: no ID available\", name)\n    }\n    return err\n}","preventionTips":["Remember GetResource (lookup) always needs an ID, unlike RegisterResource","Await outputs to concrete IDs before lookups when the value comes from another resource","Avoid zero-value interface variables for IDInput; construct with pulumi.ID(...)"],"tags":["go-sdk","pulumi","validation","resource-lookup"],"backgroundTag":"missing-required-argument","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}