Hello all, I’ve been looking at bridging a terrafo...
# package-authoring
b
Hello all, I’ve been looking at bridging a terraform provider into Pulumi, but I’m running into some go.mod weirdness and as I’m not a go dev I’d appreciate some help. In particular, my problem comes when trying to specify the provider as a dependency in `providers/go.mod`; the latest tag is v2.35.0, but go.mod won’t accept that without a
v2
in the module spec. However, the go.mod file of the provider defines the path as `github.com/terraform-providers/terraform-provider-bitbucket`; with no v2, and with a different username than where it’s actually hosted (which is https://github.com/DrFaust92/terraform-provider-bitbucket). How can I solve this?
(To be 100% clear; I have contributed to, but don’t own, the provider repo)
b
If you're not a "go dev" this could be really steep learning curve to get the module references right. Perhaps you wanna try my Cookiecutter template: https://github.com/tmeckel/pulumi-tf-provider-cookiecutter#readme Most of the time it's able to figure out the correct settings to wrap an upstream Tf provider.
b
Oh, I’ll happily give it a go; I’ve touched go before, but I can’t say I’m comfortable with the ecosystem.
b
@better-scooter-29497 have a close look on the parameter descriptions here https://github.com/tmeckel/pulumi-tf-provider-cookiecutter#parameter-details Because I saw that the upstream provider has an incorrect module name in the top-level
go.mod
file.
b
Yeah, that’s exactly what I’m running into, cheers!
So, the right step would be to use the hash, got it 👍
b
This always creates major headache 😎 The cookiecutter template is able to handle this.
b
Grand; I might also submit a PR, I suspect that go.mod string comes from some legacy terraform registry requirement…
b
You can do this if it bothers you , but it's not required if you only wanna wrap the TF provider with Pulumi TF bridge.
b
Now I’ve spotted it, it does bother me 😅
b
I can feel you 😉
If you wanna publish the provider, Pulumiverse is a great way to go.
b
I will happily; I’m sure I’m not the only one out there stuck on bitbucket cloud
(We’re planning a move soon, actually, but I want to play with this now)
b
When you're ready, add a PR like the following to get a repo for the provider: https://github.com/pulumiverse/infra/pull/65/files
b
Right, next thing to figure out is the errors from
make tfgen
🤔
b
Oh, so your're able to build
tfgen
. Congrats 🎉
What errors exactly?
b
e.g. `* TF resource "bitbucket_repository" not mapped to the Pulumi provider`; I note it’s a different message to the warnings coming from the template
b
Oh, that's expected because you (now) must add the resources and data sources one by one to the `resources.go`file to the
Resources
and
DataSources
properties of the
prov := tfbridge.ProviderInfo{
. Perhaps you wanna have a look at my `mssql`provider in Pulumiverse how to do this. https://github.com/pulumiverse/pulumi-mssql/blob/91839e66d4f572195b24e350fb1a8546977dd1db/provider/resources.go#L150
If you are comfortable with
awk
you can convert the error messages of
tfgen
into the required go declarations like so
Copy code
##
# make tfgen 2>&1 | grep -E 'TF resource \"[^"]+" not mapped' | awk -f ~/code/tf-resources.awk > resources.txt
#

function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }

BEGIN { RS = "\n" ; FS = "\"" }

{
      print "\"" trim($2) "\": {"
      print "\tTok: makeResource(mainMod, \"" trim($2) "\"),"
      print "},"
}
b
Right, we’re going; just need to figure out the Markdown mapping for the docs now and we’re all good
(I’m right in assuming the Markdown property is a path to a file in original provider package? Or do I need to copy those files across to the pulumi repo?)
b
If
tfgen
isn't able to figure out the correct docs location it might be required to set the
PULUMI_REPO_PATHS
environment variable and have the source code of the upstream provider located somewhere on the local disk. https://github.com/pulumi/pulumi-terraform-bridge#tfgen-options
You can have a look in the
Makefile
my version of the
pulumi-fortios
provider. https://github.com/tmeckel/pulumi-fortios/blob/7bdf50b18a4f7d45be0af39abf008b0383b3ee3a/Makefile#L8C1-L8C18
Oh and ensure that all required Pulumi providers are installed that match the referenced TF providers in the docs of the upstream provider. This is handled in the
install_plugins
Makefile target.
Typically issues around the docs generation will be fixed by having the correct Pulumi providers installed locally.
PULUMI_REPO_PATHS
is the last resort.