There's an annoying inefficiency in the NodeJS SDK...
# automation-api
m
There's an annoying inefficiency in the NodeJS SDK, and I'm wondering if I'm missing anything. What I want to do: check current operation (or last operation) for some stacks, and if its "destroy", do some stuff. What it would look like with RestAPI: 1. List stacks 2. For each stack: a. getStack b. check
current_operation.kind
in the output c. do my stuff What it looks like with NodeJS automation SDK: 1. List stacks 2. For each stack: a.
Stack.select()
which is mandatory for getting a Stack object. This does the
getStack
API call behind the scenes, but discards its output, so the Stack object I get (and the only Stack interface in NodeJS SDK) does not have the
current_operation
information. b.
<http://stack.info|stack.info>()
(another API call) c. check the result of the output of
info
d. do my stuff. It is really annoying that the NodeJS automation API is structured in a way that forces two API calls where the REST API only requires one. Is there a NodeJS SDK that is a more direct wrapper of the APIs that I could use instead? Or maybe something else I'm missing?
I wanted to open a ticket, and maybe even contribute a fix... but perhaps someone from Pulumi can clarify if this thing should be reported as a bug or a feature require 😅
r
I may be misremembering, but I was under the impression that
Stack.select()
just did
pulumi stack select
, which does not result in an API call, it's just a local operation.
Seems to still be the case: https://github.com/pulumi/pulumi/blob/master/sdk/nodejs/automation/localWorkspace.ts#L431-L437 So really, the REST API and automation API make the same number of API calls for this information
m
This calls the CLI. Do you know for sure that the CLI doesn’t make an API call? I may have misread the code.
r
Yes, I'm fairly certain
pulumi stack select
does not make any API calls, it's been a few years since I worked on this part of Pulumi but it's all local operations as far as I remember it https://github.com/pulumi/pulumi/blob/master/pkg/cmd/pulumi/stack_select.go