1. Packages
  2. Random Provider
  3. API Docs
  4. RandomPet
random v4.16.7 published on Wednesday, Oct 16, 2024 by Pulumi

random.RandomPet

Explore with Pulumi AI

random logo
random v4.16.7 published on Wednesday, Oct 16, 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

    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 server = new random.RandomPet("server", {keepers: {
        ami_id: amiId,
    }});
    const serverInstance = new aws.ec2.Instance("server", {
        tags: {
            Name: pulumi.interpolate`web-server-${server.id}`,
        },
        ami: server.keepers.apply(keepers => keepers?.amiId),
    });
    
    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.RandomPet("server", keepers={
        "ami_id": ami_id,
    })
    server_instance = aws.ec2.Instance("server",
        tags={
            "Name": server.id.apply(lambda id: f"web-server-{id}"),
        },
        ami=server.keepers["amiId"])
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-aws/sdk/v6/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.
    		server, err := random.NewRandomPet(ctx, "server", &random.RandomPetArgs{
    			Keepers: pulumi.StringMap{
    				"ami_id": pulumi.Any(amiId),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2.NewInstance(ctx, "server", &ec2.InstanceArgs{
    			Tags: pulumi.StringMap{
    				"Name": server.ID().ApplyT(func(id string) (string, error) {
    					return fmt.Sprintf("web-server-%v", id), nil
    				}).(pulumi.StringOutput),
    			},
    			Ami: pulumi.String(server.Keepers.ApplyT(func(keepers map[string]string) (*string, error) {
    				return &keepers.AmiId, nil
    			}).(pulumi.StringPtrOutput)),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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 server = new Random.RandomPet("server", new()
        {
            Keepers = 
            {
                { "ami_id", amiId },
            },
        });
    
        var serverInstance = new Aws.Ec2.Instance("server", new()
        {
            Tags = 
            {
                { "Name", server.Id.Apply(id => $"web-server-{id}") },
            },
            Ami = server.Keepers.Apply(keepers => keepers?.AmiId),
        });
    
    });
    
    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) {
            // 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 server = new RandomPet("server", RandomPetArgs.builder()
                .keepers(Map.of("ami_id", amiId))
                .build());
    
            var serverInstance = new Instance("serverInstance", InstanceArgs.builder()
                .tags(Map.of("Name", server.id().applyValue(id -> String.format("web-server-%s", id))))
                .ami(server.keepers().applyValue(keepers -> keepers.amiId()))
                .build());
    
        }
    }
    
    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.
      server:
        type: random:RandomPet
        properties:
          keepers:
            ami_id: ${amiId}
      serverInstance:
        type: aws:ec2:Instance
        name: server
        properties:
          tags:
            Name: web-server-${server.id}
          ami: ${server.keepers.amiId}
    

    Create RandomPet Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new RandomPet(name: string, args?: RandomPetArgs, opts?: CustomResourceOptions);
    @overload
    def RandomPet(resource_name: str,
                  args: Optional[RandomPetArgs] = None,
                  opts: Optional[ResourceOptions] = None)
    
    @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)
    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.
    
    

    Parameters

    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.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var randomPetResource = new Random.RandomPet("randomPetResource", new()
    {
        Keepers = 
        {
            { "string", "string" },
        },
        Length = 0,
        Prefix = "string",
        Separator = "string",
    });
    
    example, err := random.NewRandomPet(ctx, "randomPetResource", &random.RandomPetArgs{
    	Keepers: pulumi.StringMap{
    		"string": pulumi.String("string"),
    	},
    	Length:    pulumi.Int(0),
    	Prefix:    pulumi.String("string"),
    	Separator: pulumi.String("string"),
    })
    
    var randomPetResource = new RandomPet("randomPetResource", RandomPetArgs.builder()
        .keepers(Map.of("string", "string"))
        .length(0)
        .prefix("string")
        .separator("string")
        .build());
    
    random_pet_resource = random.RandomPet("randomPetResource",
        keepers={
            "string": "string",
        },
        length=0,
        prefix="string",
        separator="string")
    
    const randomPetResource = new random.RandomPet("randomPetResource", {
        keepers: {
            string: "string",
        },
        length: 0,
        prefix: "string",
        separator: "string",
    });
    
    type: random:RandomPet
    properties:
        keepers:
            string: string
        length: 0
        prefix: string
        separator: string
    

    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

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    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.7 published on Wednesday, Oct 16, 2024 by Pulumi