https://pulumi.com logo
#general
Title
# general
g

gorgeous-microphone-34056

08/09/2023, 3:42 PM
is there a easy way to convert swagger / open api spec into pulumi provider?
b

billowy-army-68599

08/09/2023, 4:03 PM
g

gorgeous-microphone-34056

08/09/2023, 4:16 PM
@billowy-army-68599 i had a quick look, do you have a readme on how to use that project? README is not clear on how to use it
b

billowy-army-68599

08/09/2023, 4:17 PM
i don’t i’m afraid, @clever-sunset-76585 wrote it, maybe he can help
c

clever-sunset-76585

08/09/2023, 4:20 PM
@gorgeous-microphone-34056 there are three providers that I have generated so far with that. Tailscale is the latest one: https://github.com/cloudy-sky-software/pulumi-tailscale-native/blob/main/provider/pkg/gen/schema.go#L144-L155
g

gorgeous-microphone-34056

08/09/2023, 4:21 PM
im trying to see steps required for converting a swagger spec into provider
like a usage guide tbh
c

clever-sunset-76585

08/09/2023, 4:24 PM
like a usage guide tbh
The lines I linked above is literally how you would use the library. That's the best I've got so far. Other than that, the instructions in the README for
pulschema
tell you how to prepare the OpenAPI spec for a successful conversion. You can also look at the tests in the providers I've generated thus far: https://github.com/search?q=topic%3Apulumi-provider+org%3Acloudy-sky-software+fork%3Atrue&type=repositories
g

gorgeous-microphone-34056

08/09/2023, 4:29 PM
not a golang developer 🙂 so trying to wrap my head around this. i will take a look
c

clever-sunset-76585

08/09/2023, 4:32 PM
Ah gotcha. Some familiarity around how Pulumi providers are generated is also necessary to be honest and the best place to start for that is Pulumi's own https://github.com/pulumi/pulumi-provider-boilerplate which teaches you how to structure a provider. Note that converting the API spec to a Pulumi schema spec is only half the work. The other half is to model the HTTP requests necessary to make it work. As you'll notice in the providers that I generated, I use my own private library (
pulumi-provider-framework
) that does the HTTP offloading. When it comes to that you'll be on your own but since it's just HTTP requests you can use whatever strategy you'd like and shouldn't be blocked by not having access to that private lib.
I do have my own private GitHub repo template that uses
pulschema
and my private
pulumi-provider-framework
repo, which I am happy to share a ZIP file with you but it'll be useless to anyone without
pulumi-provider-framework
, which is why I've kept my template also private.
g

gorgeous-microphone-34056

08/09/2023, 4:35 PM
i will try to get familar with these repos
my goal -> i have an open api spec (v3) -> need to create a pulumi provider for this
c

clever-sunset-76585

08/09/2023, 4:36 PM
Yeah honestly starting to understand how a Pulumi provider is built is the first thing I would recommend (the Pulumi boilerplate repo) before even attempting to convert anything because that'll teach you the problem
pulschema
is trying to solve.
g

gorgeous-microphone-34056

08/09/2023, 4:36 PM
gotcha that make sense
im assuming pulschema generates
provider/cmd
code at high level
c

clever-sunset-76585

08/09/2023, 4:40 PM
pulschema
generates the
schema.json
file that you'll see referenced in the Pulumi provider boilerplate repo. If
pulschema
didn't exist, you'd have to manually author that JSON file which is what Pulumi uses to generate the language SDKs and docs.
g

gorgeous-microphone-34056

08/09/2023, 4:55 PM
make generate_schema
seems to be generating schema.json file which step are we using
pulschema
c

clever-sunset-76585

08/09/2023, 4:57 PM
If you follow that codepath you'll end up in the lines of code I linked in my first message in this thread.
Also note that in the case of Tailscale, they don't have an OpenAPI spec file, so I needed to start with first generating an API spec file before I could even generate a Pulumi schema using
pulschema
. The API spec itself is generated using TypeSpec code in the
api
folder (not TypeScript). This is not something you'll have to worry about since you already have an OpenAPI spec. For a 1:1 comparison, perhaps the Render or the Scaleway Instances provider would be a closer match to what you might be dealing with.
g

gorgeous-microphone-34056

08/09/2023, 5:03 PM
got it, thank you
if its not too much to ask, can you confirm if this is the right approach 1. clone https://github.com/cloudy-sky-software/pulumi-render 2. install pulumictl 3. make updates to metadata like provider name etc 4. put custom.v1.Api.yml in root folder 5. run
make gen nodejs_sdk
c

clever-sunset-76585

08/09/2023, 5:11 PM
Sure, you can try that. That should work since you'd only be generating the SDKs. But like I said before,
pulumi-provider-framework
is private, so you'll encounter issues if you try to build the provider binary since it'll look for that repo.
g

gorgeous-microphone-34056

08/09/2023, 5:13 PM
gotcha, can you share that as zip / binary as you mentioned before?
c

clever-sunset-76585

08/09/2023, 5:14 PM
gotcha, can you share that as zip / binary as you mentioned before?
Oh I said I would give a ZIP of the private template, not the
pulumi-provider-framework
🙂 sorry for not being clear. I'd be happy to DM the template to you.
g

gorgeous-microphone-34056

08/09/2023, 5:14 PM
gotcha
DM works
c

clever-sunset-76585

08/09/2023, 6:13 PM
Posting here from our private conversation for posterity: I suggest starting with the Pulumi boilerplate repo and understand that first before tackling
pulschema
. It's easier to bring
pulschema
into their template due to the private module
pulumi-provider-framework
dependency that I have with my template.
pulumi-provider-framework
is an HTTP client. As long as you have a Pulumi
schema.json
generating successfully, you can build your own HTTP client library that interacts with the REST API as shown in Pulumi's own examples. At some point in the future, I might decide to make
pulumi-provider-framework
public but I haven't had the time to think about it and not certain about it just yet.
62 Views