https://pulumi.com logo
#general
Title
# general
s

swift-oxygen-28374

04/11/2020, 6:54 PM
Hi Everyone, I'm new to Pulumi. Using a full-fledged programming language to define infrastructure as code is great! I'm doing a poc to get familiar with Pulumi. Below is a snippet that creates snapshot of an ebs volume and prints snapshot id. Got an error when trying to print snapshot id. Any pointers on how to change this?
Copy code
const snapshot = new aws.ebs.Snapshot("Unattached volume", {
            tags: {
                Name: ebsVolume.tags["Name"],
                Cleanup: "true",
                Who: "satish",
                When: "04102020"
            },
            volumeId: volumeId,
        });

        // const snapshotId = <http://snapshot.id|snapshot.id>.apply(s => `${s}`);
        const snapshotId = pulumi.interpolate `prefix${<http://snapshot.id|snapshot.id>}suffix`

        console.log("Created snapshot " + snapshotId + " for volume " + volumeId);
Copy code
Created snapshot 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.
w

white-balloon-205

04/11/2020, 7:59 PM
Copy code
const str = pulumi.interpolate`Created snapshot  ${<http://snapshot.id|snapshot.id>} for volume ${<http://volume.id|volume.id>}`;
str.apply(console.log);
The result of interpolate is still an output, and if you want to do something with an output you use apply. In this case, you want to log it, so you can pass console.log to the apply. That will log it when the value becomes available (nothing will get logged during an initial preview when these values are not yet known).
🙇‍♂️ 1
s

swift-oxygen-28374

04/11/2020, 8:38 PM
This worked. Thank you! `snapshot.id.apply(id => console.log(
Created snapshot ${id} for volume ${volumeId}
));`