https://pulumi.com logo
#typescript
Title
# typescript
b

breezy-cricket-40277

12/03/2020, 9:54 AM
Hi guys. I generate a password with
@pulumi/random
and then I have my own method to generate an hash out of it, then
base64
encode to put in a k8s secret. My question is, how can I make sure that my
hash
method is only called if the
RandomPassword
changes?
GenerateHashedPassword
is my method that returns a
string
with the hash.
The problem that I have is that every time I run a
preview
or
up
the
GeneratedHashedPassword
method gets called and generates a different hash.. so all the dependencies that I have on that also get regenerated 😕
Is there any
pulumi
way of handling this, or do I have to change my underlying method to always return the same output given one input?
b

brave-planet-10645

12/03/2020, 10:04 AM
Hi, Here's an example from our docs on how to do what you're asking. The only difference is that the encoding is happening at the point of deploying the secret
b

breezy-cricket-40277

12/03/2020, 10:27 AM
Ah that makes sense. So if the rendering happens at the creation time, given that the
randomPassword
doesn’t change, pulumi doesn’t run my function. Just tried it and it works fine. Thank you @brave-planet-10645 👍
b

brave-planet-10645

12/03/2020, 10:38 AM
Glad it worked 🙂
b

breezy-cricket-40277

12/03/2020, 10:38 AM
Leaving here this code example if anyone runs into the same problem. This is for
traefik
v2 basic auth btw. Then on the secret, I just call this method with the desired
user
. Ofc, can be adapted for multiple users.
b

billowy-army-68599

12/03/2020, 3:46 PM
@breezy-cricket-40277 it doesn't answer your question, but you can also pass
stringData
to a Kubernetes secret (instead of
data
) and the k8s API will base64 encode it: always useful to know
w

wet-soccer-72485

12/03/2020, 10:27 PM
Thanks for sharing this code. This is useful for my usecase of encoding caddyserver basic auth as well
6 Views