random.RandomInteger
Explore with Pulumi AI
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,
}])
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
})
}
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 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}
Create RandomInteger Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new RandomInteger(name: string, args: RandomIntegerArgs, opts?: CustomResourceOptions);
@overload
def RandomInteger(resource_name: str,
args: RandomIntegerArgs,
opts: Optional[ResourceOptions] = None)
@overload
def RandomInteger(resource_name: str,
opts: Optional[ResourceOptions] = None,
max: Optional[int] = None,
min: Optional[int] = None,
keepers: Optional[Mapping[str, str]] = 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)
public RandomInteger(String name, RandomIntegerArgs args)
public RandomInteger(String name, RandomIntegerArgs args, CustomResourceOptions options)
type: random:RandomInteger
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- 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.
- args RandomIntegerArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control 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.
- name String
- The unique name of the resource.
- args RandomIntegerArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var randomIntegerResource = new Random.RandomInteger("randomIntegerResource", new()
{
Max = 0,
Min = 0,
Keepers =
{
{ "string", "string" },
},
Seed = "string",
});
example, err := random.NewRandomInteger(ctx, "randomIntegerResource", &random.RandomIntegerArgs{
Max: pulumi.Int(0),
Min: pulumi.Int(0),
Keepers: pulumi.StringMap{
"string": pulumi.String("string"),
},
Seed: pulumi.String("string"),
})
var randomIntegerResource = new RandomInteger("randomIntegerResource", RandomIntegerArgs.builder()
.max(0)
.min(0)
.keepers(Map.of("string", "string"))
.seed("string")
.build());
random_integer_resource = random.RandomInteger("randomIntegerResource",
max=0,
min=0,
keepers={
"string": "string",
},
seed="string")
const randomIntegerResource = new random.RandomInteger("randomIntegerResource", {
max: 0,
min: 0,
keepers: {
string: "string",
},
seed: "string",
});
type: random:RandomInteger
properties:
keepers:
string: string
max: 0
min: 0
seed: string
RandomInteger Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
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, string>
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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]string
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- Seed string
- A custom seed to always produce the same value.
- max Integer
- The maximum inclusive value of the range.
- min Integer
- The minimum inclusive value of the range.
- keepers Map<String,String>
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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]: string}
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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, str]
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- seed str
- 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 Map<String>
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- seed String
- 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:
Look up 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, str]] = 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)
public static RandomInteger get(String name, Output<String> id, RandomIntegerState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- 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.
- 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.
- Keepers Dictionary<string, string>
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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
- The random integer result.
- Seed string
- A custom seed to always produce the same value.
- Keepers map[string]string
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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
- The random integer result.
- Seed string
- A custom seed to always produce the same value.
- keepers Map<String,String>
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- max Integer
- The maximum inclusive value of the range.
- min Integer
- The minimum inclusive value of the range.
- result Integer
- The random integer result.
- seed String
- A custom seed to always produce the same value.
- keepers {[key: string]: string}
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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
- The random integer result.
- seed string
- A custom seed to always produce the same value.
- keepers Mapping[str, str]
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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
- The random integer result.
- seed str
- A custom seed to always produce the same value.
- keepers Map<String>
- Arbitrary map of values that, when changed, will trigger recreation of resource. 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
- The random integer result.
- seed String
- 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
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- random pulumi/pulumi-random
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
random
Terraform Provider.