Skip to content

Commit

Permalink
Merge #11382
Browse files Browse the repository at this point in the history
11382: Keep resource refs when invoking `pulumi:pulumi:getResource` r=justinvp a=justinvp

We used to always keep resource references when marshaling the results of `pulumi:pulumi:getResource`, but this regressed in #9323 to only keep resource if the invoke request's `acceptResources` flag was set. Unfortunately, that flag is not being set when calling `pulumi:pulumi:getResource` in the Go, Node.js, and Python SDKs (although, it is being set for .NET and Java).

Two fixes:
1. Update the monitor to go back to always keeping resources when `pulumi:pulumi:getResource` is being invoked. This way, older SDKs that are not setting `acceptResources` will go back to the original behavior.
2. Update the SDKs to always set `acceptResources`, so that these newer versions of the SDKs will work with older engines that are checking `acceptResources`.

(2) will help us with EKS 1.0. We'll be able to update EKS to use a version of ``@pulumi/pulumi`` with the fix to set the `acceptResources` flag.

Note: We definitely need tests to lock-in the behavior here so it doesn't re-regress in the future. But I also would like to get the nodejs SDK fix in the next release, because we need it for EKS. So, I'd like to add the tests as a follow-up to this PR, unless someone feels strongly it needs to be included with this change.

Fixes #11380

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
  • Loading branch information
bors[bot] and justinvp committed Nov 16, 2022
2 parents 6f21c0d + 1949b65 commit b950cf0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: engine
description: Always keep resources when pulumi:pulumi:getResource is invoked
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdk/go,nodejs,python
description: Set acceptResources when invoking pulumi:pulumi:getResource
11 changes: 10 additions & 1 deletion pkg/resource/deploy/source_eval.go
Expand Up @@ -710,11 +710,20 @@ func (rm *resmon) Invoke(ctx context.Context, req *pulumirpc.ResourceInvokeReque
if err != nil {
return nil, fmt.Errorf("invocation of %v returned an error: %w", tok, err)
}

// Respect `AcceptResources` unless `tok` is for the built-in `pulumi:pulumi:getResource` function,
// in which case always keep resources to maintain the original behavior for older SDKs that are not
// setting the `AccceptResources` flag.
keepResources := req.GetAcceptResources()
if tok == "pulumi:pulumi:getResource" {
keepResources = true
}

mret, err := plugin.MarshalProperties(ret, plugin.MarshalOptions{
Label: label,
KeepUnknowns: true,
KeepSecrets: true,
KeepResources: req.GetAcceptResources(),
KeepResources: keepResources,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal %v return: %w", tok, err)
Expand Down
5 changes: 3 additions & 2 deletions sdk/go/pulumi/context.go
Expand Up @@ -723,8 +723,9 @@ func (ctx *Context) getResource(urn string) (*pulumirpc.RegisterResourceResponse
tok := "pulumi:pulumi:getResource"
logging.V(9).Infof("Invoke(%s, #args=%d): RPC call being made synchronously", tok, len(resolvedArgsMap))
resp, err := ctx.monitor.Invoke(ctx.ctx, &pulumirpc.ResourceInvokeRequest{
Tok: "pulumi:pulumi:getResource",
Args: rpcArgs,
Tok: "pulumi:pulumi:getResource",
Args: rpcArgs,
AcceptResources: !disableResourceReferences,
})
if err != nil {
return nil, fmt.Errorf("invoke(%s, ...): error: %v", tok, err)
Expand Down
1 change: 1 addition & 0 deletions sdk/nodejs/runtime/resource.ts
Expand Up @@ -114,6 +114,7 @@ export function getResource(res: Resource, parent: Resource | undefined, props:
req.setArgs(gstruct.Struct.fromJavaScript(inputs));
req.setProvider("");
req.setVersion("");
req.setAcceptresources(!utils.disableResourceReferences);

// Now run the operation, serializing the invocation if necessary.
const opLabel = `monitor.getResource(${label})`;
Expand Down
11 changes: 10 additions & 1 deletion sdk/python/lib/pulumi/runtime/resource.py
Expand Up @@ -243,8 +243,17 @@ async def do_get():

monitor = settings.get_monitor()
inputs = await rpc.serialize_properties({"urn": urn}, {})

accept_resources = not (
os.getenv("PULUMI_DISABLE_RESOURCE_REFERENCES", "").upper()
in {"TRUE", "1"}
)
req = resource_pb2.ResourceInvokeRequest(
tok="pulumi:pulumi:getResource", args=inputs, provider="", version=""
tok="pulumi:pulumi:getResource",
args=inputs,
provider="",
version="",
acceptResources=accept_resources,
)

def do_invoke():
Expand Down

0 comments on commit b950cf0

Please sign in to comment.