How can i tell if a given Output is secret? <https...
# python
h
How can i tell if a given Output is secret? https://www.pulumi.com/registry/packages/azure/api-docs/containerservice/group/#groupcontainer has
environment_variables
and
secure_environment_variables
and I would like to automatically sort inputs into them based on if they're secrets
I think
Output.from_input(output.is_secret())
will let me get the secret value
so from that, it would be straight-forward to write a function that maps
dict[str, Input[str]]
to
Output[tuple[dict[str, str], dict[str, str]]]
based on if they're secrets
the trick is that i need to not accidentally mark the non-secret bucket as secret
a
The challenge with
.is_secret()
is that it's an
Awaitable[bool]
so it will just return a Future which can't be evaluated synchronously – and is a bit misconceiving as doing something like this will always be evaluated on non-secrets:
Copy code
if none_secret_output.is_secret():
    print("This will always evaluate")
So the solution is to do the sorting inside an async function which can either be run explicitly in the Pulumi managed asyncio event loop or simply be passed to
pulumi.Output.from_input
which will take care of that for you. See a working example: https://gist.github.com/olafurnielsen/ef143c50e1c5e1c57a9f0d187102cbf8
Screenshot 2024-04-06 at 00.56.02.png
h
ok, I can work with that