@pulumi/random
Version:
A Pulumi package to safely use randomness in Pulumi programs.
125 lines • 4.7 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.RandomId = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("./utilities");
/**
* The resource `random.RandomId` generates random numbers that are intended to be
* used as unique identifiers for other resources. If the output is considered
* sensitive, and should not be displayed in the CLI, use `random.RandomBytes`
* instead.
*
* This resource *does* use a cryptographic random number generator in order
* to minimize the chance of collisions, making the results of this resource
* when a 16-byte identifier is requested of equivalent uniqueness to a
* type-4 UUID.
*
* 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 name for an AWS EC2
* // instance that changes each time a new AMI id is selected.
* const server = new random.RandomId("server", {
* keepers: {
* ami_id: amiId,
* },
* byteLength: 8,
* });
* const serverInstance = new aws.index.Instance("server", {
* tags: {
* name: `web-server ${server.hex}`,
* },
* ami: server.keepers?.amiId,
* });
* ```
*
* ## Import
*
* The `pulumi import` command can be used, for example:
*
* Random IDs can be imported using the b64_url with an optional prefix. This
*
* can be used to replace a config value with a value interpolated from the
*
* random provider without experiencing diffs.
*
* Example with no prefix:
*
* ```sh
* $ pulumi import random:index/randomId:RandomId server p-9hUg
* ```
*
* Example with prefix (prefix is separated by a ,):
*
* ```sh
* $ pulumi import random:index/randomId:RandomId server my-prefix-,p-9hUg
* ```
*/
class RandomId extends pulumi.CustomResource {
/**
* Get an existing RandomId 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 RandomId(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of RandomId. 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'] === RandomId.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["b64Std"] = state?.b64Std;
resourceInputs["b64Url"] = state?.b64Url;
resourceInputs["byteLength"] = state?.byteLength;
resourceInputs["dec"] = state?.dec;
resourceInputs["hex"] = state?.hex;
resourceInputs["keepers"] = state?.keepers;
resourceInputs["prefix"] = state?.prefix;
}
else {
const args = argsOrState;
if (args?.byteLength === undefined && !opts.urn) {
throw new Error("Missing required property 'byteLength'");
}
resourceInputs["byteLength"] = args?.byteLength;
resourceInputs["keepers"] = args?.keepers;
resourceInputs["prefix"] = args?.prefix;
resourceInputs["b64Std"] = undefined /*out*/;
resourceInputs["b64Url"] = undefined /*out*/;
resourceInputs["dec"] = undefined /*out*/;
resourceInputs["hex"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(RandomId.__pulumiType, name, resourceInputs, opts);
}
}
exports.RandomId = RandomId;
/** @internal */
RandomId.__pulumiType = 'random:index/randomId:RandomId';
//# sourceMappingURL=randomId.js.map