{"record":{"id":"21bfb877fb45ec3c","repo":"pulumi/pulumi","slug":"malformed-resource-reference-for-q-id-not-a-stri-21bfb8","errorCode":null,"errorMessage":"malformed resource reference for %q: id not a string","messagePattern":"malformed resource reference for %q: id not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/common/resource/plugin/rpc.go","lineNumber":529,"sourceCode":"\t\t\tif typeProp, ok := obj[\"type\"]; ok {\n\t\t\t\tif !typeProp.IsString() {\n\t\t\t\t\treturn nil, fmt.Errorf(\"malformed resource reference for %q: type not a string\", key)\n\t\t\t\t}\n\t\t\t\ttyp = typeProp.StringValue()\n\t\t\t}\n\n\t\t\tid, hasID := \"\", false\n\t\t\tif idProp, ok := obj[\"id\"]; ok {\n\t\t\t\thasID = true\n\t\t\t\tswitch {\n\t\t\t\tcase idProp.IsString():\n\t\t\t\t\tid = idProp.StringValue()\n\t\t\t\tcase idProp.IsComputed():\n\t\t\t\t\t// Leave the ID empty to indicate that it is unknown.\n\t\t\t\tcase idProp.IsOutput():\n\t\t\t\t\tif idProp.OutputValue().Known {\n\t\t\t\t\t\tif !idProp.OutputValue().Element.IsString() {\n\t\t\t\t\t\t\treturn nil, fmt.Errorf(\"malformed resource reference for %q: id not a string\", key)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tid = idProp.OutputValue().Element.StringValue()\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn nil, fmt.Errorf(\"malformed resource reference for %q: id not a string\", key)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvar packageVersion string\n\t\t\tif packageVersionProp, ok := obj[\"packageVersion\"]; ok {\n\t\t\t\tif !packageVersionProp.IsString() {\n\t\t\t\t\treturn nil, fmt.Errorf(\"malformed resource reference for %q: packageVersion not a string\", key)\n\t\t\t\t}\n\t\t\t\tpackageVersion = packageVersionProp.StringValue()\n\t\t\t}\n\n\t\t\tif !opts.KeepResources {\n\t\t\t\tvalue := urn.StringValue()","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/common/resource/plugin/rpc.go#L511-L547","documentation":"In a resource reference, the 'id' field may be a plain string, a computed (unknown) value, or a known output wrapping a string. This error fires in the default branch of the ID switch: the ID was present but its property type is none of those accepted shapes (e.g. a number, bool, object, secret, or unknown output), so the deserializer cannot extract a resource ID string.","triggerScenarios":"obj[\"id\"] is a non-string, non-computed, non-output property (number, bool, object, secret wrapper); a provider serializes an unknown ID as something other than a computed/unknown output.","commonSituations":"Custom providers storing numeric IDs (common in AWS-like providers) without converting to string; hand-edited state; serializers that wrap IDs in secrets; SDK version skew on how unknown IDs are represented.","solutions":["Convert the resource ID to a string before serialization (e.g. strconv.FormatInt for numeric IDs).","If the ID is unknown, serialize it as an unknown/computed value rather than a concrete non-string.","If wrapped as a secret, use a secret-wrapped string so the element remains a string.","Fix or remove the malformed id in exported state, then pulumi stack import."],"exampleFix":"// before (producer)\nm[\"id\"] = resource.NewProperty(int64(12345))\n// after\nm[\"id\"] = resource.NewProperty(\"12345\")","handlingStrategy":"type-guard","validationCode":"func validIDProp(p resource.Property) bool {\n    return p.IsString() || p.IsComputed() ||\n        (p.IsOutput() && (!p.OutputValue().Known || p.OutputValue().Element.IsString()))\n}","typeGuard":"func asResourceID(p resource.Property) (string, bool) {\n    switch {\n    case p.IsString():\n        return p.StringValue(), true\n    case p.IsOutput() && p.OutputValue().Known && p.OutputValue().Element.IsString():\n        return p.OutputValue().Element.StringValue(), true\n    default:\n        return \"\", false\n    }\n}","tryCatchPattern":null,"preventionTips":["Convert numeric IDs to strings before serialization (strconv.FormatInt etc.).","Represent unknown IDs as computed/unknown values, not concrete non-strings.","Wrap secret IDs as secret strings so the underlying element stays a string.","Round-trip test provider serialization with the engine's deserializer in CI."],"tags":["go","serialization","resource-reference","id"],"backgroundTag":"malformed-serialized-property","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}