I am trying to create a tf-bridge for harvester: <...
# package-authoring
h
I am trying to create a tf-bridge for harvester: https://github.com/harvester/terraform-provider-harvester Following the instructions in the readme of tf-provider-boilerplate But I am stuck at schema generation, could use some pointers:
Copy code
$make tfgen
[ -x /opt/homebrew/bin/pulumi ] || curl -fsSL <https://get.pulumi.com> | sh
pulumi plugin install resource random 4.3.1
(cd provider && go build -o /Users/gsuess/SemDatex/pulumi/harvester/bin/pulumi-tfgen-harvester -ldflags "-X <http://github.com/semdatex/pulumi-harvester/provider/pkg/version.Version=0.0.1-alpha.1688662856+041f43bc.dirty|github.com/semdatex/pulumi-harvester/provider/pkg/version.Version=0.0.1-alpha.1688662856+041f43bc.dirty>" <http://github.com/semdatex/pulumi-harvester/provider/cmd/pulumi-tfgen-harvester)|github.com/semdatex/pulumi-harvester/provider/cmd/pulumi-tfgen-harvester)>
# <http://github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2|github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2>
../../../../go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.54.1/pkg/tfshim/sdk-v2/resource.go:24:26: r.tf.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
../../../../go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.54.1/pkg/tfshim/sdk-v2/resource.go:90:67: r.tf.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
../../../../go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.54.1/pkg/tfshim/sdk-v2/resource.go:91:22: r.tf.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
../../../../go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.54.1/pkg/tfshim/sdk-v2/schema.go:137:23: e.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
make: *** [tfgen] Error 1
e
I filed https://github.com/pulumi/pulumi-terraform-bridge/issues/1302 - my team will have a look, I vaguely recall seeing something similar - might be due to this replace https://github.com/pulumi/pulumi-terraform-bridge/blob/master/go.mod#L6
You can try to propagate the replace into your go.mod and see if it builds
We should probably fix the codebase though to not need this replace
h
Thanks for the posting it on github.
try to propagate the replace into your go.mod and see if it builds
do you mean this?
Copy code
require <http://github.com/pulumi/terraform-plugin-sdk/v2|github.com/pulumi/terraform-plugin-sdk/v2> v2.0.0-20220824175045-450992f2f5b9
Copy code
go mod tidy 
<http://github.com/semdatex/pulumi-harvester/provider|github.com/semdatex/pulumi-harvester/provider> imports
        <http://github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge|github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge> tested by
        <http://github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.test|github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.test> imports
        <http://github.com/hashicorp/terraform-plugin-sdk/helper/schema|github.com/hashicorp/terraform-plugin-sdk/helper/schema>: <http://github.com/pulumi/terraform-plugin-sdk/v2@v2.0.0-20220824175045-450992f2f5b9|github.com/pulumi/terraform-plugin-sdk/v2@v2.0.0-20220824175045-450992f2f5b9>: parsing go.mod:
        module declares its path as: <http://github.com/hashicorp/terraform-plugin-sdk/v2|github.com/hashicorp/terraform-plugin-sdk/v2>
                but was required as: <http://github.com/pulumi/terraform-plugin-sdk/v2|github.com/pulumi/terraform-plugin-sdk/v2>
Actually, i think
replace <http://github.com/hashicorp/terraform-plugin-sdk/v2|github.com/hashicorp/terraform-plugin-sdk/v2> => <http://github.com/pulumi/terraform-plugin-sdk/v2|github.com/pulumi/terraform-plugin-sdk/v2> v2.0.0-20230710100801-03a71d0fca3d
did the trick. ```
Copy code
make tfgen  
[ -x /opt/homebrew/bin/pulumi ] || curl -fsSL <https://get.pulumi.com> | sh
pulumi plugin install resource random 4.3.1
(cd provider && go build -o /Users/gsuess/SemDatex/pulumi/harvester/bin/pulumi-tfgen-harvester -ldflags "-X <http://github.com/semdatex/pulumi-harvester/provider/pkg/version.Version=0.0.1-alpha.1688662856+041f43bc.dirty|github.com/semdatex/pulumi-harvester/provider/pkg/version.Version=0.0.1-alpha.1688662856+041f43bc.dirty>" <http://github.com/semdatex/pulumi-harvester/provider/cmd/pulumi-tfgen-harvester)|github.com/semdatex/pulumi-harvester/provider/cmd/pulumi-tfgen-harvester)>
# <http://github.com/semdatex/pulumi-harvester/provider|github.com/semdatex/pulumi-harvester/provider>
./resources.go:49:27: undefined: harvester
./resources.go:155:8: prov.MustApplyAutoAliasing undefined (type tfbridge.ProviderInfo has no field or method MustApplyAutoAliasing)
make: *** [tfgen] Error 1
At least i believe i have reached the next error down the line.
b
@happy-napkin-59884 Perhaps you would give my Cookiecutter Template for a bridged provider a chance. https://github.com/tmeckel/pulumi-tf-provider-cookiecutter.
h
I've tried running it with:
Copy code
{
  "terraform_provider_name": "harvester",
  "terraform_provider_org": "harvester",
  "terraform_provider_source": "<http://github.com/harvester/terraform-provider-harvester|github.com/harvester/terraform-provider-harvester>",
  "terraform_provider_version_or_commit": "0.6.2",
  "terraform_provider_module": "<http://github.com/harvester/terraform-provider-harvester|github.com/harvester/terraform-provider-harvester>",
  "terraform_provider_package_name": "harvester",
  "terraform_sdk_version": "2",
  "provider": "pulumi-harvester",
  "provider_display_name": "Harvester",
  "provider_github_organization": "semdatex",
  "provider_publisher": "semdatex",
  "provider_homepage": "<https://github.com/semdatex/pulumi-harvester>",
  "provider_logoUrl": "<https://www.rancher.com/assets/img/brand-guidelines/project-logos/harvester/logo-horizontal-harvester.svg>",
  "provider_description": "A Pulumi package for creating and managing Harvester resources",
  "provider_category": "infrastructure",
  "provider_download_url": "<github://api.github.com/semdatex/pulumi-harvester>",
  "provider_javascript_package": "@semdatex/pulumi-harvester",
  "provider_dotnet_rootnamespace": "semdatex",
  "provider_python_package": "pulumiverse_harvester",
  "provider_java_base_package": "com.semdatex",
  "go_version": "1.19.8",
  "create_github_workflows": "yes",
  "skip_go_mod_tidy": "no",
  "skip_git_init": "yes"
}
Getting this error.
Copy code
Connected.
ERROR: provider name MUST NOT start with terraform-provider-
ERROR: Stopping generation because pre_gen_project hook script didn't exit successfully
Hook script failed (exit status: 1)
Disconnected from container.
actually my json was not properly picked up by cookiecutter.
@big-architect-71258 After getting it to run with the correct cookiecutter.json I get a ton of module incompatibilities. I am totally new to golang, but I suspect that the reason for this is because the terraform provider is meant to run on go 1.18, whereas with your template I am forced to run on 1.19. or above. I wonder what someone more experience with golang would say about my hypothesis, and if its correct, what would it take to allow 1.18? On another note: In this whole process I have created a dockerfile to make sure that i have consistent build environment, it provides golang, nodejs, python3, .net, typescript and yarn out of the box. Thinking to create PR for it, it can also provide a github action to publish the image, let me know if that would be helpful.
b
@happy-napkin-59884 seems that the module references around k8s are broken. Please copy the
replace
section from the
go.mod
in the provider repo to both go.mod files in the Pulumi provider. Hope that helps
When finished do a
go work sync
in the top level Pulumi provider repo. Or
a
go mod tidy
in the
provider/shim
and
provider
directories. Don't do a
go work sync
😄
No module errors then, but the Pulumi Provider can't be compiled:
Copy code
(cd provider && go build -o /tmp/pulumi-harvester/bin/pulumi-tfgen-harvester -ldflags "-X <http://github.com/pulumiverse/pulumi-harvester/provider/pkg/version.Version=0.0.1-alpha.1690366080+03ad08d4|github.com/pulumiverse/pulumi-harvester/provider/pkg/version.Version=0.0.1-alpha.1690366080+03ad08d4>" <http://github.com/pulumiverse/pulumi-harvester/provider/cmd/pulumi-tfgen-harvester)|github.com/pulumiverse/pulumi-harvester/provider/cmd/pulumi-tfgen-harvester)>
# <http://github.com/harvester/terraform-provider-harvester/internal/provider/virtualmachine|github.com/harvester/terraform-provider-harvester/internal/provider/virtualmachine>
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/resource_virtualmachine_constructor.go:204:48: cannot use uint(bootOrder) (value of type uint) as int value in argument to vmBuilder.Disk
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/resource_virtualmachine_constructor.go:294:15: vmBuilder.Input undefined (type *"<http://github.com/harvester/harvester/pkg/builder|github.com/harvester/harvester/pkg/builder>".VMBuilder has no field or method Input)
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:20:22: undefined: builder.InputTypeTablet
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:22:13: undefined: builder.InputTypeTablet
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:28:22: undefined: builder.InputBusUSB
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:30:13: undefined: builder.InputBusUSB
/home/vagrant/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:31:13: undefined: builder.InputBusVirtio
h
I did not get to that point:
Copy code
$ go mod tidy
go: finding module for package [<http://github.com/harvester/terraform-provider-harvester/shim|github.com/harvester/terraform-provider-harvester/shim>](<http://github.com/harvester/terraform-provider-harvester/shim>)
[<http://github.com/semdatex/pulumi-harvester/provider|github.com/semdatex/pulumi-harvester/provider>](<http://github.com/semdatex/pulumi-harvester/provider>) imports
        [<http://github.com/harvester/terraform-provider-harvester/shim|github.com/harvester/terraform-provider-harvester/shim>](<http://github.com/harvester/terraform-provider-harvester/shim>): module [<http://github.com/harvester/terraform-provider-harvester@latest|github.com/harvester/terraform-provider-harvester@latest>](<http://github.com/harvester/terraform-provider-harvester@latest>) found (v0.6.2), but does not contain package [<http://github.com/harvester/terraform-provider-harvester/shim|github.com/harvester/terraform-provider-harvester/shim>](<http://github.com/harvester/terraform-provider-harvester/shim>)
b
Do you have a public repo where I can have a look?
h
will push it now
now pushing 2....
while prepping it for the push, i found my mistake. i have replaced the replace that were originally there.
lets see how far my build goes now
Okay now I have module problems on
go mod tidy
in shim package.
do i need to add some replaces there too?
b
That's why you need those
replace
statements. You can go one by one and copy each single replace statement from the TF provider
go.mod
into both
go.mod
files in the
provider
and
provider/shim
folder. Or you simply copy all the replace statements into those two files. You can have more than one
replace
block in a
go.mod
file. So you need not to squeeze the `replace`statements from the TF provider into the existing ones in the
go.mod
files. Just copy and paste the complete
replace
block from the TF provider.
h
okay i only did it for the prvider, not the shim
b
And by looking at you provider repo: that will never work with Pulumi. Because except Pulumi YAML you must provide language mappings at least for nodejs, dotnet, go and python. Please refer to one of the providers hosted at Pulumiverse for a correct repo layout.
h
i did not get to the SDK yet
okay i got to where you are now:
Copy code
# [<http://github.com/harvester/terraform-provider-harvester/internal/provider/virtualmachine|github.com/harvester/terraform-provider-harvester/internal/provider/virtualmachine>](<http://github.com/harvester/terraform-provider-harvester/internal/provider/virtualmachine>)
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/resource_virtualmachine_constructor.go:204:48: cannot use uint(bootOrder) (value of type uint) as type int in argument to vmBuilder.Disk
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/resource_virtualmachine_constructor.go:294:15: vmBuilder.Input undefined (type *builder.VMBuilder has no field or method Input)
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:20:22: undefined: builder.InputTypeTablet
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:22:13: undefined: builder.InputTypeTablet
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:28:22: undefined: builder.InputBusUSB
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:30:13: undefined: builder.InputBusUSB
/home/cookiecutter/go/pkg/mod/github.com/harvester/terraform-provider-harvester@v0.6.2/internal/provider/virtualmachine/schema_virtualmachine_input.go:31:13: undefined: builder.InputBusVirtio
114 Views