1. How to reference auto-named Pulumi resources in tests?


    Sure, while testing Pulumi programs, you can use the getOutput method for referencing auto-named Pulumi resources.

    Let's say you have a bucket resource with an autogenerated name:

    import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; const bucket = new aws.s3.Bucket("my-bucket");

    To reference this S3 bucket in your tests, obtain the bucket name using getOutput:

    const bucketName = pulumi .output(bucket.bucket) // `bucket` is the auto-named property .apply(bucketName => `bucketName=${bucketName}`);

    The apply function is used here to interact directly with the output's value (the bucket name).

    The getOutput method returns a value of type Output, which represents a value that is computed asynchronously (i.e., an output property value or a resource output property value computed during a Pulumi preview or update).

    Keep in mind that this isn't used during the unit testing phrase but is helpful during integration testing where the actual resources are being used.

    For more details, refer to the official Pulumi testing guide.