@pulumi/random
Version:
A Pulumi package to safely use randomness in Pulumi programs.
170 lines (169 loc) • 6.62 kB
TypeScript
import * as pulumi from "@pulumi/pulumi";
/**
* 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.ec2.Instance("server", {
* tags: {
* Name: pulumi.interpolate`web-server ${server.hex}`,
* },
* ami: server.keepers.apply(keepers => keepers?.amiId),
* });
* ```
*
* ## Import
*
* 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
* ```
*/
export declare 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: string, id: pulumi.Input<pulumi.ID>, state?: RandomIdState, opts?: pulumi.CustomResourceOptions): RandomId;
/**
* 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: any): obj is RandomId;
/**
* The generated id presented in base64 without additional transformations.
*/
readonly b64Std: pulumi.Output<string>;
/**
* The generated id presented in base64, using the URL-friendly character set: case-sensitive letters, digits and the characters `_` and `-`.
*/
readonly b64Url: pulumi.Output<string>;
/**
* The number of random bytes to produce. The minimum value is 1, which produces eight bits of randomness.
*/
readonly byteLength: pulumi.Output<number>;
/**
* The generated id presented in non-padded decimal digits.
*/
readonly dec: pulumi.Output<string>;
/**
* The generated id presented in padded hexadecimal digits. This result will always be twice as long as the requested byte length.
*/
readonly hex: pulumi.Output<string>;
/**
* Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
*/
readonly keepers: pulumi.Output<{
[key: string]: string;
} | undefined>;
/**
* Arbitrary string to prefix the output value with. This string is supplied as-is, meaning it is not guaranteed to be URL-safe or base64 encoded.
*/
readonly prefix: pulumi.Output<string | undefined>;
/**
* Create a RandomId resource with the given unique name, arguments, and options.
*
* @param name The _unique_ name of the resource.
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name: string, args: RandomIdArgs, opts?: pulumi.CustomResourceOptions);
}
/**
* Input properties used for looking up and filtering RandomId resources.
*/
export interface RandomIdState {
/**
* The generated id presented in base64 without additional transformations.
*/
b64Std?: pulumi.Input<string>;
/**
* The generated id presented in base64, using the URL-friendly character set: case-sensitive letters, digits and the characters `_` and `-`.
*/
b64Url?: pulumi.Input<string>;
/**
* The number of random bytes to produce. The minimum value is 1, which produces eight bits of randomness.
*/
byteLength?: pulumi.Input<number>;
/**
* The generated id presented in non-padded decimal digits.
*/
dec?: pulumi.Input<string>;
/**
* The generated id presented in padded hexadecimal digits. This result will always be twice as long as the requested byte length.
*/
hex?: pulumi.Input<string>;
/**
* Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
*/
keepers?: pulumi.Input<{
[key: string]: pulumi.Input<string>;
}>;
/**
* Arbitrary string to prefix the output value with. This string is supplied as-is, meaning it is not guaranteed to be URL-safe or base64 encoded.
*/
prefix?: pulumi.Input<string>;
}
/**
* The set of arguments for constructing a RandomId resource.
*/
export interface RandomIdArgs {
/**
* The number of random bytes to produce. The minimum value is 1, which produces eight bits of randomness.
*/
byteLength: pulumi.Input<number>;
/**
* Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
*/
keepers?: pulumi.Input<{
[key: string]: pulumi.Input<string>;
}>;
/**
* Arbitrary string to prefix the output value with. This string is supplied as-is, meaning it is not guaranteed to be URL-safe or base64 encoded.
*/
prefix?: pulumi.Input<string>;
}