The upstream Grafana TF provider has versioned res...
# package-authoring
l
The upstream Grafana TF provider has versioned resources like: https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/apps_dashboard_dashboard_v2beta1 I want to generate versioned resources like it is done in the Kubernetes provider. Converting the resource above, I am able to set the Pulumi type identifier to
grafana:apps/v2beta1:Dashboard
Via
resources.go
, I configure the language sections with module mappings. For instance, my
schema.json
contains the following for `nodejs`:
Copy code
"nodejs": {
            ...
            "moduleToPackage": {
                "apps/v2beta1": "apps/v2beta1"
            },
            ...
        },
The generated NodeJS SDK however has file
sdk/nodejs/apps/dashboard.ts
, while I expected
sdk/nodejs/apps/v2beta1/dashboard.ts
. What am I missing?
e
So I don't think a module name mapping of X => X does anything. per-chance does your schema set a moduleFormat regex?
apps
is not mapped in
tks.MappedModules
at the end of
resources.go
e
hmm I think this might be a bridge thing, gimme a min
l
So I don't think a module name mapping of X => X does anything.
Why not? The codegen behaves differently for
grafana:apps/dashboard:Dashboard
and
grafana:apps/v2beta1:Dashboard
. Without mappings, both generate to
grafana.apps.Dashboard
(NodeJS), while I want the latter to be remapped properly. By accident, the Pulumi module name and the language package name are the same. My expectation is that it would still do its magic.
e
So looking at the code whenever we take values from the modulesToPackages mapping it's just to replace the module name that was mapped. So if we have X and we look up X in the map and get back X nothing has. changed. I think what's happening with tfbridge though is it defaults the module format regex to
(.*)(?:/[^/]*)
so it's pulling off that /dasboard or /v2beta1 before doing any further module naming
try calling into grafanaResource from grafanaVersionedResource so you end up with
grafana:apps/v2beta1/dashboard:Dashboard
l
Isn't SDK generation invoking
pulumi package gen-sdk
feeding it
schema.json
? Asking because my
schema.json
contain the correct Pulumi resource types and mappings sections in the language configuration sections.
e
what's the schema.json say?
l
https://raw.githubusercontent.com/pulumiverse/pulumi-grafana/babf79108e698f5e1553cbd50783[…]24351b2/provider/cmd/pulumi-resource-grafana/schema.json The mappings are in the language section at the top. Search for
grafana:apps/v2beta1:Dashboard
as the resource type.
e
Yeh so I think "grafanaapps/v1beta1Dashboard" should be "grafanaapps/v1beta1/dashboardDashboard" to be in alignment with other resources like "grafanaalerting/recordingRuleV0Alpha1RecordingRuleV0Alpha1" note how the resource name is duplicated into the module name but then ignored by the rest of codegen
l
Leaving the mixed naming setup in this grafana provider aside for a minute, why is the versioned naming working for the Kubernetes provider, even with X=>X mappings like
"policy/v1": "policy/v1",
? https://raw.githubusercontent.com/pulumi/pulumi-kubernetes/refs/heads/master/provider/cmd/pulumi-resource-kubernetes/schema.json My understanding of SDK generation has been so far that one needs to get the proper information into
schema.json
, usually done by the
gen
specific command (
pulumi-gen-kubernetes
,
pulumi-tfgen-grafana
). Once at that point, actual SDK generation is triggered via
pulumi package gen-sdk
. Is there still something specific to SDK generation which is different in these
gen
commands?
e
because k8s has a different module format set in its schema
l
Are you referring now to some config option? I tried dotted notation too in the Grafana provider, e.g
grafana:<http://apps.grafana.com/v2beta1:Dashboard|apps.grafana.com/v2beta1:Dashboard>
and matching mappings, but the generated type ended up being
grafana.apps.grafana.com.Dashboard
e
In the schema meta options there's a "moduleFormat" setting
Again I think what you want is to try calling into grafanaResource from grafanaVersionedResource so you end up with
grafana:apps/v2beta1/dashboard:Dashboard
l
🤔 I can't find
moduleFormat
in the Kubernetes
schema.json
. I'll try your suggestion, but I had hoped to understand how Pulumi resource type to SDK type generation works. Understanding why it works for the Kubernetes provider would have brought me a step further in understanding.
e
Ah k8s probably uses the default which is '(.*)'
l
Ah, so K8s using the default
moduleFormat
, while my bridge provider has
"moduleFormat": "(.*)(?:/[^/]*)"
💡
👍 1
Even after all those years, TIL:
moduleFormat
is a thing. Mainly because it is hardcoded for TF-bridged providers: https://github.com/pulumi/pulumi-terraform-bridge/blob/736bb6d87fca760e830c4cf62c46b79d3c5f7608/pkg/tfgen/generate_schema.go#L287
e
It's pretty much just a back compat thing for tfbridge, we wouldn't recommend using it for anything now