{"record":{"id":"ee3c4a0ceca7c102","repo":"pulumi/pulumi","slug":"expected-a-s-got-a-resource-of-type-s","errorCode":null,"errorMessage":"expected a %s, got a resource of type %s","messagePattern":"expected a (.+?), got a resource of type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/pulumi/rpc.go","lineNumber":863,"sourceCode":"\t\t}\n\t\treturn true, nil\n\tcase v.IsResourceReference():\n\t\tres, secret, err := unmarshalPropertyValue(ctx, v)\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\t\tresV := reflect.ValueOf(res)\n\t\t// If we unmarshal a pointer and the destination is \"any\", we also want to make sure the result is a\n\t\t// pointer.  We check above whether the destination is a pointer, but that's not true for \"any\", even\n\t\t// though it can hold a pointer.\n\t\tif !allocatedPointer && resV.Kind() == reflect.Pointer && dest.Type().Kind() == reflect.Interface &&\n\t\t\tresV.Elem().Type().AssignableTo(dest.Type()) {\n\t\t\tdest.Set(resV)\n\t\t\treturn secret, nil\n\t\t}\n\n\t\tif !resV.Elem().Type().AssignableTo(dest.Type()) {\n\t\t\treturn false, fmt.Errorf(\"expected a %s, got a resource of type %s\", dest.Type(), resV.Type())\n\t\t}\n\t\tdest.Set(resV.Elem())\n\t\treturn secret, nil\n\tcase v.IsOutput():\n\t\tif _, err := unmarshalOutput(ctx, v.OutputValue().Element, dest); err != nil {\n\t\t\treturn false, err\n\t\t}\n\t\treturn v.OutputValue().Secret, nil\n\t}\n\n\t// Unmarshal based on the desired type.\n\t//nolint:exhaustive // We only need to handle a few types here.\n\tswitch dest.Kind() {\n\tcase reflect.Bool:\n\t\tif !v.IsBool() {\n\t\t\treturn false, fmt.Errorf(\"expected a %v, got a %s\", dest.Type(), v.TypeString())\n\t\t}\n\t\tdest.SetBool(v.BoolValue())","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi/rpc.go#L845-L881","documentation":"Thrown by the Go SDK's property unmarshaling when a deserialized value is a resource reference whose concrete resource type is not assignable to the destination type (sdk/go/pulumi/rpc.go:863). During `unmarshalOutput`, the engine sends back a resource reference (URN + optional ID); the SDK instantiates the typed resource wrapper and checks `resV.Elem().Type().AssignableTo(dest.Type())`. When the provider returns a resource of a different type than the struct field being populated, the assignability check fails and this error is returned.","triggerScenarios":"Calling `resource.Output<T>(...)` / `GetResource` style APIs where the engine returns a resource reference of type A but the destination field is typed as resource B. Also happens when a provider is upgraded/renamed and returns resources with a different URN type token, or when hand-crafted property values passed through custom resource outputs don't match the declared Go type.","commonSituations":"Provider version mismatch: a resource renamed between provider versions returns a URN whose type token no longer matches the Go SDK's generated type. Using the same output struct for resources from different providers. Copy-pasted apply functions casting outputs to the wrong resource type.","solutions":["Check the actual resource type returned by the provider (log the URN) and align the destination struct field type with it.","Ensure the Go SDK version of the provider matches the provider version actually deployed (run `pulumi plugin ls` and `pulumi up` to refresh state).","If the value may genuinely be either resource type, unmarshal into `pulumi.ResourceOutput` or `pulumi.AnyOutput` and assert type in an Apply.","Regenerate the provider SDK so generated resource types match the provider schema."],"exampleFix":"// before\nvar buckets pulumi.StringOutput = bucket.ID()\n// error: expected a pulumi.StringOutput, got a resource of type aws.s3.Bucket\n\n// after\nvar bucket pulumi.AwsS3BucketOutput\nbucket.ApplyT(func(b *awss3.Bucket) (string, error) { return b.ID().ToStringOutput() })","handlingStrategy":"type-guard","validationCode":"if b, ok := someOutput.(pulumi.AwsS3BucketOutput); !ok {\n    return fmt.Errorf(\"output is not an AwsS3Bucket\")\n}","typeGuard":"func isBucket(v interface{}) bool {\n    _, ok := v.(*awss3.Bucket)\n    return ok\n}","tryCatchPattern":"err := ...unmarshal...\nif err != nil && strings.Contains(err.Error(), \"got a resource of type\") {\n    // log URN / resource type and fall back to a generic resource output\n}","preventionTips":["Keep provider plugin versions in lockstep with generated Go SDK versions","Type resource output fields exactly as the generated resource struct","Log resource URNs when debugging type mismatches"],"tags":["go","unmarshaling","resource-reference","type-mismatch"],"backgroundTag":"resource-type-mismatch","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}