rough-island-84087
10/19/2023, 4:35 PMmake tfgen
is failing with this call stack:
$ make tfgen
[ -x /home/rico/bin/pulumi ] || curl -fsSL <https://get.pulumi.com> | sh
pulumi plugin install resource random 4.3.1
(cd provider && go build -o /home/rico/projects/hyperscale/pulumi-nsxt/bin/pulumi-tfgen-nsxt -ldflags "-X <http://github.com/SCC-Hyperscale-fr/pulumi-nsxt/provider/pkg/version.Version=0.0.1-alpha.1697732185+d136c29f.dirty|github.com/SCC-Hyperscale-fr/pulumi-nsxt/provider/pkg/version.Version=0.0.1-alpha.1697732185+d136c29f.dirty>" <http://github.com/SCC-Hyperscale-fr/pulumi-nsxt/provider/cmd/pulumi-tfgen-nsxt)|github.com/SCC-Hyperscale-fr/pulumi-nsxt/provider/cmd/pulumi-tfgen-nsxt)>
# <http://github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2|github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2>
/home/rico/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.62.0/pkg/tfshim/sdk-v2/resource.go:24:26: r.tf.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
/home/rico/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.62.0/pkg/tfshim/sdk-v2/resource.go:90:67: r.tf.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
/home/rico/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.62.0/pkg/tfshim/sdk-v2/resource.go:91:22: r.tf.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
/home/rico/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/v3@v3.62.0/pkg/tfshim/sdk-v2/schema.go:137:23: e.SchemaMap undefined (type *schema.Resource has no field or method SchemaMap)
make: *** [Makefile:51 : tfgen] Erreur 1
No idea what's going on, so any suggestion would be appreciated ! Thanks 🙂big-architect-71258
10/19/2023, 4:37 PMrough-island-84087
10/20/2023, 6:40 AMbig-architect-71258
10/20/2023, 7:51 AMrough-island-84087
10/20/2023, 7:54 AM// 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-20220824175045-450992f2f5b9
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
So I try to go(lang😅) next, to see if it can work. As you said, NSX is a huge package with a lot of resources and datasources... I'm digging into the code to catch them all[5/24] terraform_provider_module (<http://github.com/vmware/terraform-provider-nsxt/v3|github.com/vmware/terraform-provider-nsxt/v3>):
I have no clue of what cookiecutter expects, but seems the default "/v3" is not the right choice... And I didn't find any reference on upstrem tf provider ?big-architect-71258
10/20/2023, 9:31 AMgo.mod
file defines it as <http://github.com/vmware/terraform-provider-nsxt|github.com/vmware/terraform-provider-nsxt>
. Thus use a commit hash for the template parameter terraform_provider_version_or_commit
https://github.com/tmeckel/pulumi-tf-provider-cookiecutter#parameter-detailsrough-island-84087
10/20/2023, 9:32 AMbig-architect-71258
10/20/2023, 9:32 AM"terraform_provider_name": "nsxt",
"terraform_provider_org": "vmware",
"terraform_provider_source": "github.com/vmware/terraform-provider-nsxt",
"terraform_provider_version_or_commit": "1c47f8ee58d4e992bae27c188cf336edd67fa251",
"terraform_provider_module": "github.com/vmware/terraform-provider-nsxt",
"terraform_provider_package_name": "nsxt",
"terraform_sdk_version": "2",
rough-island-84087
10/20/2023, 9:33 AMbig-architect-71258
10/20/2023, 9:34 AMvi ~/.cookiecutter_replay/pulumi-tf-provider-cookiecutter.json
and start cookiecutter with the --replay
option.rough-island-84087
10/20/2023, 9:46 AMbig-architect-71258
10/20/2023, 9:50 AMTok: makeResource(mainMod, "<put-resourcename-here>"),
rough-island-84087
10/20/2023, 9:52 AMdhcpRelayProfile
as suggested in boilerplate readme ?big-architect-71258
10/20/2023, 10:02 AMmakeResource
and makeDatasource
call convertName
which will automatically create this name. But as I said the NSXT Provider is huge and perhaps you should move resources to separate namespaces. As I have the same isssue with the Fortios provider, I extended the `convertName`method to the following:
var module_overrides = map[string]string{}
func convertName(tfname string) (module string, name string) {
tfNameItems := strings.Split(tfname, "_")
contract.Assertf(len(tfNameItems) >= 2, "Invalid snake case name %s", tfname)
contract.Assertf(tfNameItems[0] == "fortios", "Invalid snake case name %s. Does not start with fortios", tfname)
if len(tfNameItems) == 2 {
module = mainMod
name = tfNameItems[1]
} else {
module = tfNameItems[1]
name = strings.Join(tfNameItems[2:], "_")
}
if v, ok := module_overrides[module]; ok {
module = v
}
contract.Assertf(!unicode.IsDigit(rune(module[0])), "Pulumi namespace must not start with a digit: %s", name)
contract.Assertf(!unicode.IsDigit(rune(name[0])), "Pulumi name must not start with a digit: %s", name)
name = strcase.ToPascal(name)
return
}
It will move resources/datasources automatically along the underscores to separate namespaces.module_overrides
hashtable this can be fine tuned if required. E.g. In Fortios there are resources which match the `firewallconsolidated`namespace. But with
var module_overrides = map[string]string{
"firewallconsolidated": "firewall/consolidated",
They are moved to the firewall/consolidated
namespace. But be aware that with dotnet
there seems to be an issue with the language generator.rough-island-84087
10/20/2023, 10:14 AMwarning: Found <elided> in description for [nsxt_vlan_logical_switch]. The description and any examples will be dropped in the Pulumi provider.
warning: Unexpected code snippets in section 'Importing' for resource 'nsxt_vm_tags'. The HCL code will be converted if possible, but may not display correctly in the generated docs.
warning: Found <elided> in description for [nsxt_vm_tags]. The description and any examples will be dropped in the Pulumi provider.
error: failed to gather package metadata: problem gathering resources: 7 errors occurred:
* Pulumi token "nsxt:index/edgeHighAvailabilityProfile:EdgeHighAvailabilityProfile" is mapped to TF provider resource "nsxt_edge_high_availability_profile", but no such resource found. The mapping will be ignored in the generated provider
* Pulumi token "nsxt:index/nodeUser:NodeUser" is mapped to TF provider resource "nsxt_node_user", but no such resource found. The mapping will be ignored in the generated provider
* Pulumi token "nsxt:index/policyHostTransportNode:PolicyHostTransportNode" is mapped to TF provider resource "nsxt_policy_host_transport_node", but no such resource found. The mapping will be ignored in the generated provider
* Pulumi token "nsxt:index/policyHostTransportNodeCollection:PolicyHostTransportNodeCollection" is mapped to TF provider resource "nsxt_policy_host_transport_node_collection", but no such resource found. The mapping will be ignored in the generated provider
* Pulumi token "nsxt:index/policyUplinkHostSwitchProfile:PolicyUplinkHostSwitchProfile" is mapped to TF provider resource "nsxt_policy_uplink_host_switch_profile", but no such resource found. The mapping will be ignored in the generated provider
* Pulumi token "nsxt:index/policyUserManagementRole:PolicyUserManagementRole" is mapped to TF provider resource "nsxt_policy_user_management_role", but no such resource found. The mapping will be ignored in the generated provider
* Pulumi token "nsxt:index/policyUserManagementRoleBinding:PolicyUserManagementRoleBinding" is mapped to TF provider resource "nsxt_policy_user_management_role_binding", but no such resource found. The mapping will be ignored in the generated provider
I have no clue why some mappings are not found while they are explicitly declared here : https://github.com/vmware/terraform-provider-nsxt/blob/master/nsxt/provider.gobig-architect-71258
10/20/2023, 10:21 AMrough-island-84087
10/20/2023, 10:32 AMbig-architect-71258
10/20/2023, 10:35 AMUpstreamRepoPath: "./upstream",
property in tfbridge.ProviderInfo
.
To automate this the Makefile should be extended as well:
upstream/.git:
@echo "Initializing upstream" ; \
git clone --depth 1 --branch <branch-name> <https://github.com/><repo> upstream
Whereas the upstream/.git
target should be a dependency for the tfgen
target.make build_sdks
rough-island-84087
10/20/2023, 10:37 AMbig-architect-71258
10/20/2023, 10:41 AMprovider/generator.go
file to your repo and add a line //go:generate go run generate.go
to the provider/resources.go
and you can use go generate
to let the generator add missing mapping automatically.