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

Unable to convert HCL example #11305

Closed
dirien opened this issue Nov 9, 2022 · 4 comments · Fixed by #11311
Closed

Unable to convert HCL example #11305

dirien opened this issue Nov 9, 2022 · 4 comments · Fixed by #11311
Assignees
Labels
area/providers impact/panic This bug represents a panic or unexpected crash kind/bug Some behavior is incorrect or out of spec p1 Bugs severe enough to be the next item assigned to an engineer resolution/fixed This issue was fixed
Milestone

Comments

@dirien
Copy link
Contributor

dirien commented Nov 9, 2022

What happened?

With the latest version of

github.com/pulumi/pulumi-terraform-bridge/v3
github.com/pulumi/pulumi/sdk/v3

The provider I'm building is pulumiverse/pulumi-aquasec.

I get following output, when creating the sdks:

warning: unable to convert HCL example for Pulumi entity '#/functions/aquasec:index/getPermissionsSets:getPermissionsSets': 1 error occurred:
        * failed to convert HCL for #/functions/aquasec:index/getPermissionsSets:getPermissionsSets to csharp: panic converting HCL: runtime error: invalid memory address or nil pointer dereference

. The example will be dropped from any generated docs or SDKs.
warning: unable to convert HCL example for Pulumi entity '#/functions/aquasec:index/getRoles:getRoles': 1 error occurred:
        * failed to convert HCL for #/functions/aquasec:index/getRoles:getRoles to csharp: panic converting HCL: runtime error: invalid memory address or nil pointer dereference

See https://github.com/pulumiverse/pulumi-aquasec/actions/runs/3426284456/jobs/5708011242#step:11:236 for more output in the GitHub action.

Steps to reproduce

Run the generation of the sdks in this provider -> https://github.com/pulumiverse/pulumi-aquasec

Expected Behavior

Examples get converted from HCL to the language

Actual Behavior

The example will be dropped from any generated docs or SDKs.

Output of pulumi about

pulumi about
CLI          
Version      3.46.0
Go Version   go1.19.2
Go Compiler  gc

Host     
OS       darwin
Version  12.5
Arch     arm64

Additional context

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).

@dirien dirien added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Nov 9, 2022
@RobbieMcKinstry
Copy link
Contributor

Here's a stack trace I captured from my reproduction. Regardless of the language, all codegen reliably creates a trace like this (looked at dotnet, go, and node).

warning: unable to convert HCL example for Pulumi entity '#/functions/aquasec:index/getUsersSaas:getUsersSaas': 1 error occurred:
	* failed to convert HCL for #/functions/aquasec:index/getUsersSaas:getUsersSaas to go: panic converting HCL: runtime error: invalid memory address or nil pointer dereference. The stack trace from the panic is:
goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x64
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convert.func1()
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/docs.go:1189 +0xb4
panic({0x104a7dd40, 0x105d5b1b0})
	/usr/local/go/src/runtime/panic.go:884 +0x204
