https://pulumi.com logo
e

early-musician-41645

07/24/2019, 7:12 PM
b

broad-football-5123

07/24/2019, 7:16 PM
Have you tried adding
.get()
or does that throw an error?
m

modern-bear-85657

07/24/2019, 7:29 PM
.get()
errors in preview and instructs to use
.apply()
instead. It’s a hassle. I saw a thread yesterday where they’re trying to address this, though.
w

white-balloon-205

07/24/2019, 7:40 PM
I replied to the question in the thread itself above.
e

early-musician-41645

07/24/2019, 8:06 PM
Is there a definitive way to get a string from a
pulumi.Output<string>
?
I can
console.log
the output, but I can not do something like:
Copy code
let myString: string = myPulumiOutput.apply(val => return val);
In short - the problem I'm trying to solve is: 1) create a keypair 2) store the keypair as a secretString in secretsmanager in AWS 3) use the publicKey as a string for other purposes later on
I believe the secretString for secrets requires a
string
, hence I'm doing a
JSON.stringify
on the secretString:
Copy code
83     let secretString =  {
     84       publicKey: publicKey,
     85       privateKey: privateKey
     86     };

     96     const secretVersion = new aws.secretsmanager.SecretVersion("v1", {
     97       secretId: secret.id,
     98       secretString: JSON.stringify(secretString),
     99     });
I don't see other examples around this that allow me to shove a
pulumi.Output<string>
as above into the secretString directly. Am I missing some step or info? @white-balloon-205?
w

white-balloon-205

07/24/2019, 8:15 PM
Is there a definitive way to get a string from a
pulumi.Output<string>
?
It is not possible to turn an
Output<string>
into a
string
because an
Output<string>
represents a value that may or may not be known. The primary way to see the value inside is to use
.apply(v => ...)
and write whatever logic you want to happen if/when the value is available inside that callback.
I believe the secretString for secrets requires a
string
No - it expects an
Input<string>
, which can be either a
string
or an
Output<string>
.
This section of the documentation discusses these concepts in some detail: https://www.pulumi.com/docs/reference/programming-model/#outputs
e

early-musician-41645

07/24/2019, 8:18 PM
Thanks, I'll take some time to dig through and find the right flow for these!
I've made progress! After porting everything to use
pulumi.Output
things are working... sort of. Last hurdle is this:
Copy code
44   let secretString = pulumi.output(`{"publicKey":"${publicKey}", "privateKey":"${privateKey}"}`);
     45
     46   const secret = new aws.secretsmanager.Secret(secretName, {
     47     name: secretName,
     48     description: "SSH keypair for worker nodes in an EKS cluster",
     49   });
     50
     51   const secretVersion = new aws.secretsmanager.SecretVersion("v1", {
     52     secretId: secret.id,
     53     secretString: secretString,
     54   });
The secret is created, however, the actual value of the secretString is:
Copy code
{"publicKey":"Calling [toString] on an [Output<T>] is not supported.

To get the value of an Output<T> as an Output<string> consider either:
1: o.apply(v => `prefix${v}suffix`)
2: pulumi.interpolate `prefix${v}suffix`

See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of @pulumi/pulumi.", "privateKey":"Calling [toString] on an [Output<T>] is not supported.

To get the value of an Output<T> as an Output<string> consider either:
1: o.apply(v => `prefix${v}suffix`)
2: pulumi.interpolate `prefix${v}suffix`

See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of @pulumi/pulumi."}
I'm trying to form a
secretString
out of `pulumi.Output`s formatted into json and it's not working. How can I create a
string
or
Output<string>
from a combination of `string`s and `Output<string>`s for use in the
secretString
?
publicKey
and
privateKey
are both
Output<string>
oh, maybe I just spotted it:
pulumi.all
??
testing...
Finally figure it out!!
Copy code
42 // Create an AWS secret resource
     43 function createSecret(publicKey: pulumi.Output<string>, privateKey: pulumi.Output<string>) {
     44   let secretString = pulumi.all([publicKey, privateKey]).apply(([pub, priv]) => { return JSON.stringify({ publicKey: pub, privateKey: priv }) });
     45
     46   const secret = new aws.secretsmanager.Secret(secretName, {
     47     name: secretName,
     48     description: "SSH keypair for worker nodes in an EKS cluster",
     49   });
     50
     51   secretString.apply(s => {
     52     const secretVersion = new aws.secretsmanager.SecretVersion("v1", {
     53       secretId: secret.id,
     54       secretString: secretString,
     55     });
     56   });
     57 }
woohoo 2
that is one super complex piece of code syntax :0
w

white-balloon-205

07/24/2019, 9:54 PM
Great that you got this working. That is indeed the expected way to do this currently, though we continue to look for ways to simplify some common cases like this.