Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

RandomInteger

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 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

using Pulumi;
using Aws = Pulumi.Aws;
using Random = Pulumi.Random;

class MyStack : Stack
{
    public MyStack()
    {
        var priority = new Random.RandomInteger("priority", new Random.RandomIntegerArgs
        {
            Keepers = 
            {
                { "listener_arn", @var.Listener_arn },
            },
            Max = 50000,
            Min = 1,
        });
        var main = new Aws.Alb.ListenerRule("main", new Aws.Alb.ListenerRuleArgs
        {
            Actions = 
            {
                new Aws.Alb.Inputs.ListenerRuleActionArgs
                {
                    TargetGroupArn = @var.Target_group_arn,
                    Type = "forward",
                },
            },
            ListenerArn = @var.Listener_arn,
            Priority = priority.Result,
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v3/go/aws/alb"
    "github.com/pulumi/pulumi-random/sdk/v3/go/random"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        priority, err := random.NewRandomInteger(ctx, "priority", &random.RandomIntegerArgs{
            Keepers: pulumi.AnyMap{
                "listener_arn": pulumi.Any(_var.Listener_arn),
            },
            Max: pulumi.Int(50000),
            Min: pulumi.Int(1),
        })
        if err != nil {
            return err
        }
        _, err = alb.NewListenerRule(ctx, "main", &alb.ListenerRuleArgs{
            Actions: alb.ListenerRuleActionArray{
                &alb.ListenerRuleActionArgs{
                    TargetGroupArn: pulumi.Any(_var.Target_group_arn),
                    Type:           pulumi.String("forward"),
                },
            },
            ListenerArn: pulumi.Any(_var.Listener_arn),
            Priority:    priority.Result,
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws
import pulumi_random as random

priority = random.RandomInteger("priority",
    keepers={
        "listener_arn": var["listener_arn"],
    },
    max=50000,
    min=1)
main = aws.alb.ListenerRule("main",
    actions=[aws.alb.ListenerRuleActionArgs(
        target_group_arn=var["target_group_arn"],
        type="forward",
    )],
    listener_arn=var["listener_arn"],
    priority=priority.result)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as random from "@pulumi/random";

const priority = new random.RandomInteger("priority", {
    keepers: {
        // Generate a new integer each time we switch to a new listener ARN
        listener_arn: var_listener_arn,
    },
    max: 50000,
    min: 1,
});
const main = new aws.alb.ListenerRule("main", {
    actions: [{
        targetGroupArn: var_target_group_arn,
        type: "forward",
    }],
    listenerArn: var_listener_arn,
    priority: priority.result,
});

Create a RandomInteger Resource

new RandomInteger(name: string, args: RandomIntegerArgs, opts?: CustomResourceOptions);
def RandomInteger(resource_name: str, opts: Optional[ResourceOptions] = None, keepers: Optional[Mapping[str, Any]] = None, max: Optional[int] = None, min: Optional[int] = None, seed: Optional[str] = None)
func NewRandomInteger(ctx *Context, name string, args RandomIntegerArgs, opts ...ResourceOption) (*RandomInteger, error)
public RandomInteger(string name, RandomIntegerArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RandomIntegerArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args RandomIntegerArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RandomIntegerArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

RandomInteger Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The RandomInteger resource accepts the following input properties:

Max int

The maximum inclusive value of the range.

Min int

The minimum inclusive value of the range.

Keepers Dictionary<string, object>

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Seed string

A custom seed to always produce the same value.

Max int

The maximum inclusive value of the range.

Min int

The minimum inclusive value of the range.

Keepers map[string]interface{}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Seed string

A custom seed to always produce the same value.

max number

The maximum inclusive value of the range.

min number

The minimum inclusive value of the range.

keepers {[key: string]: any}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

seed string

A custom seed to always produce the same value.

max int

The maximum inclusive value of the range.

min int

The minimum inclusive value of the range.

keepers Mapping[str, Any]

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

seed str

A custom seed to always produce the same value.

Outputs

All input properties are implicitly available as output properties. Additionally, the RandomInteger resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Result int

(int) The random Integer result.

Id string
The provider-assigned unique ID for this managed resource.
Result int

(int) The random Integer result.

id string
The provider-assigned unique ID for this managed resource.
result number

(int) The random Integer result.

id str
The provider-assigned unique ID for this managed resource.
result int

(int) The random Integer result.

Look up an Existing RandomInteger Resource

Get an existing RandomInteger resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: RandomIntegerState, opts?: CustomResourceOptions): RandomInteger
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, keepers: Optional[Mapping[str, Any]] = None, max: Optional[int] = None, min: Optional[int] = None, result: Optional[int] = None, seed: Optional[str] = None) -> RandomInteger
func GetRandomInteger(ctx *Context, name string, id IDInput, state *RandomIntegerState, opts ...ResourceOption) (*RandomInteger, error)
public static RandomInteger Get(string name, Input<string> id, RandomIntegerState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

Keepers Dictionary<string, object>

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Max int

The maximum inclusive value of the range.

Min int

The minimum inclusive value of the range.

Result int

(int) The random Integer result.

Seed string

A custom seed to always produce the same value.

Keepers map[string]interface{}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

Max int

The maximum inclusive value of the range.

Min int

The minimum inclusive value of the range.

Result int

(int) The random Integer result.

Seed string

A custom seed to always produce the same value.

keepers {[key: string]: any}

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

max number

The maximum inclusive value of the range.

min number

The minimum inclusive value of the range.

result number

(int) The random Integer result.

seed string

A custom seed to always produce the same value.

keepers Mapping[str, Any]

Arbitrary map of values that, when changed, will trigger a new id to be generated. See the main provider documentation for more information.

max int

The maximum inclusive value of the range.

min int

The minimum inclusive value of the range.

result int

(int) The random Integer result.

seed str

A custom seed to always produce the same value.

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 ,)

 $ pulumi import random:index/randomInteger:RandomInteger priority 15390,1,50000

Package Details

Repository
https://github.com/pulumi/pulumi-random
License
Apache-2.0
Notes
This Pulumi package is based on the random Terraform Provider.