How to pass Pulumi output as input to another resource?TypeScript
You can pass an output of one resource as an input to another using the
applymethod of the
Outputclass in Pulumi. The
applyfunction is used to transform the data of
Output<U>, making it easy to chain operations off of resources that do not have their values available until after the resource is created.
Let's consider a scenario where you want to create an AWS S3 bucket and then an AWS S3 bucket policy that refers to this bucket.
Here is a simple example:
In this code:
bucket.arn.applyis called on the ARN of the bucket. This ARN is not yet known and will only be known once the bucket is created. However, it is wrapped with
applyfunction allows us to provide a callback (a function) which takes the bucket's ARN as input.
- This callback creates a new
aws.s3.BucketPolicyusing this ARN.
You can see more about using outputs in our official documentation.