https://pulumi.com logo
c

chilly-photographer-60932

02/21/2019, 5:05 PM
I would like to serialize the
exports
from
pulumi
object especially string and write it to a bucket for other API’s to consume.
Copy code
{ IstioIngressIPAddress:
       Output {
         __pulumiOutput: true,
         isKnown: Promise { <pending> },
         resources: [Function],
         promise: [Function],
         apply: [Function],
         get: [Function] },
      IdentityIngressIPAddress:
       Output {
         __pulumiOutput: true,
         isKnown: Promise { <pending> },
         resources: [Function],
         promise: [Function],
         apply: [Function],
         get: [Function] },
      ExternalNATIPAddress: '[object Object]' }
I am trying to serialize using
JSON.stringify
. How do I get a proper serialized json object?
b

brainy-magician-83981

02/21/2019, 5:49 PM
Maybe the section on Outputs will be helpful here https://pulumi.io/reference/programming-model.html#outputs
c

chilly-photographer-60932

02/21/2019, 6:31 PM
It didn’t do that
@gorgeous-egg-16927 Would you be able to help with that?
b

brainy-magician-83981

02/21/2019, 6:53 PM
Copy code
pulumi stack output --json > output.json
https://pulumi.io/reference/programming-model.html#stack-outputs
c

chilly-photographer-60932

02/21/2019, 6:58 PM
I want to it using the API
I don’t want a command line
c

creamy-potato-29402

02/21/2019, 7:38 PM
@chilly-photographer-60932 the documentation above tells you more or less how to do this.
It is very hard in general to understand your errors when you don’t tell us what you’ve written or what you did. 🙂
c

chilly-photographer-60932

02/21/2019, 7:39 PM
@creamy-potato-29402 How do I get the output within the pulumi code?
I don’t want to use the command line
c

creamy-potato-29402

02/21/2019, 7:39 PM
Again, it is hard to know where you went wrong when you don’t tell us what you’ve written or tried.
The docs above do cover how to do this programmatically.
If you did something different from that, but don’t tell us what, we are probably not going to be able to help you.
c

chilly-photographer-60932

02/21/2019, 7:41 PM
I understand
Let me share the code
Copy code
import * as pulumi from '@pulumi/pulumi';
import * as gcp from '@pulumi/gcp';

// Create a GCP resource (Storage Bucket)
const bucket = new gcp.storage.Bucket('my-bucket');

// Export the DNS name of the bucket
export const bucketName = bucket.url;

console.log(pulumi.output(bucket).apply(s => s));
Here is the sample code. I want a properly serialized output of
bucket
Instead of it being
Copy code
pulumi:pulumi:Stack (testingpulumioutput-dev):
    Output {
      __pulumiOutput: true,
      isKnown: Promise { <pending> },
      resources: [Function],
      promise: [Function],
      apply: [Function],
      get: [Function] }
c

creamy-potato-29402

02/21/2019, 8:41 PM
@chilly-photographer-60932 that does not look like the examples in the docs, right?
c

chilly-photographer-60932

02/21/2019, 8:45 PM
Yes, I want a way to serialize. Let me know how I can do that.
Is there an API for pulumi stack output?
c

creamy-potato-29402

02/22/2019, 3:38 AM
@chilly-photographer-60932 , in your code above you're already doing this.
@chilly-photographer-60932 Right? What does this code do? And how would it change if you omitted the
.url
?
Copy code
export const bucketName = bucket.url;
Compare that with what you’ve written here:
Copy code
console.log(pulumi.output(bucket).apply(s => s));
pulumi.output
returns an
Output<Bucket>
, which is what is getting printed above. That is not what you want, right?
Whereas the argument
s
is of type
Bucket
, right?
in
apply(s => s)
So if you want to print a
Bucket
type, where should you put the
console.log
Let’s think it through together.