Hi :wave: We are currently evaluating Pulumi and ...
# contribute
a
Hi 👋 We are currently evaluating Pulumi and Terraform for use within our organization. I prefer Pulumi. But I need a 'proof of concept' we can bridge certain Terraform providers that are not yet available as standard in Pulumi. To gain some experience with tf-bridge I watched an (outdated) video on YouTube (Building a Pulumi Terraform Bridge Provider | Pulumi ContribEx) and followed the excellent blog at https://thulasirajkomminar.com/how -to-bridge-a-terraform-provider-to-pulumi-623db829f52f. I also used the cookiecutter (https://github.com/tmeckel/pulumi-tf-provider-cookiecutter) Bridging influxdb according the blog worked without any problems. But here's the thing: Our organization uses Netapp for storage. Now I'm trying to bridge the netap-ontap terraform provider (https://github.com/NetApp/terraform-provider-netapp-ontap) in the same way. Unfortunately that doesn't work and I get stuck. I suspect this is due to case sensitivity and the use of a hyphen character in the name of the terraform provider. I currently have little experience with Pulumi and Go. Can anyone help me to successfully bridge this provider? Below are the steps I did: The cookiecutter input values (non-defaults only):
Copy code
[1/26] terraform_provider_name (terraform-provider-name): netappontap
  [2/26] terraform_provider_org (terraform-providers): netapp
  [3/26] terraform_provider_source (<http://github.com/netapp/terraform-provider-netappontap|github.com/netapp/terraform-provider-netappontap>): <http://github.com/netapp/terraform-provider-netapp-ontap|github.com/netapp/terraform-provider-netapp-ontap>
  [4/26] terraform_provider_version_or_commit (0.0.0): 1.1.2
  [5/26] terraform_provider_module (<http://github.com/netapp/terraform-provider-netappontap|github.com/netapp/terraform-provider-netappontap>): <http://github.com/netapp/terraform-provider-netapp-ontap|github.com/netapp/terraform-provider-netapp-ontap>
  [6/26] terraform_provider_package_name (netappontap): internal/provider
  [7/26] Select terraform_sdk_version
    1 - 1
    2 - 2
    3 - plugin-framework
    Choose from [1/2/3] (1): 3
  ...
  [23/26] go_version (1.22.5):
  ...
According to the blog I also changed the ~/pulumi-netappontap/provider/shim/shim.go to:
Copy code
package shim

import (
        "<http://github.com/netapp/terraform-provider-netapp-ontap/internal/provider|github.com/netapp/terraform-provider-netapp-ontap/internal/provider>"
        tfpf "<http://github.com/hashicorp/terraform-plugin-framework/provider|github.com/hashicorp/terraform-plugin-framework/provider>"
)

func NewProvider() tfpf.Provider {
        return provider.New("dev")()
   }
In step 1/26 I initially had for terraform-provider-name "netapp-ontap" cookiecutter then fails on an assertion:
Copy code
ERROR: netapp-ontap IS NOT a valid terraform provider name!
ERROR: Stopping generation because pre_gen_project hook script didn't exit successfully
But with the custom terraform-provider-name "netappontap", the process fails at make tfgen:
Copy code
1-alpha.1723480192+a6d32fc5" <http://github.com/pulumiverse/pulumi-netappontap/provider/cmd/pulumi-tfgen-netappontap)|github.com/pulumiverse/pulumi-netappontap/provider/cmd/pulumi-tfgen-netappontap)>
$/dev-projects/pulumi-netappontap/bin/pulumi-tfgen-netappontap schema --out provider/cmd/pulumi-resource-netappontap
panic: fatal: An assertion has failed: Invalid snake case name netapp-ontap_cluster_licensing_license_resource. Does not start with netappontap
I did a 'hack' with a custom regexp in the pre_gen_project hook script. But I think that's a bad idea: In ~/.cookiecutters/pulumi-tf-provider-cookiecutter/hooks/pre_gen_project.py:
Copy code
PROVIDER_NAME_REGEX = r"^[-a-zA-Z0-9]+$"
I get further, but with a different error message:
Copy code
(vcoockiecutter) :~/dev-projects/pulumi-netapp-ontap$ make tfgen
[ -x $/.pulumi/bin/pulumi ] || curl -fsSL <https://get.pulumi.com> | sh
pulumi plugin install resource random 4.3.1
(cd provider && go build -o $/dev-projects/pulumi-netapp-ontap/bin/pulumi-tfgen-netapp-ontap -ldflags "-X <http://github.com/pulumiverse/pulumi-netapp-ontap/provider/pkg/version.Version=0.0.1-alpha.1723229264+1efcb411|github.com/pulumiverse/pulumi-netapp-ontap/provider/pkg/version.Version=0.0.1-alpha.1723229264+1efcb411>" <http://github.com/pulumiverse/pulumi-netapp-ontap/provider/cmd/pulumi-tfgen-netapp-ontap)|github.com/pulumiverse/pulumi-netapp-ontap/provider/cmd/pulumi-tfgen-netapp-ontap)>
cmd/pulumi-tfgen-netapp-ontap/main.go:18:8: missing import path
make: *** [Makefile:49: tfgen] Error 1
To 'fix' that, I changed the import path in the two main.go files: from: netapp-ontap to: netappontap tfgen gets through, but with 109 errors afterwards in the mod.go file. But in the end, things still go wrong with the created Python SDK. Import the python package:
Copy code
>>> imnport pulumiverse_netapp-ontap
  File "<stdin>", line 1
    imnport pulumiverse_netapp-ontap
            ^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax
And
Copy code
>>> pulumiverse_netapp = __import__('pulumiverse_netapp-ontap')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "$/dev-projects/pulumi-netapp-ontap/sdk/python/pulumiverse_netapp-ontap/__init__.py", line 15
    import pulumiverse_netapp-ontap.cluster as __cluster
                             ^
SyntaxError: invalid syntax
My conclusion so far is that bridging this provider is not possible because a hypen character is used in the terraform provider name. Btw. To gain some more TF-bridge experience, I also tried to bridge configcat (https://github.com/configcat/terraform-provider-configcat). Unfortunately that didn't work either. Anyone already encountered the error below? Steps to reproduce:
Copy code
[1/26] terraform_provider_name (terraform-provider-name): configcat
  [2/26] terraform_provider_org (terraform-providers): configcat
  [3/26] terraform_provider_source (<http://github.com/configcat/terraform-provider-configcat|github.com/configcat/terraform-provider-configcat>):
  [4/26] terraform_provider_version_or_commit (0.0.0): 5.4.0
  [5/26] terraform_provider_module (<http://github.com/configcat/terraform-provider-configcat/v5|github.com/configcat/terraform-provider-configcat/v5>): <http://github.com/configcat/terraform-provider-configcat|github.com/configcat/terraform-provider-configcat>
  [6/26] terraform_provider_package_name (configcat): internal/configcat
  [7/26] Select terraform_sdk_version
    1 - 1
    2 - 2
    3 - plugin-framework
    Choose from [1/2/3] (1): 3
  ....
modified shim.go
Copy code
package shim

import (
	"<http://github.com/configcat/terraform-provider-configcat/internal/configcat|github.com/configcat/terraform-provider-configcat/internal/configcat>"
	tfpf "<http://github.com/hashicorp/terraform-plugin-framework/provider|github.com/hashicorp/terraform-plugin-framework/provider>"
)

func NewProvider() tfpf.Provider {
	return configcat.New("dev")()
   }
Gives an error:
Copy code
error: Resource configcat_webhook has a problem: "id" attribute is of type "Int", expected type "string". To map this resource consider overriding the SchemaInfo.Type field or specifying ResourceInfo.ComputeID

Additional example conversion stats are available by setting COVERAGE_OUTPUT_DIR.

Provider:     configcat
Success rate: NaN% (0/0)


General metrics:
        0 total resources containing 0 total inputs.
        0 total functions.
But I don't know how to override SchemaInfo.Type or specify ResourceInfo.ComputeID All help is welcome 🙂 Regards, David
m
Hi David! Looks like you've made some good progress on bridging netapp-ontap. The package name is configurable for each language and we often do this for python for exactly this reason. Here's an example from a provider I recently bridged: pulumi-junipermist/provider/resources.go
The error you're seeing with configcat is another common one that you sometimes need to configure around. The
id
parameter is treated specially by pulumi and must be a string (Resource Provider Implementer’s Guide — Pulumi documentation), you have two options: 1) Just make it a string in the pulumi schema (eg: [Breaking] Set workspace_id to a string instead of int for Pulumi · pulumi-databricks/435) and let the bridge convert it to an Int for the underlying terraform provider code. 2) Rename that field to something else and tell the bridge to use some other string as the ID (by setting
ComputeID
on the resource)
l
@ambitious-crayon-4360 I should bring a bit more attention to this configcat provider. Will try to do that ASAP. https://github.com/pulumiverse/pulumi-configcat/
a
Hi Matt, RIngo, thanks for your responses and tips. The pulumi_netapp_ontap Python package is now valid. But I doubt that everything has worked out well now. For example, I miss the IntelliSense (parameter info, quick info etc.) in vscode for the python SDK. While this does work with the previously built influx bridge. I'm trying to figure it out myself before I start asking questions again.
Just discovered the new Any Terraform Provider and immediately tried it for the netapp_ontap provider. Works without any problems. Really great and a game changer for us! 👍🎉 Only a small error in the generated comment regarding the hyphen char:
You can then import the SDK in your Python code with:
import pulumi_netapp-ontap as netapp-ontap
So that must be:
import pulumi_netapp_ontap as netapp_ontap
Regards, David
🎉 1