What's a reliable way to build a Pulumi Terraform ...
# package-authoring
s
What's a reliable way to build a Pulumi Terraform "Plugin Framework" bridge provider? Toying with https://github.com/joneshf/terraform-provider-openwrt/tree/main/openwrt I tried manually, but the tf-bridge development seems in flux, and got lost. Got further along with the cookiecutter project, but now I'm running into this error - which makes no sense since I didn't publish anything yet. Why would it try to download it for the ts example project? I'm still very much "in dev mode", trying to sort things out.
Copy code
pulumi-openwrt/examples/openwrt-system/ts  255  pulumi up
Previewing update (dev)

View in Browser (Ctrl+O): <https://app.pulumi.com/pcuci/ts/dev/previews/d4770506-61cd-4002-b5f4-2ae37c244f8f>

     Type                         Name             Plan       Info
 +   pulumi:pulumi:Stack          ts-dev           create
     └─ pulumi:providers:openwrt  openwrtProvider             1 error


Diagnostics:
  pulumi:providers:openwrt (openwrtProvider):
    error: Could not automatically download and install resource plugin 'pulumi-resource-openwrt' at version v0.0.1-alpha.1695222502+35e1f4e7.dirty, install the plugin using `pulumi plugin install resource openwrt v0.0.1-alpha.1695222502+35e1f4e7.dirty --server <github://api.github.com/deposition-cloud/pulumi-openwrt>`: error downloading provider openwrt to file: failed to download plugin: openwrt-0.0.1-alpha.1695222502+35e1f4e7.dirty: 404 HTTP error fetching plugin from <https://api.github.com/repos/deposition-cloud/pulumi-openwrt/releases/tags/v0.0.1-alpha.1695222502+35e1f4e7.dirty>. If this is a private GitHub repository, try providing a token via the GITHUB_TOKEN environment variable. See: <https://github.com/settings/tokens>
Code here: https://github.com/deposition-cloud/pulumi-openwrt - in case anyone familiar with the bridging workflow wants to have a look; what am I missing? ...after the second run of
make tfgen
I noticed the
.dirty
suffix—what exactly is happening here?
e
Have you run
make provider
to build the provider binary so it's on $PATH?
s
Not sure I follow, the Makefile does:
Copy code
provider:: tfgen install_plugins # build the provider binary
	(cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER})
Had to inquire ChatGPT: The command performs the following actions: 1. Change Directory: It changes the current directory to
provider
using
cd provider
.
2. _Go Build: It then runs
go build
to compile the Go code located in
${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER}
._ 3. _Output: The compiled binary is saved to
$(WORKING_DIR)/bin/${PROVIDER}
._ 4. Linker Flags: It sets some linker flags to embed the version information into the binary. This make task doesn't seem to add anything to the PATH, so I symlinked
./bin/pulumi-resource-openwrt
to
~/go/bin/pulumi-resource-openwrt
and it was picked up . Next error 🙂
Copy code
 pulumi up
Previewing update (dev)

View in Browser (Ctrl+O): <https://app.pulumi.com/pcuci/ts/dev/previews/9498ada9-bbe5-4071-af4d-ee57be9ad417>

     Type                         Name             Plan       Info
 +   pulumi:pulumi:Stack          ts-dev           create     2 warnings
     └─ pulumi:providers:openwrt  openwrtProvider             1 error


Diagnostics:
  pulumi:providers:openwrt (openwrtProvider):
    error: pulumi:providers:openwrt resource 'openwrtProvider' has a problem: could not validate provider configuration: Invalid or unknown key. Examine values at 'openwrtProvider.pluginDownloadURL'.

  pulumi:pulumi:Stack (ts-dev):
    warning: using pulumi-resource-openwrt from $PATH at /home/paul/go/bin/pulumi-resource-openwrt
    warning: using pulumi-resource-openwrt from $PATH at /home/paul/go/bin/pulumi-resource-openwrt
I can only guess it's complaining about this line: https://github.com/deposition-cloud/pulumi-openwrt/blob/109b949f89b1cb83cbdc3be8244cdd3eb5d97900/provider/resources.go#L83 (?) Am I returning the right thing here: https://github.com/deposition-cloud/pulumi-openwrt/blob/109b949f89b1cb83cbdc3be8244cdd3eb5d97900/provider/resources.go#L187
Copy code
return pf.ProviderInfo{
		ProviderInfo: prov,
		NewProvider: func() pfprovider.Provider {
			return openwrt.New(version.Version, os.LookupEnv)
		},
	}
e
This make task doesn't seem to add anything to the PATH
Ah right some of our provider makefiles build directly to /go/bin, assumed this one was the same. Just symlinking works.
I can only guess it's complaining about this line
That pluginUrl looks fine. It might be you just need to update the deps in go.mod to the lastest version of github.com/pulumi/pulumi-terraform-bridge/v3 and github.com/pulumi/pulumi-terraform-bridge/pf
b
Only as a small sidenote. I always perform intial tests for a new Pulumi provider, e.g. which has been wrapped by using the TF bridge, with a YAML program. The advantage of Pulumi YAML is that the provider executable only needs to be present in the path. The complete (correct) setup, e.g. for Node via yarn link, can then be omitted for the time being.
s
@echoing-dinner-19531 hm, upgrading seems to break the contract https://github.com/pulumi/pulumi-terraform-bridge/blob/master/pf/tfbridge/main.go doesn't export a
ProviderInfo
struct anymore, so the code I shared above breaks @big-architect-71258 - any plans to upgrade your cookiecutter?
b
@straight-cartoon-24485 Mind opening an issue in my repo? And I think the issue might stem from a breaking change in TF PF mentioned by @orange-policeman-59119 a couple of weeks ago. But I didn't have any time to look at it or even incorporate the required changes into the template yet.
@straight-cartoon-24485 I just published v0.0.12 of the Cookiecutter Template with fixes to the breaking change mentioned in the issue you opened. @billowy-army-68599