RandomIntegerArgs

data class RandomIntegerArgs(val keepers: Output<Map<String, String>>? = null, val max: Output<Int>? = null, val min: Output<Int>? = null, val seed: Output<String>? = null) : ConvertibleToJava<RandomIntegerArgs>

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

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 pulumi
import pulumi_aws as aws
import pulumi_random as random
# The following example shows how to generate a random priority
# between 1 and 50000 for a aws_alb_listener_rule resource:
priority = random.RandomInteger("priority",
min=1,
max=50000,
keepers={
"listener_arn": listener_arn,
})
main = aws.alb.ListenerRule("main",
listener_arn=priority.keepers["listenerArn"],
priority=priority.result,
actions=[{
"type": "forward",
"target_group_arn": target_group_arn,
}])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Random = Pulumi.Random;
return await Deployment.RunAsync(() =>
{
// The following example shows how to generate a random priority
// between 1 and 50000 for a aws_alb_listener_rule resource:
var priority = new Random.RandomInteger("priority", new()
{
Min = 1,
Max = 50000,
Keepers =
{
{ "listener_arn", listenerArn },
},
});
var main = new Aws.Alb.ListenerRule("main", new()
{
ListenerArn = priority.Keepers.Apply(keepers => keepers?.ListenerArn),
Priority = priority.Result,
Actions = new[]
{
new Aws.Alb.Inputs.ListenerRuleActionArgs
{
Type = "forward",
TargetGroupArn = targetGroupArn,
},
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/alb"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// The following example shows how to generate a random priority
// between 1 and 50000 for a aws_alb_listener_rule resource:
priority, err := random.NewRandomInteger(ctx, "priority", &random.RandomIntegerArgs{
Min: pulumi.Int(1),
Max: pulumi.Int(50000),
Keepers: pulumi.StringMap{
"listener_arn": pulumi.Any(listenerArn),
},
})
if err != nil {
return err
}
_, err = alb.NewListenerRule(ctx, "main", &alb.ListenerRuleArgs{
ListenerArn: pulumi.String(priority.Keepers.ApplyT(func(keepers map[string]string) (*string, error) {
return &keepers.ListenerArn, nil
}).(pulumi.StringPtrOutput)),
Priority: priority.Result,
Actions: alb.ListenerRuleActionArray{
&alb.ListenerRuleActionArgs{
Type: pulumi.String("forward"),
TargetGroupArn: pulumi.Any(targetGroupArn),
},
},
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.random.RandomInteger;
import com.pulumi.random.RandomIntegerArgs;
import com.pulumi.aws.alb.ListenerRule;
import com.pulumi.aws.alb.ListenerRuleArgs;
import com.pulumi.aws.alb.inputs.ListenerRuleActionArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
// The following example shows how to generate a random priority
// between 1 and 50000 for a aws_alb_listener_rule resource:
var priority = new RandomInteger("priority", RandomIntegerArgs.builder()
.min(1)
.max(50000)
.keepers(Map.of("listener_arn", listenerArn))
.build());
var main = new ListenerRule("main", ListenerRuleArgs.builder()
.listenerArn(priority.keepers().applyValue(_keepers -> _keepers.listenerArn()))
.priority(priority.result())
.actions(ListenerRuleActionArgs.builder()
.type("forward")
.targetGroupArn(targetGroupArn)
.build())
.build());
}
}
resources:
# The following example shows how to generate a random priority
# between 1 and 50000 for a aws_alb_listener_rule resource:
priority:
type: random:RandomInteger
properties:
min: 1
max: 50000
keepers:
listener_arn: ${listenerArn}
main:
type: aws:alb:ListenerRule
properties:
listenerArn: ${priority.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 ,):

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

Constructors

Link copied to clipboard
constructor(keepers: Output<Map<String, String>>? = null, max: Output<Int>? = null, min: Output<Int>? = null, seed: Output<String>? = null)

Properties

Link copied to clipboard
val keepers: Output<Map<String, String>>? = null

Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.

Link copied to clipboard
val max: Output<Int>? = null

The maximum inclusive value of the range.

Link copied to clipboard
val min: Output<Int>? = null

The minimum inclusive value of the range.

Link copied to clipboard
val seed: Output<String>? = null

A custom seed to always produce the same value.

Functions

Link copied to clipboard
open override fun toJava(): RandomIntegerArgs