Hi, I'm trying to convert an existing Pulumi types...
# package-authoring
s
Hi, I'm trying to convert an existing Pulumi typescript program into a package using the component provider boilerplate from https://github.com/pulumi/pulumi-component-provider-ts-boilerplate I'm getting this error message when I try to use the class like in
examples/simple
. The package is called
platform
and the component class I'm creating is called
Platform
Copy code
Error: unknown resource type platform:index:Platform: Error: unknown resource type platform:index:Platform
        at Provider.<anonymous> (/snapshot/pulumi-resource-platform/bin/provider.js:38:27)
        at Generator.next (<anonymous>)
        at /snapshot/pulumi-resource-platform/bin/provider.js:21:71
        at new Promise (<anonymous>)
        at __awaiter (/snapshot/pulumi-resource-platform/bin/provider.js:17:12)
        at Provider.construct (/snapshot/pulumi-resource-platform/bin/provider.js:33:16)
        at Server.<anonymous> (/snapshot/pulumi-resource-platform/node_modules/@pulumi/pulumi/provider/server.js:316:52)
        at Generator.next (<anonymous>)
        at fulfilled (/snapshot/pulumi-resource-platform/node_modules/@pulumi/pulumi/provider/server.js:18:58)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
I don't know why this default case in the autogenerated code is being run because the
bin/provider.js
file has a switch
case 'platform:index:Platform'
which is the same type indicated in the thrown error.
l
Looks like the autogenerated AI code is wrong. Why would your code care about the type string? The only place you put that is in the call to
super()
. It doesn't go anywhere else in your code.
s
The type string also needs to go in the boilerplate files provider/cmd/pulumi-resource-xyz/provider.ts and schema.json as far as I can tell. Is that not correct?
Also, I didn’t mention that the result of that thrown error from the switch is
failed to register new resource
at Object.registerResource
l
Ah, that's in the provider. Do you need a provider? Would ComponentResources be enough? You don't need that stuff for normal ComponentResources.
s
I need a provider because I’m trying to package an existing ComponentResource. I’ve reduced the problem down as much as I can — I’ve changed it so all I’m doing to the boilerplate is renaming the StaticPage class to Platform and changing the type string in the class, in provider.ts and in the top level schema.json. I still get the same error with the type not being found when registering the resource! I must be missing something…
l
I need a provider because I’m trying to package an existing ComponentResource.
Can you explain this? I have component resource classes in packages that are used in multiple projects. Putting a ComponentResource in a jar or NPM package or pip package or whatever doesn't require a provider. A provider is required when you need to make non-Pulumi SDK calls to manage your resources. This should not apply to ComponentResources: if you need to do this, you need a CustomResource, not a ComponentResource.
I don't know what would happen if you tried to create a ComponentResource in a dynamic provider. Probably, exactly what you're seeing. It shouldn't work.
s
I’m following the component instructions here: https://www.pulumi.com/docs/using-pulumi/pulumi-packages/how-to-author/#select-a-template My understanding of the component provider boilerplate is that it compiles a binary from your componentresource and generates SDKs for other languages. That’s my goal — I wrote a componentresource in Typescript and want to use it in Go and Python too. The boilerplate does this with a StaticPage componentresource which just contains an s3 bucket. It works as expected out of the box, but I can’t even rename the class as I described above without it breaking.
l
I've not seen this construct before. You'll have to ignore all my previous points, as I had no idea that component resources could be generated in multi-language packages; in older versions of Pulumi, that's what component resources were not for, and you'd have to use custom resources for that. After you renamed the class in the schema and wherever else the tool uses to generate the code for all the SDKs, did you regenerate the code? I'm guessing you don't want to edit the generated code, it'd be too easy to miss something and end up with a mismatch of some sort.
s
No problem 🙂 Yes, I’ve tried it multiple times and reran all the steps in the README, including a manual plugin installation step with
pulumi plugin install resource xyz v0.0.1 -f bin/pulumi-resource-xyz