rhythmic-actor-14991
06/29/2021, 11:04 AMCalling [toJSON] on an [Output<T>] is not supported.
To get the value of an Output as a JSON value or JSON string consider either:
1: o.apply(v => v.toJSON())
2: o.apply(v => JSON.stringify(v))
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of @pulumi/pulumi
``````const dbpassword = new random.RandomPassword(`${userName}-password`, {
length: 16,
special: true,
overrideSpecial: `_%@`,
});
const textMessage = dbpassword.result.apply(s => `{username: ${userName}, password: ${s}}`);
const passwordString = dbpassword.result.apply(v => `password: ${v}`);
const content = dbpassword.result.apply( (v) => `
username: ${userName}
password: "${v}"
`);
console.log(passwordString);
sendMessageToFeishu(webhookURL, {
msg_type: "post",
content: {
post: {
zh_cn: {
title: "MetaDB Password",
content: [[
{ tag: "text", text: content },
// { tag: "text", text: `username: ${userName} ; ` },
{ tag: "text", text: passwordString },
]],
},
},
},
});
gorgeous-country-43026
06/29/2021, 11:07 AMnew random.RandomPassword
returns an Output<string>
. That's not the same as plain stringOutput
has a method called apply
which also returns an Output
Output
you need to do something like this:const someOutput = new random.RandomPassword(.....);
someOutput.apply(password => console.log('Password is:", password));
apply
. Pulumi will call that function after the Output
has realized it's valuepulumi.all
function to wait for all of them at the same time. Basically you'll do this:
const dbPassword = new random.RandomPassword(...);
const apiPassword = new random.RandomPassword(...);
pulumi.all({
db: dbPassword,
apiPassword
}).apply({db, apiPassword} => {
// This is called *only* after *both* Outputs are realized
console.log("DB password:", db);
console.log("API password:", apiPassword);
});
billowy-army-68599
06/29/2021, 11:22 AM@
individual people asking for help
there's a blog post here explaining why you can't get this value outside of an apply: https://www.leebriggs.co.uk/blog/2021/05/09/pulumi-apply.html
Thanks for helping out @gorgeous-country-43026 - much appreciatedrhythmic-actor-14991
06/29/2021, 1:57 PMapply
, but still get no effect..{ tag: "text", text: dbpassword.result.apply(result => `Password is:, ${result}`) },
acceptable-army-69872
06/29/2021, 2:42 PMconst someOutput = new random.RandomPassword(.....);
// out here someOutput is an output and you can't get the value
someOutput.apply( => {
// in here someOutput is a string
console.log('Password is:", someOutput);
// you can use the value like this
sendMessageToFeishu(webhookURL, {
msg_type: "post",
content: {
post: {
zh_cn: {
title: "MetaDB Password",
content: [[
{ tag: "text", text: content },
{ tag: "text", text: someOutput },
]],
},
},
},
});
});
rhythmic-actor-14991
06/29/2021, 2:53 PM