RandomPetArgs

data class RandomPetArgs(val keepers: Output<Map<String, String>>? = null, val length: Output<Int>? = null, val prefix: Output<String>? = null, val separator: Output<String>? = null) : ConvertibleToJava<RandomPetArgs>

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"])
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 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
})
}
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}

Constructors

Link copied to clipboard
constructor(keepers: Output<Map<String, String>>? = null, length: Output<Int>? = null, prefix: Output<String>? = null, separator: Output<String>? = null)

Properties

Link copied to clipboard
val keepers: Output<Map<String, String>>? = null

Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.

Link copied to clipboard
val length: Output<Int>? = null

The length (in words) of the pet name. Defaults to 2

Link copied to clipboard
val prefix: Output<String>? = null

A string to prefix the name with.

Link copied to clipboard
val separator: Output<String>? = null

The character to separate words in the pet name. Defaults to "-"

Functions

Link copied to clipboard
open override fun toJava(): RandomPetArgs