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/v2/go/aws/alb"
    "github.com/pulumi/pulumi-random/sdk/v2/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.StringMap{
                "listener_arn": pulumi.String(_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.String(_var.Target_group_arn),
                    Type:           pulumi.String("forward"),
                },
            },
            ListenerArn: pulumi.String(_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=[{
        "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

def RandomInteger(resource_name, opts=None, keepers=None, max=None, min=None, seed=None, __props__=None);
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.

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.

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.

seed string

A custom seed to always produce the same value.

max float

The maximum inclusive value of the range.

min float

The minimum inclusive value of the range.

keepers Dict[str, Any]

Arbitrary map of values that, when changed, will trigger a new id to be generated.

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 float

(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
static get(resource_name, id, opts=None, keepers=None, max=None, min=None, result=None, seed=None, __props__=None);
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.

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.

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.

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 Dict[str, Any]

Arbitrary map of values that, when changed, will trigger a new id to be generated.

max float

The maximum inclusive value of the range.

min float

The minimum inclusive value of the range.

result float

(int) The random Integer result.

seed str

A custom seed to always produce the same value.

Package Details

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