@pulumi/random
Version:
A Pulumi package to safely use randomness in Pulumi programs.
81 lines • 3.5 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.RandomPet = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("./utilities");
/**
* 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 `createBeforeDestroy` lifecycle flag set, to avoid conflicts with unique names during the brief period where both the old and new resources exist concurrently.
*
* ## Example Usage
*
* ```typescript
* 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),
* });
* ```
*/
class RandomPet extends pulumi.CustomResource {
/**
* Get an existing RandomPet resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new RandomPet(name, state, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* Returns true if the given object is an instance of RandomPet. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === RandomPet.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["keepers"] = state ? state.keepers : undefined;
resourceInputs["length"] = state ? state.length : undefined;
resourceInputs["prefix"] = state ? state.prefix : undefined;
resourceInputs["separator"] = state ? state.separator : undefined;
}
else {
const args = argsOrState;
resourceInputs["keepers"] = args ? args.keepers : undefined;
resourceInputs["length"] = args ? args.length : undefined;
resourceInputs["prefix"] = args ? args.prefix : undefined;
resourceInputs["separator"] = args ? args.separator : undefined;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(RandomPet.__pulumiType, name, resourceInputs, opts);
}
}
exports.RandomPet = RandomPet;
/** @internal */
RandomPet.__pulumiType = 'random:index/randomPet:RandomPet';
//# sourceMappingURL=randomPet.js.map