Skip to content

Commit

Permalink
feat: enable imports from nodejs provider resources (#14668)
Browse files Browse the repository at this point in the history
# Description
I was writing a typescript resource provider, but got errors that the
the plugin didn't support imports, while the `read` method was
implemented on the provider.
This PR also sets the `Inputs` on the `ReadResponse`, so imports will be
supported.

Fixes # (issue)
Could not find existing issue

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
(None of the above, since the change is in js code)

- [ ] I have added tests that prove my fix is effective or that my
feature works
There are no existing tests for the `server.ts` file. If really required
for merging I could maybe take a look at a test for this use-case.

- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change

- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
  • Loading branch information
bfraterman-tkhsecurity authored Nov 30, 2023
1 parent dc63265 commit 25f1e52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: sdk/nodejs
description: Enable resource imports for nodejs providers
4 changes: 4 additions & 0 deletions sdk/nodejs/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export interface ReadResult {
* The current property state read from the live environment.
*/
readonly props?: any;
/**
* The inputs that would lead to the current resource state when importing it.
*/
readonly inputs?: any;
}

/**
Expand Down
1 change: 1 addition & 0 deletions sdk/nodejs/provider/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class Server implements grpc.UntypedServiceImplementation {
const result: any = await this.provider.read(id, req.getUrn(), props);
resp.setId(result.id);
resp.setProperties(structproto.Struct.fromJavaScript(result.props));
resp.setInputs(structproto.Struct.fromJavaScript(result.inputs));
} else {
// In the event of a missing read, simply return back the input state.
resp.setId(id);
Expand Down

0 comments on commit 25f1e52

Please sign in to comment.