Hey guys! I need to use a secret inside a template...
# python
i
Hey guys! I need to use a secret inside a template string. For example:
Copy code
my_template = "my secret: {my_secret}"
my_secret = config.require_secret('my_secret')
foo = my_template.format(my_secret=my_secret)
This will result in the following output:
Copy code
my secret: <pulumi.output.Output object at 0x7f02baf74b80>
I tried using apply, and even Output.all, like follows:
Copy code
foo = my_template.format(my_secret=my_secret.apply(lambda current_secret: current_secret))
But it will give me the same result. What am I missing here?
b
@incalculable-whale-36468 your code is back to front, you need to do
my_template.format
inside the apply. something like:
Copy code
my_secret.apply(lambda current_secret: my_template.format(my_secret=my_template.format(current_secret)
i
I have tried that, but it did not work, I still got the output object. However, I did find a solution. This is the only way that worked:
Copy code
foo = Output.all(
    my_secret=my_secret
).apply(
    lambda output_args: my_template.format(my_secret=output_args['my_secret'])
)
I have no idea why apply would behave differently
b
@incalculable-whale-36468 what was your code before the
Output.all
?
f
Try to get it with
my_secret = config.require('my_secret')
. => use "require" instead of "require_secret"