Random Integer
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
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) {
var priority = new RandomInteger("priority", RandomIntegerArgs.builder()
.min(1)
.max(50000)
.keepers(Map.of("listener_arn", var_.listener_arn()))
.build());
var main = new ListenerRule("main", ListenerRuleArgs.builder()
.listenerArn(priority.keepers().applyValue(keepers -> keepers.listenerArn()))
.priority(priority.result())
.actions(ListenerRuleActionArgs.builder()
.type("forward")
.targetGroupArn(var_.target_group_arn())
.build())
.build());
}
}
Content copied to clipboard
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
Content copied to clipboard