https://pulumi.com logo
Title
i

incalculable-whale-36468

03/28/2022, 9:24 PM
Hey guys! I need to use a secret inside a template string. For example:
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:
my secret: <pulumi.output.Output object at 0x7f02baf74b80>
I tried using apply, and even Output.all, like follows:
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

billowy-army-68599

03/28/2022, 9:33 PM
@incalculable-whale-36468 your code is back to front, you need to do
my_template.format
inside the apply. something like:
my_secret.apply(lambda current_secret: my_template.format(my_secret=my_template.format(current_secret)
i

incalculable-whale-36468

03/29/2022, 10:11 AM
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:
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

billowy-army-68599

03/29/2022, 1:37 PM
@incalculable-whale-36468 what was your code before the
Output.all
?
f

few-diamond-68626

06/20/2022, 2:41 PM
Try to get it with
my_secret = config.require('my_secret')
. => use "require" instead of "require_secret"