github.com/pulumi/pulumi/pkg/v3/codegen/pcl.annotateObjectProperties({0x104ddb2c0?, 0x14001d46d40}, {0x104dc88a0?, 0x0?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/pcl/invoke.go:62 +0x148
github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindInvokeSignature(0x14001d77b00, {0x14001d69340, 0x2, 0x0?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/pcl/invoke.go:153 +0x808
github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model.GenericFunctionSignature.GetSignature(0x14001d7a390?, {0x14001d69340?, 0x6?, 0x1039de960?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/hcl2/model/functions.go:57 +0x44
github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model.(*Function).GetSignature(...)
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/hcl2/model/functions.go:82
github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model.(*expressionBinder).bindFunctionCallExpression(0x14001b2ba60, 0x140001fa870)
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/hcl2/model/binder_expression.go:431 +0x118
github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model.(*expressionBinder).bindExpression(0x14001b2ba68?, {0x104dc7770?, 0x140001fa870?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/hcl2/model/binder_expression.go:86 +0x2b0
github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model.BindExpression({0x104dc7770, 0x140001fa870}, 0x14001d7a390, {0x104dcb5a0, 0x14001d7a360}, {0x14001b2bb60, 0x1, 0x103a49e8c?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/hcl2/model/binder_expression.go:60 +0xbc
github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model.BindAttribute(0x14001be4e00, 0x0?, {0x104dcb5a0, 0x14001d7a360}, {0x14001b2bb60, 0x1, 0x1})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/hcl2/model/attribute.go:78 +0x74
github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindLocalVariable(0x14001d77b00?, 0x14001d7a4e0)
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/pcl/binder_nodes.go:116 +0x98
github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindNode(0x104933e20?, {0x104ddbd88, 0x14001d7a4e0})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/pcl/binder_nodes.go:59 +0x32c
github.com/pulumi/pulumi/pkg/v3/codegen/pcl.BindProgram({0x1400045a848?, 0x1, 0x1}, {0x14001d46740, 0x6, 0x4?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/pkg/v3@v3.44.2/codegen/pcl/binder.go:156 +0xb18
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/convert.convertTF12({0x1400045a7e8, 0x1, 0x104278a41?}, {0x1, 0x0, 0x1, 0x0, 0x0, 0x1, {0x0, ...}, ...})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tf2pulumi/convert/tf12.go:168 +0x1528
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/convert.internalEject({0x1, 0x0, 0x1, 0x0, 0x0, 0x1, {0x0, 0x0}, {0x104ddcbe0, 0x14001d6b110}, ...})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tf2pulumi/convert/eject.go:145 +0x27c
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/convert.Convert({0x1, 0x0, 0x1, 0x0, 0x0, 0x1, {0x0, 0x0}, {0x104ddcbe0, 0x14001d6b110}, ...})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tf2pulumi/convert/convert.go:95 +0x1b4
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convert(0x140000d8280, {0x104ddcbe0, 0x14001d6b110}, {0x10426f3fa, 0x2})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/docs.go:1196 +0x284
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convertHCLToString(0x140000d8280, {0x14000d31e80, 0x75}, {0x14001131280, 0x33}, {0x10426f3fa, 0x2})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/docs.go:1224 +0x14c
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convertHCL(0x140000d8280, {0x14000d31e80, 0x75}, {0x14001131280, 0x33}, {0x0, 0x0}, {0x14001d670d0, 0x1, 0x0?})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/docs.go:1354 +0x920
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convertExamples(0x140000d8280, {0x14000d371e0, 0x153}, {0x14001131280, 0x33}, 0x1)
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/docs.go:1107 +0xe64
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convertExamplesInFunctionSpec(0x14001b2dae0?, {0x14001131280, 0x33}, {{0x14000d371e0, 0x153}, 0x0, 0x14000ad1490, {0x0, 0x0}, 0x0, ...})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/generate_schema.go:842 +0x7c
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).convertExamplesInSchema(_, {{0x14000550070, 0x7}, {0x1042776e5, 0x7}, {0x1047e5620, 0xb}, {0x104301243, 0x43}, {0x140003d4db0, ...}, ...})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/generate_schema.go:867 +0x500
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.(*Generator).Generate(0x140000d8280)
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/generate.go:783 +0x238
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.newTFGenCmd.func1(0x0?, {0x14000ab0500, 0x1, 0x0?})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/main.go:144 +0x468
github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil.RunFunc.func1(0x0?, {0x14000ab0500?, 0x0?, 0x0?})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.2/go/common/util/cmdutil/exit.go:96 +0x28
github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil.RunResultFunc.func1(0x140000f8000?, {0x14000ab0500, 0x1, 0x8})
	/Users/robbiemckinstry/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.2/go/common/util/cmdutil/exit.go:112 +0x38
github.com/spf13/cobra.(*Command).execute(0x140000f8000, {0x1400004e0a0, 0x8, 0x8})
	/Users/robbiemckinstry/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:876 +0x4b8
github.com/spf13/cobra.(*Command).ExecuteC(0x140000f8000)
	/Users/robbiemckinstry/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:990 +0x354
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/robbiemckinstry/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:918
github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen.Main({_, _}, {_, _}, {{0x104de0440, 0x1400053c420}, {0x10427802a, 0x7}, {0x0, 0x0}, ...})
	/Users/robbiemckinstry/workspace/pulumi/pulumi-terraform-bridge/pkg/tfgen/main.go:36 +0x4c
main.main()
	/Users/robbiemckinstry/workspace/pulumi/pulumi-aquasec/provider/cmd/pulumi-tfgen-aquasec/main.go:25 +0x7c

@RobbieMcKinstry RobbieMcKinstry added p1 Bugs severe enough to be the next item assigned to an engineer area/providers impact/panic This bug represents a panic or unexpected crash and removed needs-triage Needs attention from the triage team labels Nov 9, 2022
@RobbieMcKinstry RobbieMcKinstry added this to the 0.80 milestone Nov 9, 2022
@RobbieMcKinstry
Copy link
Contributor

Thanks for submitting this @dirien . My first PR in this area of the codebase, but I think we were just missing a guard. Hopefully its as simple as this.

@RobbieMcKinstry RobbieMcKinstry self-assigned this Nov 9, 2022
bors bot added a commit that referenced this issue Nov 14, 2022
11311: Guard against empty inputs for objs expressions. r=RobbieMcKinstry a=RobbieMcKinstry

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

`@dirien` raised an issue where tfgen would panic converting PCL under an edge case where an `ObjectExpression` had `nil` arguments. By introducing this guard, we skip annotating the the Object with the type provided by the schema the function in the schema has no args.

S/o to `@Zaid-Ajaj` for explaining this code to me and confirming the kill. I was lost without his aid! 

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #11305

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Robbie McKinstry <robbie@pulumi.com>
@RobbieMcKinstry
Copy link
Contributor

We're merging a fix for this now. I was able to locally verify correctness. Please let me know if you still encounter this issue after the next release and we can reopen. 👍🏻

@RobbieMcKinstry RobbieMcKinstry modified the milestones: 0.80, 0.81 Nov 14, 2022
bors bot added a commit that referenced this issue Nov 15, 2022
11311: Guard against empty inputs for objs expressions. r=RobbieMcKinstry a=RobbieMcKinstry

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

`@dirien` raised an issue where tfgen would panic converting PCL under an edge case where an `ObjectExpression` had `nil` arguments. By introducing this guard, we skip annotating the the Object with the type provided by the schema the function in the schema has no args.

S/o to `@Zaid-Ajaj` for explaining this code to me and confirming the kill. I was lost without his aid! 

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #11305

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Robbie McKinstry <robbie@pulumi.com>
@bors bors bot closed this as completed in f6d09b8 Nov 15, 2022
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Nov 15, 2022
@dirien
Copy link
Contributor Author

dirien commented Nov 15, 2022

Thanks @RobbieMcKinstry! Will let u know! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/providers impact/panic This bug represents a panic or unexpected crash kind/bug Some behavior is incorrect or out of spec p1 Bugs severe enough to be the next item assigned to an engineer resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants