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

Failed marshaling of arguments with nested structs of input types #270

Open
MMartyn opened this issue Sep 9, 2024 · 5 comments
Open

Failed marshaling of arguments with nested structs of input types #270

MMartyn opened this issue Sep 9, 2024 · 5 comments
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@MMartyn
Copy link
Contributor

MMartyn commented Sep 9, 2024

What happened?

I am not sure if this error is expected and is the same as referenced here https://github.com/pulumi/pulumi-go-provider/blob/main/examples/random-login/main.go#L41, but essentially we have component arguments that contain a nested struct that has a pulumi.StringInput. The provider compiles successfully, but when you use it it throws a error: an unhandled error occurred: waiting for RPCs: rpc error: code = Unknown desc = waiting for RPCs: cannot marshal an input of type pulumi.StringOutput with element type string as a value of type pulumi.StringInput

Example

The following will throw the marshal error:

type CustomComponent struct{}

type NestedThing struct {
	Bar string             `pulumi:"bar"`
	Baz Pulumi.StringInput `pulumi:"baz"`
}

type CustomComponentArgs struct {
	Foo         string      `pulumi:"foo"`
	NestedThing NestedThing `pulumi:"nestedThing"`
}

type CustomComponentState struct {
	pulumi.ResourceState
	CustomComponentArgs
	// Outputs
	// None at this time
}

func (k *CustomComponent) Construct(ctx *pulumi.Context, name, typ string, args CustomComponentArgs, opts pulumi.ResourceOption) (*CustomComponentState, error) {
	comp := &CustomComponentState{CustomComponentArgs: args}
    .....
}

If we remove the CustomComponentArgs from the CustomComponentState struct and make the comp just comp := &CustomComponentState{} it will run without error. I am unsure of any errors that will result from removing this from the state as in the example this is how I see it working.

Output of pulumi about

CLI
Version 3.131.0
Go Version go1.23.0
Go Compiler gc

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

@MMartyn MMartyn added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Sep 9, 2024
@mjeffryes
Copy link
Member

I'm not 100% sure on this, but I wonder if that error isn't coming from the fact that baz in NestedThing is a Pulumi.StringInput and we can't coerce the output values to a StringInput. Does it work if baz is a plain string?

@MMartyn
Copy link
Contributor Author

MMartyn commented Sep 12, 2024

Yeah plain values are fine but Input/Output types don't work in nested structs. Unfortunately the value I am passing in is in reality is a Pulumi.StringOutput that is not known until a dependent resource is created.

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

iwahbe commented Sep 12, 2024

@MMartyn The error message looks like the marshaling code is having issues with inputs vs outputs. Can you try marking baz as an output:

 type NestedThing struct {
 	bar string             `pulumi:"bar"`
-	baz Pulumi.StringInput `pulumi:"baz"`
+	baz Pulumi.StringOutput `pulumi:"baz"`
 }

Do you see the same error message?


Also, I'm pretty sure that nothing will work right for un-exported fields (baz vs Baz).

@MMartyn
Copy link
Contributor Author

MMartyn commented Sep 12, 2024

My bad, I messed up the capitalization when writing the example for the ticket. But know that the fields are properly capitalized in the real code.

@MMartyn
Copy link
Contributor Author

MMartyn commented Sep 12, 2024

Edited example to show proper capitalization to match the real world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

3 participants