Skip to content

Commit

Permalink
go: allow unknowns during update (#15942)
Browse files Browse the repository at this point in the history
Currently we reject all unknowns during `pulumi up`. However we are soon
going to allow them to come through via `up --continue-on-error`, and
thus should no longer error out when we have them.

This is a similar preparatory PR to
#15898, except that Go deals with
the unknowns a little different, so we don't need to treat apply
specially, but the marshalling.
  • Loading branch information
tgummerer committed Apr 15, 2024
1 parent a7e0551 commit 44c8de5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: sdk/go
description: Allow unknowns during `pulumi up`
58 changes: 27 additions & 31 deletions sdk/go/pulumi/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,11 @@ func (ctx *Context) registerTransform(t XResourceTransform) (*pulumirpc.Callback

rpcRes.Properties, err = plugin.MarshalProperties(
properties,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: ctx.state.keepResources,
}),
},
)
if err != nil {
return nil, fmt.Errorf("marshaling properties: %w", err)
Expand Down Expand Up @@ -574,10 +575,11 @@ func (ctx *Context) Invoke(tok string, args interface{}, result interface{}, opt

rpcArgs, err := plugin.MarshalProperties(
resolvedArgsMap,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: ctx.state.keepResources,
}),
},
)
if err != nil {
return fmt.Errorf("marshaling arguments: %w", err)
Expand Down Expand Up @@ -612,10 +614,11 @@ func (ctx *Context) Invoke(tok string, args interface{}, result interface{}, opt
// Otherwise, simply unmarshal the output properties and return the result.
outProps, err := plugin.UnmarshalProperties(
resp.Return,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: true,
}),
},
)
if err != nil {
return err
Expand Down Expand Up @@ -707,11 +710,12 @@ func (ctx *Context) Call(tok string, args Input, output Output, self Resource, o
// Marshal all properties for the RPC call.
rpcArgs, err := plugin.MarshalProperties(
resolvedArgs,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: ctx.state.keepResources,
KeepOutputValues: ctx.state.keepOutputValues,
}))
})
if err != nil {
return nil, fmt.Errorf("marshaling args: %w", err)
}
Expand Down Expand Up @@ -754,10 +758,11 @@ func (ctx *Context) Call(tok string, args Input, output Output, self Resource, o

var outprops resource.PropertyMap
if err == nil {
outprops, err = plugin.UnmarshalProperties(ret, ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
outprops, err = plugin.UnmarshalProperties(ret, plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: true,
}))
})
}
if err != nil {
logging.V(9).Infof("Call(%s, ...): success: w/ unmarshal error: %v", tok, err)
Expand Down Expand Up @@ -1006,10 +1011,11 @@ func (ctx *Context) getResource(urn string) (*pulumirpc.RegisterResourceResponse

rpcArgs, err := plugin.MarshalProperties(
resolvedArgsMap,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: ctx.state.keepResources,
}),
},
)
if err != nil {
return nil, fmt.Errorf("marshaling arguments: %w", err)
Expand Down Expand Up @@ -1543,10 +1549,11 @@ func (state *resourceState) resolve(ctx *Context, err error, inputs *resourceInp
if err == nil {
outprops, err = plugin.UnmarshalProperties(
result,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: true,
}),
},
)
}
if err != nil {
Expand Down Expand Up @@ -1825,13 +1832,14 @@ func (ctx *Context) prepareResourceInputs(res Resource, props Input, t string, o
// Marshal all properties for the RPC call.
rpcProps, err := plugin.MarshalProperties(
resolvedProps,
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: ctx.state.keepResources,
// To initially scope the use of this new feature, we only keep output values when
// remote is true (for multi-lang components).
KeepOutputValues: remote && ctx.state.keepOutputValues,
}))
})
if err != nil {
return nil, fmt.Errorf("marshaling properties: %w", err)
}
Expand Down Expand Up @@ -2070,10 +2078,11 @@ func (ctx *Context) RegisterResourceOutputs(resource Resource, outs Map) error {

outsMarshalled, err := plugin.MarshalProperties(
outsResolved.ObjectValue(),
ctx.withKeepOrRejectUnknowns(plugin.MarshalOptions{
plugin.MarshalOptions{
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: ctx.state.keepResources,
}))
})
if err != nil {
return
}
Expand Down Expand Up @@ -2128,19 +2137,6 @@ func (ctx *Context) NewOutput() (Output, func(interface{}), func(error)) {
return newAnyOutput(&ctx.state.join)
}

// Sets marshalling flags based on `ctx.state.DryRun()`: we will either
// preserve unknowns as-is or fail strictly with an exception if any
// unkowns are found. The third option, filtering out unknown values
// from the data structure being marshalled, is never used.
func (ctx *Context) withKeepOrRejectUnknowns(options plugin.MarshalOptions) plugin.MarshalOptions {
if ctx.DryRun() {
options.KeepUnknowns = true
} else {
options.RejectUnknowns = true
}
return options
}

// Returns the source position of the Nth stack frame, where N is skip+1.
//
// This is used to compute the source position of the user code that instantiated a resource. The number of frames to
Expand Down

0 comments on commit 44c8de5

Please sign in to comment.