@pulumi/random
Version:
A Pulumi package to safely use randomness in Pulumi programs.
108 lines • 4.45 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.RandomInteger = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("./utilities");
/**
* The resource `random.RandomInteger` generates random values from a given range, described by the `min` and `max` attributes of a given resource.
*
* 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 random priority
* // between 1 and 50000 for a aws_alb_listener_rule resource:
* const priority = new random.RandomInteger("priority", {
* min: 1,
* max: 50000,
* keepers: {
* listener_arn: listenerArn,
* },
* });
* const main = new aws.alb.ListenerRule("main", {
* listenerArn: priority.keepers.apply(keepers => keepers?.listenerArn),
* priority: priority.result,
* actions: [{
* type: "forward",
* targetGroupArn: targetGroupArn,
* }],
* });
* ```
*
* ## Import
*
* Random integers can be imported using the result, min, and max, with an
*
* optional seed. This can be used to replace a config value with a value
*
* interpolated from the random provider without experiencing diffs.
*
* Example (values are separated by a ,):
*
* ```sh
* $ pulumi import random:index/randomInteger:RandomInteger priority 15390,1,50000
* ```
*/
class RandomInteger extends pulumi.CustomResource {
/**
* Get an existing RandomInteger 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 RandomInteger(name, state, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* Returns true if the given object is an instance of RandomInteger. 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'] === RandomInteger.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["keepers"] = state ? state.keepers : undefined;
resourceInputs["max"] = state ? state.max : undefined;
resourceInputs["min"] = state ? state.min : undefined;
resourceInputs["result"] = state ? state.result : undefined;
resourceInputs["seed"] = state ? state.seed : undefined;
}
else {
const args = argsOrState;
if ((!args || args.max === undefined) && !opts.urn) {
throw new Error("Missing required property 'max'");
}
if ((!args || args.min === undefined) && !opts.urn) {
throw new Error("Missing required property 'min'");
}
resourceInputs["keepers"] = args ? args.keepers : undefined;
resourceInputs["max"] = args ? args.max : undefined;
resourceInputs["min"] = args ? args.min : undefined;
resourceInputs["seed"] = args ? args.seed : undefined;
resourceInputs["result"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(RandomInteger.__pulumiType, name, resourceInputs, opts);
}
}
exports.RandomInteger = RandomInteger;
/** @internal */
RandomInteger.__pulumiType = 'random:index/randomInteger:RandomInteger';
//# sourceMappingURL=randomInteger.js.map