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

RandomShuffle

The resource random.RandomShuffle generates a random permutation of a list of strings given as an argument.

Example Usage

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

class MyStack : Stack
{
    public MyStack()
    {
        var az = new Random.RandomShuffle("az", new Random.RandomShuffleArgs
        {
            Inputs = 
            {
                "us-west-1a",
                "us-west-1c",
                "us-west-1d",
                "us-west-1e",
            },
            ResultCount = 2,
        });
        var example = new Aws.Elb.LoadBalancer("example", new Aws.Elb.LoadBalancerArgs
        {
            AvailabilityZones = az.Results,
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v3/go/aws/elb"
    "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 {
        az, err := random.NewRandomShuffle(ctx, "az", &random.RandomShuffleArgs{
            Inputs: pulumi.StringArray{
                pulumi.String("us-west-1a"),
                pulumi.String("us-west-1c"),
                pulumi.String("us-west-1d"),
                pulumi.String("us-west-1e"),
            },
            ResultCount: pulumi.Int(2),
        })
        if err != nil {
            return err
        }
        _, err = elb.NewLoadBalancer(ctx, "example", &elb.LoadBalancerArgs{
            AvailabilityZones: az.Results,
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws
import pulumi_random as random

az = random.RandomShuffle("az",
    inputs=[
        "us-west-1a",
        "us-west-1c",
        "us-west-1d",
        "us-west-1e",
    ],
    result_count=2)
example = aws.elb.LoadBalancer("example", availability_zones=az.results)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as random from "@pulumi/random";

const az = new random.RandomShuffle("az", {
    inputs: [
        "us-west-1a",
        "us-west-1c",
        "us-west-1d",
        "us-west-1e",
    ],
    resultCount: 2,
});
const example = new aws.elb.LoadBalancer("example", {
    // Place the ELB in any two of the given availability zones, selected
    // at random.
    availabilityZones: az.results,
});

Create a RandomShuffle Resource

new RandomShuffle(name: string, args: RandomShuffleArgs, opts?: CustomResourceOptions);
def RandomShuffle(resource_name: str, opts: Optional[ResourceOptions] = None, inputs: Optional[Sequence[str]] = None, keepers: Optional[Mapping[str, Any]] = None, result_count: Optional[int] = None, seed: Optional[str] = None)
func NewRandomShuffle(ctx *Context, name string, args RandomShuffleArgs, opts ...ResourceOption) (*RandomShuffle, error)
public RandomShuffle(string name, RandomShuffleArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RandomShuffleArgs
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 RandomShuffleArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RandomShuffleArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

RandomShuffle Resource Properties

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

Inputs

The RandomShuffle resource accepts the following input properties:

Inputs List<string>

The list of strings to shuffle.

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.

ResultCount int

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

Seed string

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

Inputs []string

The list of strings to shuffle.

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.

ResultCount int

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

Seed string

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

inputs string[]

The list of strings to shuffle.

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.

resultCount number

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

seed string

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

inputs Sequence[str]

The list of strings to shuffle.

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.

result_count int

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

seed str

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
Results List<string>

Random permutation of the list of strings given in input.

Id string
The provider-assigned unique ID for this managed resource.
Results []string

Random permutation of the list of strings given in input.

id string
The provider-assigned unique ID for this managed resource.
results string[]

Random permutation of the list of strings given in input.

id str
The provider-assigned unique ID for this managed resource.
results Sequence[str]

Random permutation of the list of strings given in input.

Look up an Existing RandomShuffle Resource

Get an existing RandomShuffle 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?: RandomShuffleState, opts?: CustomResourceOptions): RandomShuffle
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, inputs: Optional[Sequence[str]] = None, keepers: Optional[Mapping[str, Any]] = None, result_count: Optional[int] = None, results: Optional[Sequence[str]] = None, seed: Optional[str] = None) -> RandomShuffle
func GetRandomShuffle(ctx *Context, name string, id IDInput, state *RandomShuffleState, opts ...ResourceOption) (*RandomShuffle, error)
public static RandomShuffle Get(string name, Input<string> id, RandomShuffleState? 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:

Inputs List<string>

The list of strings to shuffle.

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.

ResultCount int

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

Results List<string>

Random permutation of the list of strings given in input.

Seed string

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

Inputs []string

The list of strings to shuffle.

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.

ResultCount int

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

Results []string

Random permutation of the list of strings given in input.

Seed string

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

inputs string[]

The list of strings to shuffle.

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.

resultCount number

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

results string[]

Random permutation of the list of strings given in input.

seed string

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

inputs Sequence[str]

The list of strings to shuffle.

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.

result_count int

The number of results to return. Defaults to the number of items in the input list. If fewer items are requested, some elements will be excluded from the result. If more items are requested, items will be repeated in the result but not more frequently than the number of items in the input list.

results Sequence[str]

Random permutation of the list of strings given in input.

seed str

Arbitrary string with which to seed the random number generator, in order to produce less-volatile permutations of the list. Important: Even with an identical seed, it is not guaranteed that the same permutation will be produced across different versions of Terraform. This argument causes the result to be less volatile, but not fixed for all time.

Package Details

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