https://pulumi.com logo
#getting-started
Title
# getting-started
d

dry-pilot-49577

04/21/2023, 10:57 PM
I'm running into what I'm pretty sure is a function serialization issue since
dynamic.ResourceProvider
is a ts/js thing specifically. Every attempt to call an API service inside a dynamic resource provider, I reach a dead end because of native code. I tried using a polyfilled
fetch
, then a ponyfilled
fetch
, then
got
, and even
axios
. All end up calling native code eventually, because they eventually hit something like
JSON.parse
or
fetch
. I'm either doing something really dumb (likely), need to pre-bundle & compile my typescript before running
pulumi.*
(ew?), or a third way I've yet to uncover. Open to suggestions, code in ๐Ÿงต
Context: The terraform provider (and pulumi registry item) for MongoDB don't include the Atlas DataAPI application service and dependents, so I'm building that as a set of dynamic resources. Code, Config, and Logs: https://gist.github.com/jakobo/bda66c77da6f9bfd4c0cdd50392f9ce4
g

green-stone-37839

04/21/2023, 11:01 PM
There is a known issue with accessing
pulumi.Config
inside dynamic providers. https://github.com/pulumi/pulumi/issues/4512
My suggestion (same as issue comments) is to pass those needed values as args.
Not saying that's your only issue, but likely one of them.
d

dry-pilot-49577

04/21/2023, 11:05 PM
I can definitely work around that one. Was following a pulumi video. Makes sense that wouldn't serialize well. Will report back. The current pulumi error is below which I'm just stumped on. (edit: code config and logs moved to <https://gist.github.com/jakobo/bda66c77da6f9bfd4c0cdd50392f9ce4>)
Code and error updated to reflect current status. No change in the output. It's definitely at the library level, but if I can't use node-fetch, axios, got, ky, and others I feel rather stuck. Purrl gets around this by making the http calls in Go, but it's very difficult to marshal the bearer token (via
response.apply
through all the resources)
g

green-stone-37839

04/21/2023, 11:18 PM
๐Ÿ˜• it's an odd error message. I can't take a look at the code further right now, but there should be no issue using
axios
or whatever HTTP client you want with a dynamic provider. Thats the whole point!
d

dry-pilot-49577

04/21/2023, 11:27 PM
That's what I thought too ๐Ÿ˜† I suppose the following questions come to mind that might unblock me โ€ข What runtime is the serializer using at execution? My pulumi code is all ts with ES2020+node16 module resolution. It might be getting serialized for node16, and then executing in a different runtime โ€ข Is pulumi's ts-node config somewhere? Searching the repo turned up a lot of hits. I'm running
esm: true
& coupled with the compile targets I might be messing up the internal serialization
b

billowy-army-68599

04/22/2023, 12:09 AM
I would recommend opening a GitHub issue for things in the engine like this if you can summarise it
d

dry-pilot-49577

04/22/2023, 12:11 AM
I'll try. sweaty blob I'm still trying to wrap my own head around what I'm seeing. I will clean up this thread and move everything into a gist so it's easier to read. I've just got massive gaps in my understanding of how serializing works and why node 18/esm would cause it to fail out before even reaching preview.
Traced it to the following GitHub issue, about 1.5 years old. https://github.com/pulumi/pulumi/issues/5294 They're likely to be the same root cause, as dynamic resources make use of the same serialization. It's just really easy to trip on native code. ๐Ÿ˜ž
2 Views