I would like to serialize the `exports` from `pulu...
# general
c
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
Maybe the section on Outputs will be helpful here https://pulumi.io/reference/programming-model.html#outputs
c
It didn’t do that
@gorgeous-egg-16927 Would you be able to help with that?
b
Copy code
pulumi stack output --json > output.json
https://pulumi.io/reference/programming-model.html#stack-outputs
c
I want to it using the API
I don’t want a command line
c
@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
@creamy-potato-29402 How do I get the output within the pulumi code?
I don’t want to use the command line
c
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
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
@chilly-photographer-60932 that does not look like the examples in the docs, right?
c
Yes, I want a way to serialize. Let me know how I can do that.
Is there an API for pulumi stack output?
c
@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.