https://pulumi.com logo
#package-authoring
Title
# package-authoring
b

better-scooter-29497

08/22/2023, 3:12 PM
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

big-architect-71258

08/22/2023, 3:14 PM
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

better-scooter-29497

08/22/2023, 3:16 PM
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

big-architect-71258

08/22/2023, 3:18 PM
@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

better-scooter-29497

08/22/2023, 3:19 PM
Yeah, that’s exactly what I’m running into, cheers!
So, the right step would be to use the hash, got it 👍
b

big-architect-71258

08/22/2023, 3:20 PM
This always creates major headache 😎 The cookiecutter template is able to handle this.
b

better-scooter-29497

08/22/2023, 3:20 PM
Grand; I might also submit a PR, I suspect that go.mod string comes from some legacy terraform registry requirement…
b

big-architect-71258

08/22/2023, 3:22 PM
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

better-scooter-29497

08/22/2023, 3:22 PM
Now I’ve spotted it, it does bother me 😅
b

big-architect-71258

08/22/2023, 3:23 PM
I can feel you 😉
If you wanna publish the provider, Pulumiverse is a great way to go.
b

better-scooter-29497

08/22/2023, 3:25 PM
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

big-architect-71258

08/22/2023, 3:29 PM
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

better-scooter-29497

08/22/2023, 3:57 PM
Right, next thing to figure out is the errors from
make tfgen
🤔
b

big-architect-71258

08/22/2023, 3:57 PM
Oh, so your're able to build
tfgen
. Congrats 🎉
What errors exactly?
b

better-scooter-29497

08/22/2023, 3:58 PM
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

big-architect-71258

08/22/2023, 4:01 PM
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

better-scooter-29497

08/22/2023, 4:28 PM
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

big-architect-71258

08/22/2023, 4:33 PM
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.