Random Pet Args
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
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());
}
}
Content copied to clipboard