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}") },
},
});
}
}
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
"github.com/pulumi/pulumi-random/sdk/v2/go/random"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
serverRandomPet, err := random.NewRandomPet(ctx, "serverRandomPet", &random.RandomPetArgs{
Keepers: pulumi.StringMap{
"ami_id": pulumi.String(_var.Ami_id),
},
})
if err != nil {
return err
}
_, err = ec2.NewInstance(ctx, "serverInstance", &ec2.InstanceArgs{
Ami: pulumi.String(serverRandomPet.Keepers.ApplyT(func(keepers map[string]string) (string, error) {
return keepers.AmiId, nil
}).(pulumi.StringOutput)),
Tags: pulumi.StringMap{
"Name": serverRandomPet.ID().ApplyT(func(id string) (string, error) {
return fmt.Sprintf("%v%v", "web-server-", id), nil
}).(pulumi.StringOutput),
},
})
if err != nil {
return err
}
return nil
})
}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, opts=None, keepers=None, length=None, prefix=None, separator=None, __props__=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:
Outputs
All input properties are implicitly available as output properties. Additionally, the RandomPet resource produces the following output properties:
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): RandomPetstatic get(resource_name, id, opts=None, keepers=None, length=None, prefix=None, separator=None, __props__=None);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:
Package Details
- Repository
- https://github.com/pulumi/pulumi-random
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
randomTerraform Provider.