Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

RandomPet

The resource random.RandomPet generates random pet names that are intended to be used as unique identifiers for other resources.

This resource can be used in conjunction with resources that have the create_before_destroy lifecycle flag set, to avoid conflicts with unique names during the brief period where both the old and new resources exist concurrently.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;
using Random = Pulumi.Random;

class MyStack : Stack
{
    public MyStack()
    {
        var serverRandomPet = new Random.RandomPet("serverRandomPet", new Random.RandomPetArgs
        {
            Keepers = 
            {
                { "ami_id", @var.Ami_id },
            },
        });
        var serverInstance = new Aws.Ec2.Instance("serverInstance", new Aws.Ec2.InstanceArgs
        {
            Ami = serverRandomPet.Keepers.Apply(keepers => keepers.AmiId),
            Tags = 
            {
                { "Name", serverRandomPet.Id.Apply(id => $"web-server-{id}") },
            },
        });
    }

}

Coming soon!

import pulumi
import pulumi_aws as aws
import pulumi_random as random

server_random_pet = random.RandomPet("serverRandomPet", keepers={
    "ami_id": var["ami_id"],
})
server_instance = aws.ec2.Instance("serverInstance",
    ami=server_random_pet.keepers["amiId"],
    tags={
        "Name": server_random_pet.id.apply(lambda id: f"web-server-{id}"),
    })
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as random from "@pulumi/random";

const serverRandomPet = new random.RandomPet("server", {
    keepers: {
        // Generate a new pet name each time we switch to a new AMI id
        ami_id: var_ami_id,
    },
});
const serverInstance = new aws.ec2.Instance("server", {
    ami: serverRandomPet.keepers.apply(keepers => keepers.amiId),
    tags: {
        Name: pulumi.interpolate`web-server-${serverRandomPet.id}`,
    },
});

Create a RandomPet Resource

new RandomPet(name: string, args?: RandomPetArgs, opts?: CustomResourceOptions);
def RandomPet(resource_name: str, opts: Optional[ResourceOptions] = None, keepers: Optional[Mapping[str, Any]] = None, length: Optional[int] = None, prefix: Optional[str] = None, separator: Optional[str] = None)
func NewRandomPet(ctx *Context, name string, args *RandomPetArgs, opts ...ResourceOption) (*RandomPet, error)
public RandomPet(string name, RandomPetArgs? args = null, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RandomPetArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args RandomPetArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RandomPetArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

RandomPet Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The RandomPet resource accepts the following input properties:

Keepers Dictionary<string, object>

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Length int

The length (in words) of the pet name.

Prefix string

A string to prefix the name with.

Separator string

The character to separate words in the pet name.

Keepers map[string]interface{}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Length int

The length (in words) of the pet name.

Prefix string

A string to prefix the name with.

Separator string

The character to separate words in the pet name.

keepers {[key: string]: any}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

length number

The length (in words) of the pet name.

prefix string

A string to prefix the name with.

separator string

The character to separate words in the pet name.

keepers Mapping[str, Any]

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

length int

The length (in words) of the pet name.

prefix str

A string to prefix the name with.

separator str

The character to separate words in the pet name.

Outputs

All input properties are implicitly available as output properties. Additionally, the RandomPet resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing RandomPet Resource

Get an existing RandomPet resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: RandomPetState, opts?: CustomResourceOptions): RandomPet
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, keepers: Optional[Mapping[str, Any]] = None, length: Optional[int] = None, prefix: Optional[str] = None, separator: Optional[str] = None) -> RandomPet
func GetRandomPet(ctx *Context, name string, id IDInput, state *RandomPetState, opts ...ResourceOption) (*RandomPet, error)
public static RandomPet Get(string name, Input<string> id, RandomPetState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

Keepers Dictionary<string, object>

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Length int

The length (in words) of the pet name.

Prefix string

A string to prefix the name with.

Separator string

The character to separate words in the pet name.

Keepers map[string]interface{}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Length int

The length (in words) of the pet name.

Prefix string

A string to prefix the name with.

Separator string

The character to separate words in the pet name.

keepers {[key: string]: any}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

length number

The length (in words) of the pet name.

prefix string

A string to prefix the name with.

separator string

The character to separate words in the pet name.

keepers Mapping[str, Any]

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

length int

The length (in words) of the pet name.

prefix str

A string to prefix the name with.

separator str

The character to separate words in the pet name.

Package Details

Repository
https://github.com/pulumi/pulumi-random
License
Apache-2.0
Notes
This Pulumi package is based on the random Terraform Provider.