Hi guys. I generate a password with `@pulumi/rando...
# typescript
b
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
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
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
Glad it worked 🙂
b
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
@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
Thanks for sharing this code. This is useful for my usecase of encoding caddyserver basic auth as well