Apologies for the re-post but I never got a reply ...
# general
f
Apologies for the re-post but I never got a reply and I'm still interested:
If I do a
pulumi.export
in a file other than
__main__.py
it seems like it gets ignored. I added
<http://pulumi.info|pulumi.info>
statements to ensure that my
pulumi.export
functions are being called and they are. I also logged one of the values I'm exporting via
value.apply(lambda x: <http://pulumi.info|pulumi.info>(x))
and it's a valid value. Why can't I export it from a function in another file?
m
I think I've seen this before and been confused by it also. I'm not sure why technically, but the call to export does need to happen outside of
apply
. (The call can be in another file, too, just not inside an
apply
.) I'll see if I can find a good explanation for why this is, and get it added to the docs also, but in the meantime, this may help: https://gist.github.com/cnunciato/93dfba1036b7503270eefa498d122299
f
Ah! I didn't realize mine was happening inside an
apply
, but it is. I have to do a stack reference to get some outputs from another stack and a stack reference is an
Output
so I resolve the stack reference and then
apply
that into a fairly large function that does all the other work. And that gist shows a good solution! Thanks.
m
You bet! Thanks for calling it out too -- good thing to get into the docs for sure.
f
Hmmm... The workaround works but has limitations. If you want to export just a single value from the function you called via
apply
it works great. In my case I have several values to export so I had my function return a
Dict[str, Any]
mapping the export name to the value I want exported. So when you call
result = some_output.apply(some_function)
result
is now an
Output[Dict[str, Any]]
which means you can't iterate over it like
for k, v in result.items
to export each item individually. You can export the entire Dict however. But, in my case some of the values in
result
are secrets and some are not. But due to how Pulumi works that means the entire
Dict
is a secret so I can't see my outputs without
pulumi stack output --show-secrets
. Not the end of the world, but the ability to actually export from an
apply
would make this easier.