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

boundless-angle-56560

05/05/2021, 3:40 PM
Hi, I am getting following error, is this a bug or am I missing something ?
error: Exception calling application: Object of type Unknown is not JSON serializable
The code I have is this:
The initial pulumi up successfully provisions everything but when I introduce a change into user_data1 string, the second pulumi up run fails with that error
looks like pumuli has some trouble diffing stuff when the apply callback is used
g

gorgeous-minister-41131

05/05/2021, 6:25 PM
I believe you have to base64 encode the user data inside of the callback like
Copy code
user_data_rendered_bytes = user_data_rendered.encode("utf-8")
            user_data_rendered_b64 = base64.b64encode(user_data_rendered_bytes).decode(
                "utf-8"
            )
so in your example, assuming you imported base64 lib somewhere in scope, you can do that
lambda x: base64.b64encode(user_data1.format(x).encode("utf-8"))
actually nevermind, I was looking at the LaunchTemplate resource and it needs pre-encoded user_data, the Instance() resource is supposed to do that for you. However, it might be tripping up because it's an Output[t]
b

boundless-angle-56560

05/05/2021, 7:29 PM
I probably found an error and it seems it was related to something else. Sorry for confusion
g

gorgeous-minister-41131

05/06/2021, 7:02 PM
No worries. I've had that happen a lot. Mind sharing what it ended up being if it's not too complicated?
b

boundless-angle-56560

05/06/2021, 7:12 PM
I was passing that instance into my own dynamic provider. There in the diff function I was serializing inputs naively to json for comparison purposes and it failed because it tried to serialize Unknow type (from input that hasn't been resolved yet at that phase)
g

gorgeous-minister-41131

05/06/2021, 10:31 PM
aye! makes sense. Yeah the promises/futures and the Output/Input stuff still gets me a lot. I don't have a super strong async programming background so I get stuck on that stuff. I definitely found patterns when pulumi spits back errors like that, gives me a
<pulumi.Output at 0xabcdefgs>
string or refers to "Unknown" type that it's probably an issue in not doing the right callback first.
b

boundless-angle-56560

05/11/2021, 1:10 PM
I understand the Output/Input quite well I think and it makes sense to me. In this case I was just doing a silly thing (mostly because I copy pasted the diff code from somewhere else 😁)
3 Views