What is the best/recommended way to compute a simp...
# python
What is the best/recommended way to compute a simple sha256 hash of a dictionary whose keys a a type
, and their values could be
that's something you do not want to do, unless you can afford doing this in the scope of
I think something like:
Copy code
Output.json_dumps(dictionary, sort_keys=True).apply(lambda json: sha256(json.encode('utf-8')).hexdigest())
I'm fine with the expense, but it looks like the Output.json_dumps() creates a non-deterministic value.. which is weird since the dictionary's resultant values haven't changed..
the actual outcome results in the same sha256, but Pulumi keeps 'detecting' change where I'm using the resulting output of json_dumps (since it's just an Output[str])
Have you set "sort_keys=True"? I'd think that should result in deterministic results. Can you share a copy of what the engine thinks the diff is?
I did, I just realized what it was... I was trying to use the output directly on something instead of running yet another apply against it, so it was returning with the "You can't run str On an Output[T]" bogus... I really think that should raise an exception... 🙂 not create surprise rubbish strings that aren't truly the Output value.
It says it might start throwing in the future... hopefully that happens. 😄 Anyway, works great @echoing-dinner-19531, thanks! I wasn't even aware Output had its own json_dumps; saves me from having to do all that work myself.