Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs on how to shim a provider hidden by /internal/ #111

Open
TieyanFu opened this issue Mar 20, 2024 · 2 comments
Open

Improve docs on how to shim a provider hidden by /internal/ #111

TieyanFu opened this issue Mar 20, 2024 · 2 comments
Labels
area/docs Improvements or additions to documentation kind/bug Some behavior is incorrect or out of spec

Comments

@TieyanFu
Copy link

TieyanFu commented Mar 20, 2024

What happened?

Trying to create a bridged terraform provider for the BTP terraform provider

https://github.com/SAP/terraform-provider-btp/

I pushed my latest changes here

https://github.com/TieyanFu/pulumi-btp/tree/issue_111

In step make tfgen, I got following error:

pulumi plugin install resource random 4.3.1
(cd provider && go build -o /Users/d049740/Work/k8s/workspace/TerraformProvider/pulumi-btp/bin/pulumi-tfgen-btp -ldflags "-X github.com/tieyanfu/pulumi-btp/provider/pkg/version.Version=0.0.1-alpha.1710887702+9ff41a2f.dirty" github.com/tieyanfu/pulumi-btp/provider/cmd/pulumi-tfgen-btp)
package github.com/tieyanfu/pulumi-btp/provider/cmd/pulumi-tfgen-btp
	imports github.com/tieyanfu/pulumi-btp/provider
	resources.go:31:2: use of internal package github.com/SAP/terraform-provider-btp/internal/provider not allowed
make: *** [tfgen] Error 1

The error is understandably correct, since the BTP terraform plugin provider is inside folder internal. However, the folder structure is following the latest terraform provider scaffolding framework template where provider is also inside internal folder.

I had look into a few bridged provider examples:

	"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
	"github.com/hashicorp/terraform-provider-azurerm/shim"
  • pulumi-splunk, its "provider" pacakge is named splunk which is also not under internal folder

A quick note: in provider/resources.go it seems the pulumi is trying to reference datasource definition, not necessarily provider itself, not sure if I understand it correctly.

So the questions are:

  • What are the recommended project structure for terraform-plugin in order to use pulumi bridge tf provider?
  • If the provider package in the terraform-plugin is already inside internal folder, how should it be configured in resources.go as described in below step?
image

Example

see above

Output of pulumi about

CLI
Version 3.111.1
Go Version go1.22.1
Go Compiler gc

Host
OS darwin
Version 14.4
Arch x86_64

Backend
Name pulumi.com
URL https://app.pulumi.com
User Unknown
Organizations
Token type personal

Pulumi locates its logs in /var/folders/xp/w_dp2zwj1v31p7rsl_qr0zbr0000gn/T/ by default
warning: Failed to read project: no Pulumi.yaml project file found (searching upwards from /Users/dxxxxx/Work/k8s/workspace/TerraformProvider/pulumi-btp). If you have not created a project yet, use pulumi new to do so: no project file found
warning: Failed to get information about the current stack: no Pulumi.yaml project file found (searching upwards from /Users/xxxxx/Work/k8s/workspace/TerraformProvider/pulumi-btp). If you have not created a project yet, use pulumi new to do so: no project file found

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@TieyanFu TieyanFu added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Mar 20, 2024
@TieyanFu
Copy link
Author

TieyanFu commented Mar 20, 2024

Just found out that there is a section discuss the shim pattern. However, there are still some hoops to jump through. https://github.com/pulumi/pulumi-random/blob/master/provider/go.mod provides a good example.

@iwahbe iwahbe removed the needs-triage Needs attention from the triage team label Mar 26, 2024
@iwahbe
Copy link
Member

iwahbe commented Mar 26, 2024

Hey @TieyanFu. Thanks for raising this. There are definitely hoops to jump through. It sounds like you were able to get unblocked. I'm going to leave this issue as a reminder that we need to improve our documentation here.

It might be worth checking out https://github.com/tmeckel/pulumi-tf-provider-cookiecutter here. It's not officially supported, but it will handle this type of setup for you. It's much closer to "it just works" then the boilerplate is right now.

@iwahbe iwahbe changed the title make tfgen failing to build provider (provider in internal folder) Improve docs on how to shim a provider hidden by /internal/ Mar 26, 2024
@iwahbe iwahbe added the area/docs Improvements or additions to documentation label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs Improvements or additions to documentation kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants