From 8259c2b24ee51dd03d5ff8f105daa57e2a3a1319 Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Thu, 1 Dec 2022 14:58:27 -0800 Subject: [PATCH] [sdk/nodejs] Fix regression when passing a provider to a MLC https://github.com/pulumi/pulumi/pull/11093 changed the Node.js SDK to pass a provider specified in a MLC's `ResourceOptions.provider` to the engine. Unfortunately, this regresses behavior that existing programs rely on. For example: ```ts import * as aws from "@pulumi/aws"; import * as awsx from "@pulumi/awsx"; const myRegion = new aws.Provider("us-east-1", { region: "us-east-1", }); const vpc = new awsx.ec2.Vpc("awsx-nodejs-default-args", {}, { provider: myRegion }); ``` In the above program, an explicit _aws_ provider is being passed to the _awsx_ `VPC` component, with the intention that the _aws_ provider will be used as the provider for all of `Vpc`'s children. With the change in https://github.com/pulumi/pulumi/pull/11093, the engine would try to call `Construct` for the `Vpc` using the specified `aws` provider, which does not work (it fails with `plugins that can construct components must support secrets`). This change reverts the change from https://github.com/pulumi/pulumi/pull/11093 that included the `provider` in the `RegisterResourceRequest` for MLCs, and adds a regression test to lock-in the previous behavior. Note: We do want to be able to support specifying a MLC's provider (to allow explicit providers for MLCs), but we'll address that in a separate change. --- ...dejs--fix-regression-when-passing-a-provider-to-a-mlc.yaml | 4 ++++ sdk/nodejs/runtime/resource.ts | 2 +- sdk/nodejs/tests/runtime/langhost/run.spec.ts | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelog/pending/20221201--sdk-nodejs--fix-regression-when-passing-a-provider-to-a-mlc.yaml diff --git a/changelog/pending/20221201--sdk-nodejs--fix-regression-when-passing-a-provider-to-a-mlc.yaml b/changelog/pending/20221201--sdk-nodejs--fix-regression-when-passing-a-provider-to-a-mlc.yaml new file mode 100644 index 000000000000..510d02e39772 --- /dev/null +++ b/changelog/pending/20221201--sdk-nodejs--fix-regression-when-passing-a-provider-to-a-mlc.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdk/nodejs + description: Fix regression when passing a provider to a MLC diff --git a/sdk/nodejs/runtime/resource.ts b/sdk/nodejs/runtime/resource.ts index 443bdd75c7ce..a4b12e831b9e 100644 --- a/sdk/nodejs/runtime/resource.ts +++ b/sdk/nodejs/runtime/resource.ts @@ -529,7 +529,7 @@ async function prepareResource(label: string, res: Resource, parent: Resource | let providerRef: string | undefined; let importID: ID | undefined; - if (custom || remote) { + if (custom) { const customOpts = opts; importID = customOpts.import; providerRef = await ProviderResource.register(opts.provider); diff --git a/sdk/nodejs/tests/runtime/langhost/run.spec.ts b/sdk/nodejs/tests/runtime/langhost/run.spec.ts index 73d9b35e1e05..53df7166b0d9 100644 --- a/sdk/nodejs/tests/runtime/langhost/run.spec.ts +++ b/sdk/nodejs/tests/runtime/langhost/run.spec.ts @@ -1214,6 +1214,7 @@ describe("rpc", () => { propertyDeps?: any, ignoreChanges?: string[], version?: string, importID?: string, replaceOnChanges?: string[], providers?: any) => { if (name === "singular" || name === "map" || name === "array") { + assert.strictEqual(provider, ""); assert.deepStrictEqual(Object.keys(providers), ["test"]); } return { urn: makeUrn(t, name), id: undefined, props: undefined };