https://pulumi.com logo
#automation-api
Title
# automation-api
i

icy-jordan-58549

06/08/2021, 11:25 AM
Any ideas, why I can’t use this inside automation-api process?
Copy code
const config = await authorization.getClientConfig();
const token = await authorization.getClientToken();
Getting:
Copy code
creating error: Program run without the Pulumi engine available; re-run using the `pulumi` CLI
b

bored-oyster-3147

06/08/2021, 12:50 PM
Your error looks unrelated. Do you have the Pulumi CLI installed? Automation API currently depends on the CLI still.
i

icy-jordan-58549

06/08/2021, 2:15 PM
yep, it’s installed… btw, I have tested this inside automation api in another script and it does work
probably something wrong with my CustomProvider
b

bored-oyster-3147

06/08/2021, 2:39 PM
Will probably need more information in order to help then
l

lemon-agent-27707

06/08/2021, 3:07 PM
Are you trying to call this code from within your pulumiFunction, or just in the general automation script?
i

icy-jordan-58549

06/09/2021, 9:54 AM
I’ve decided to test it inside general automation script (automation api) and it does work @lemon-agent-27707
but it was not working when I’ve embedded it inside CustomResource
but here, you are using
Copy code
let clientID = azure.config.clientId;
let clientSecret = azure.config.clientSecret;
let tenantID = azure.config.tenantId;
let subscriptionID = azure.config.subscriptionId;
instead of
Copy code
const config = await authorization.getClientConfig();
const token = await authorization.getClientToken();
does it make sense? @bored-oyster-3147 @lemon-agent-27707
b

bored-oyster-3147

06/09/2021, 12:37 PM
AFAIK you don't want to
await
inside a pulumi program. Automation API can do this but you'll see weird behavior doing that using the CLI with a local program I think. What is
authorization
in this context?
yep, I know… I am doing await inside Automation API
btw, in the example below you have await inside regular pulumi program 😉
b

bored-oyster-3147

06/09/2021, 3:29 PM
Actually there is an important distinction to be made. In the examples you linked, you are correct that the functions
getAuthorizationManagementClient
and
getRoleIdByName
each contain a couple `await`s. But it's important to note that when the pulumi program executes them, it does so by piping the resulting
Promise
to a
pulumi.output(...)
call here. So the pulumi program is dealing with asynchronous actions only through
Output<T>
and is not awaiting the
Promise
explicitly.
Also note that in this line it is passing the
Promise<T>
to a
Pulumi.Resource
directly because
Promise<T>
can be implicitly cast to
Input<T>
, again, not being awaited explicitly
But to clarify though, your `await`s are located inside your dynamic provider implementation and not in your pulumi program? Because that should be OK
i

icy-jordan-58549

06/10/2021, 7:21 AM
yeah, it’s located inside dynamicprovider, but currently I’ve decided to not go with that approach. Anyway, thanks for great explanation @bored-oyster-3147
👍 1
I appreciate that