1. Answers
  2. Using Pulumi's 'all' Function to Combine Outputs

How do I use Pulumi's 'all' function to combine outputs?

In this example, we will demonstrate how to use Pulumi’s all function to combine multiple outputs into a single output. This can be particularly useful when you need to aggregate information from multiple resources and use it in subsequent resources or export it from the stack.

We will create two AWS S3 buckets and combine their names using the all function.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create the first S3 bucket
const bucket1 = new aws.s3.Bucket("bucket1");

// Create the second S3 bucket
const bucket2 = new aws.s3.Bucket("bucket2");

// Use the all function to combine the names of the two buckets
const combinedBucketNames = pulumi.all([bucket1.bucket, bucket2.bucket]).apply(([bucket1Name, bucket2Name]) => {
    return `Bucket 1: ${bucket1Name}, Bucket 2: ${bucket2Name}`;
});

// Export the combined bucket names
export const bucketNames = combinedBucketNames;

Key Points:

  • We created two AWS S3 buckets using Pulumi.
  • We used Pulumi’s all function to combine the outputs of the bucket names.
  • The combined bucket names were exported from the stack.

Summary:

In this example, we demonstrated how to use Pulumi’s all function to aggregate outputs from multiple resources. This approach allows you to manage and use combined information efficiently in your Pulumi programs.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up