1. Packages
  2. Random
  3. API Docs
  4. RandomPet
random v4.16.0 published on Wednesday, Feb 28, 2024 by Pulumi

random.RandomPet

Explore with Pulumi AI

random logo
random v4.16.0 published on Wednesday, Feb 28, 2024 by Pulumi

    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 System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    using Random = Pulumi.Random;
    
    return await Deployment.RunAsync(() => 
    {
        // The following example shows how to generate a unique pet name
        // for an AWS EC2 instance that changes each time a new AMI id is
        // selected.
        var serverRandomPet = new Random.RandomPet("serverRandomPet", new()
        {
            Keepers = 
            {
                { "ami_id", @var.Ami_id },
            },
        });
    
        var serverInstance = new Aws.Ec2.Instance("serverInstance", new()
        {
            Tags = 
            {
                { "Name", serverRandomPet.Id.Apply(id => $"web-server-{id}") },
            },
            Ami = serverRandomPet.Keepers.Apply(keepers => keepers?.AmiId),
        });
    
        // ... (other aws_instance arguments) ...
    });
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ec2"
    	"github.com/pulumi/pulumi-random/sdk/v4/go/random"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		// The following example shows how to generate a unique pet name
    		// for an AWS EC2 instance that changes each time a new AMI id is
    		// selected.
    		serverRandomPet, err := random.NewRandomPet(ctx, "serverRandomPet", &random.RandomPetArgs{
    			Keepers: pulumi.StringMap{
    				"ami_id": pulumi.Any(_var.Ami_id),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2.NewInstance(ctx, "serverInstance", &ec2.InstanceArgs{
    			Tags: pulumi.StringMap{
    				"Name": serverRandomPet.ID().ApplyT(func(id string) (string, error) {
    					return fmt.Sprintf("web-server-%v", id), nil
    				}).(pulumi.StringOutput),
    			},
    			Ami: serverRandomPet.Keepers.ApplyT(func(keepers interface{}) (*string, error) {
    				return &keepers.AmiId, nil
    			}).(pulumi.StringPtrOutput),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.random.RandomPet;
    import com.pulumi.random.RandomPetArgs;
    import com.pulumi.aws.ec2.Instance;
    import com.pulumi.aws.ec2.InstanceArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var serverRandomPet = new RandomPet("serverRandomPet", RandomPetArgs.builder()        
                .keepers(Map.of("ami_id", var_.ami_id()))
                .build());
    
            var serverInstance = new Instance("serverInstance", InstanceArgs.builder()        
                .tags(Map.of("Name", serverRandomPet.id().applyValue(id -> String.format("web-server-%s", id))))
                .ami(serverRandomPet.keepers().applyValue(keepers -> keepers.amiId()))
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    import pulumi_random as random
    
    # The following example shows how to generate a unique pet name
    # for an AWS EC2 instance that changes each time a new AMI id is
    # selected.
    server_random_pet = random.RandomPet("serverRandomPet", keepers={
        "ami_id": var["ami_id"],
    })
    server_instance = aws.ec2.Instance("serverInstance",
        tags={
            "Name": server_random_pet.id.apply(lambda id: f"web-server-{id}"),
        },
        ami=server_random_pet.keepers["amiId"])
    # ... (other aws_instance arguments) ...
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as random from "@pulumi/random";
    
    // The following example shows how to generate a unique pet name
    // for an AWS EC2 instance that changes each time a new AMI id is
    // selected.
    const serverRandomPet = new random.RandomPet("serverRandomPet", {keepers: {
        ami_id: _var.ami_id,
    }});
    const serverInstance = new aws.ec2.Instance("serverInstance", {
        tags: {
            Name: pulumi.interpolate`web-server-${serverRandomPet.id}`,
        },
        ami: serverRandomPet.keepers.apply(keepers => keepers?.amiId),
    });
    // ... (other aws_instance arguments) ...
    
    resources:
      # The following example shows how to generate a unique pet name
      # for an AWS EC2 instance that changes each time a new AMI id is
      # selected.
      serverRandomPet:
        type: random:RandomPet
        properties:
          keepers:
            ami_id: ${var.ami_id}
      serverInstance:
        type: aws:ec2:Instance
        properties:
          tags:
            Name: web-server-${serverRandomPet.id}
          # Read the AMI id "through" the random_pet resource to ensure that
          #   # both will change together.
          ami: ${serverRandomPet.keepers.amiId}
    

    Create RandomPet Resource

    new RandomPet(name: string, args?: RandomPetArgs, opts?: CustomResourceOptions);
    @overload
    def RandomPet(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  keepers: Optional[Mapping[str, str]] = None,
                  length: Optional[int] = None,
                  prefix: Optional[str] = None,
                  separator: Optional[str] = None)
    @overload
    def RandomPet(resource_name: str,
                  args: Optional[RandomPetArgs] = None,
                  opts: Optional[ResourceOptions] = None)
    func NewRandomPet(ctx *Context, name string, args *RandomPetArgs, opts ...ResourceOption) (*RandomPet, error)
    public RandomPet(string name, RandomPetArgs? args = null, CustomResourceOptions? opts = null)
    public RandomPet(String name, RandomPetArgs args)
    public RandomPet(String name, RandomPetArgs args, CustomResourceOptions options)
    
    type: random:RandomPet
    properties: # The arguments to resource properties.
    options: # 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.
    resource_name str
    The unique name of the resource.
    args RandomPetArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control 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.
    name String
    The unique name of the resource.
    args RandomPetArgs
    The arguments to resource properties.
    options 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 Architecture and Concepts docs.

    Inputs

    The RandomPet resource accepts the following input properties:

    Keepers Dictionary<string, string>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The length (in words) of the pet name. Defaults to 2
    Prefix string
    A string to prefix the name with.
    Separator string
    The character to separate words in the pet name. Defaults to "-"
    Keepers map[string]string
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The length (in words) of the pet name. Defaults to 2
    Prefix string
    A string to prefix the name with.
    Separator string
    The character to separate words in the pet name. Defaults to "-"
    keepers Map<String,String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Integer
    The length (in words) of the pet name. Defaults to 2
    prefix String
    A string to prefix the name with.
    separator String
    The character to separate words in the pet name. Defaults to "-"
    keepers {[key: string]: string}
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length number
    The length (in words) of the pet name. Defaults to 2
    prefix string
    A string to prefix the name with.
    separator string
    The character to separate words in the pet name. Defaults to "-"
    keepers Mapping[str, str]
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length int
    The length (in words) of the pet name. Defaults to 2
    prefix str
    A string to prefix the name with.
    separator str
    The character to separate words in the pet name. Defaults to "-"
    keepers Map<String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Number
    The length (in words) of the pet name. Defaults to 2
    prefix String
    A string to prefix the name with.
    separator String
    The character to separate words in the pet name. Defaults to "-"

    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 string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up 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, str]] = 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)
    public static RandomPet get(String name, Output<String> id, RandomPetState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    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.
    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, string>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The length (in words) of the pet name. Defaults to 2
    Prefix string
    A string to prefix the name with.
    Separator string
    The character to separate words in the pet name. Defaults to "-"
    Keepers map[string]string
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The length (in words) of the pet name. Defaults to 2
    Prefix string
    A string to prefix the name with.
    Separator string
    The character to separate words in the pet name. Defaults to "-"
    keepers Map<String,String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Integer
    The length (in words) of the pet name. Defaults to 2
    prefix String
    A string to prefix the name with.
    separator String
    The character to separate words in the pet name. Defaults to "-"
    keepers {[key: string]: string}
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length number
    The length (in words) of the pet name. Defaults to 2
    prefix string
    A string to prefix the name with.
    separator string
    The character to separate words in the pet name. Defaults to "-"
    keepers Mapping[str, str]
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length int
    The length (in words) of the pet name. Defaults to 2
    prefix str
    A string to prefix the name with.
    separator str
    The character to separate words in the pet name. Defaults to "-"
    keepers Map<String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Number
    The length (in words) of the pet name. Defaults to 2
    prefix String
    A string to prefix the name with.
    separator String
    The character to separate words in the pet name. Defaults to "-"

    Package Details

    Repository
    random pulumi/pulumi-random
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the random Terraform Provider.
    random logo
    random v4.16.0 published on Wednesday, Feb 28, 2024 by Pulumi