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

Automatically unmarshal complex configuration types #171

Closed
blampe opened this issue Dec 20, 2023 · 2 comments · Fixed by #269
Closed

Automatically unmarshal complex configuration types #171

blampe opened this issue Dec 20, 2023 · 2 comments · Fixed by #269
Assignees
Labels
customer/feedback Feedback from customers kind/enhancement Improvements or new features resolution/fixed This issue was fixed

Comments

@blampe
Copy link
Contributor

blampe commented Dec 20, 2023

Non-primitive config fields are automatically JSON.Stringify-d when sent to the server:

https://github.com/pulumi/pulumi/blob/f500bef2fa732aab23c644dc07ed9b101a9cfaaf/pkg/codegen/nodejs/gen.go#L794-L797

				// provider properties must be marshaled as JSON strings.
				if r.IsProvider && !isStringType(prop.Type) {
					arg = fmt.Sprintf("pulumi.output(%s).apply(JSON.stringify)", arg)
				}

However we aren't unmarshaling them on the receiving end. A type like this results in an error:

package foo

type Config struct {
   Foo []string `pulumi:"foo"`
}
error: ... provider returned an unexpected error from Configure: unknown mapper error: Field 'foo' on 'foo.Config' must be a '[]string'; got 'string' instead

The bridge seems to handle this here:

https://github.com/pulumi/pulumi-terraform-bridge/blob/0f7ccfdef31d3fddd4eb46c9770d460bbfbe81e3/pkg/tfbridge/config_encoding.go#L150C11-L174

    var jsonString string
    var jsonStringDetected, jsonStringSecret bool


    if pv.IsString() {
        jsonString = pv.StringValue()
        jsonStringDetected = true
    }


    if opts.KeepSecrets && pv.IsSecret() && pv.SecretValue().Element.IsString() {
        jsonString = pv.SecretValue().Element.StringValue()
        jsonStringDetected = true
        jsonStringSecret = true
    }


    if jsonStringDetected {
        v, err := enc.convertStringToPropertyValue(jsonString, shimType)
        if err != nil {
            return nil, fmt.Errorf("error unmarshalling property %q: %w", key, err)
        }
        if jsonStringSecret {
            s := resource.MakeSecret(v)
            return &s, nil
        }
        return &v, nil
    }

I think this is essentially the issue:

func (p *provider) Configure(ctx context.Context, req *rpc.ConfigureRequest) (*rpc.ConfigureResponse, error) {
argMap, err := p.getMap(req.GetArgs())

We unmarshal the provider's config the same way we unmarshal properties, but this JSON behavior is unique to config.

@blampe blampe added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Dec 20, 2023
@blampe blampe changed the title Automatically unmarshal complex types Automatically unmarshal complex configuration types Dec 20, 2023
@mjeffryes mjeffryes removed the needs-triage Needs attention from the triage team label Dec 21, 2023
@mikhailshilkov mikhailshilkov added the customer/feedback Feedback from customers label Sep 6, 2024
@iwahbe iwahbe closed this as completed in 9c1bcdd Sep 10, 2024
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Sep 10, 2024
@pulumi-bot
Copy link

This issue has been addressed in PR #269 and shipped in release v0.22.0.

@pulumi-bot
Copy link

This issue has been addressed in PR #269 and shipped in release v0.23.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer/feedback Feedback from customers kind/enhancement Improvements or new features resolution/fixed This issue was fixed
Projects
None yet
5 participants