How do I configure a random UUID with Pulumi?
This guide will demonstrate how to generate a random UUID using Pulumi. A UUID (Universally Unique Identifier) is useful for creating unique resource names or identifiers in your infrastructure. We will use the random.RandomUuid
resource from the random
provider to achieve this.
Below is the Pulumi program written in TypeScript that configures a random UUID:
import * as pulumi from "@pulumi/pulumi";
import * as random from "@pulumi/random";
// Generate a random UUID
const randomUuid = new random.RandomUuid("exampleUuid");
// Export the generated UUID
export const uuid = randomUuid.result;
Key Points
- Pulumi and Random Provider: We import the necessary Pulumi and random provider modules.
- Random UUID Resource: We create a new
RandomUuid
resource namedexampleUuid
. - Exporting the UUID: We export the generated UUID so that it can be used elsewhere in our Pulumi stack.
Summary
In this guide, we demonstrated how to generate a random UUID using Pulumi. We used the random.RandomUuid
resource from the random
provider to create a unique identifier and exported it for use in other parts of our infrastructure. This approach ensures that resource names or identifiers are unique, avoiding potential conflicts.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.