RandomString

The resource random.RandomString generates a random permutation of alphanumeric characters and optionally special characters.

This resource does use a cryptographic random number generator.

Historically this resource’s intended usage has been ambiguous as the original example used it in a password. For backwards compatibility it will continue to exist. For unique ids please use random_id, for sensitive random values please use random_password.

Example Usage

using Pulumi;
using Random = Pulumi.Random;

class MyStack : Stack
{
    public MyStack()
    {
        var random = new Random.RandomString("random", new Random.RandomStringArgs
        {
            Length = 16,
            OverrideSpecial = "/@£$",
            Special = true,
        });
    }

}
package main

import (
	"fmt"

	"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 {
		_, err := random.NewRandomString(ctx, "random", &random.RandomStringArgs{
			Length:          pulumi.Int(16),
			OverrideSpecial: pulumi.String(fmt.Sprintf("%v%v", "/@£", "$")),
			Special:         pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_random as random

random = random.RandomString("random",
    length=16,
    override_special="/@£$",
    special=True)
import * as pulumi from "@pulumi/pulumi";
import * as random from "@pulumi/random";

const randomRandomString = new random.RandomString("random", {
    length: 16,
    overrideSpecial: "/@£$",
    special: true,
});

Create a RandomString Resource

new RandomString(name: string, args: RandomStringArgs, opts?: CustomResourceOptions);
@overload
def RandomString(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 keepers: Optional[Mapping[str, Any]] = None,
                 length: Optional[int] = None,
                 lower: Optional[bool] = None,
                 min_lower: Optional[int] = None,
                 min_numeric: Optional[int] = None,
                 min_special: Optional[int] = None,
                 min_upper: Optional[int] = None,
                 number: Optional[bool] = None,
                 override_special: Optional[str] = None,
                 special: Optional[bool] = None,
                 upper: Optional[bool] = None)
@overload
def RandomString(resource_name: str,
                 args: RandomStringArgs,
                 opts: Optional[ResourceOptions] = None)
func NewRandomString(ctx *Context, name string, args RandomStringArgs, opts ...ResourceOption) (*RandomString, error)
public RandomString(string name, RandomStringArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RandomStringArgs
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 RandomStringArgs
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 RandomStringArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RandomStringArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

RandomString Resource Properties

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

Inputs

The RandomString resource accepts the following input properties:

Length int
The length of the string desired
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.
Lower bool
(default true) Include lowercase alphabet characters in random string.
MinLower int
(default 0) Minimum number of lowercase alphabet characters in random string.
MinNumeric int
(default 0) Minimum number of numeric characters in random string.
MinSpecial int
(default 0) Minimum number of special characters in random string.
MinUpper int
(default 0) Minimum number of uppercase alphabet characters in random string.
Number bool
(default true) Include numeric characters in random string.
OverrideSpecial string
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
Special bool
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
Upper bool
(default true) Include uppercase alphabet characters in random string.
Length int
The length of the string desired
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.
Lower bool
(default true) Include lowercase alphabet characters in random string.
MinLower int
(default 0) Minimum number of lowercase alphabet characters in random string.
MinNumeric int
(default 0) Minimum number of numeric characters in random string.
MinSpecial int
(default 0) Minimum number of special characters in random string.
MinUpper int
(default 0) Minimum number of uppercase alphabet characters in random string.
Number bool
(default true) Include numeric characters in random string.
OverrideSpecial string
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
Special bool
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
Upper bool
(default true) Include uppercase alphabet characters in random string.
length number
The length of the string desired
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.
lower boolean
(default true) Include lowercase alphabet characters in random string.
minLower number
(default 0) Minimum number of lowercase alphabet characters in random string.
minNumeric number
(default 0) Minimum number of numeric characters in random string.
minSpecial number
(default 0) Minimum number of special characters in random string.
minUpper number
(default 0) Minimum number of uppercase alphabet characters in random string.
number boolean
(default true) Include numeric characters in random string.
overrideSpecial string
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
special boolean
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
upper boolean
(default true) Include uppercase alphabet characters in random string.
length int
The length of the string desired
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.
lower bool
(default true) Include lowercase alphabet characters in random string.
min_lower int
(default 0) Minimum number of lowercase alphabet characters in random string.
min_numeric int
(default 0) Minimum number of numeric characters in random string.
min_special int
(default 0) Minimum number of special characters in random string.
min_upper int
(default 0) Minimum number of uppercase alphabet characters in random string.
number bool
(default true) Include numeric characters in random string.
override_special str
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
special bool
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
upper bool
(default true) Include uppercase alphabet characters in random string.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
Result string
Random string generated.
Id string
The provider-assigned unique ID for this managed resource.
Result string
Random string generated.
id string
The provider-assigned unique ID for this managed resource.
result string
Random string generated.
id str
The provider-assigned unique ID for this managed resource.
result str
Random string generated.

Look up an Existing RandomString Resource

Get an existing RandomString 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?: RandomStringState, opts?: CustomResourceOptions): RandomString
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        keepers: Optional[Mapping[str, Any]] = None,
        length: Optional[int] = None,
        lower: Optional[bool] = None,
        min_lower: Optional[int] = None,
        min_numeric: Optional[int] = None,
        min_special: Optional[int] = None,
        min_upper: Optional[int] = None,
        number: Optional[bool] = None,
        override_special: Optional[str] = None,
        result: Optional[str] = None,
        special: Optional[bool] = None,
        upper: Optional[bool] = None) -> RandomString
func GetRandomString(ctx *Context, name string, id IDInput, state *RandomStringState, opts ...ResourceOption) (*RandomString, error)
public static RandomString Get(string name, Input<string> id, RandomStringState? 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. See the main provider documentation for more information.
Length int
The length of the string desired
Lower bool
(default true) Include lowercase alphabet characters in random string.
MinLower int
(default 0) Minimum number of lowercase alphabet characters in random string.
MinNumeric int
(default 0) Minimum number of numeric characters in random string.
MinSpecial int
(default 0) Minimum number of special characters in random string.
MinUpper int
(default 0) Minimum number of uppercase alphabet characters in random string.
Number bool
(default true) Include numeric characters in random string.
OverrideSpecial string
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
Result string
Random string generated.
Special bool
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
Upper bool
(default true) Include uppercase alphabet characters in random string.
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.
Length int
The length of the string desired
Lower bool
(default true) Include lowercase alphabet characters in random string.
MinLower int
(default 0) Minimum number of lowercase alphabet characters in random string.
MinNumeric int
(default 0) Minimum number of numeric characters in random string.
MinSpecial int
(default 0) Minimum number of special characters in random string.
MinUpper int
(default 0) Minimum number of uppercase alphabet characters in random string.
Number bool
(default true) Include numeric characters in random string.
OverrideSpecial string
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
Result string
Random string generated.
Special bool
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
Upper bool
(default true) Include uppercase alphabet characters in random string.
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.
length number
The length of the string desired
lower boolean
(default true) Include lowercase alphabet characters in random string.
minLower number
(default 0) Minimum number of lowercase alphabet characters in random string.
minNumeric number
(default 0) Minimum number of numeric characters in random string.
minSpecial number
(default 0) Minimum number of special characters in random string.
minUpper number
(default 0) Minimum number of uppercase alphabet characters in random string.
number boolean
(default true) Include numeric characters in random string.
overrideSpecial string
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
result string
Random string generated.
special boolean
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
upper boolean
(default true) Include uppercase alphabet characters in random string.
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.
length int
The length of the string desired
lower bool
(default true) Include lowercase alphabet characters in random string.
min_lower int
(default 0) Minimum number of lowercase alphabet characters in random string.
min_numeric int
(default 0) Minimum number of numeric characters in random string.
min_special int
(default 0) Minimum number of special characters in random string.
min_upper int
(default 0) Minimum number of uppercase alphabet characters in random string.
number bool
(default true) Include numeric characters in random string.
override_special str
Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The special argument must still be set to true for any overwritten characters to be used in generation.
result str
Random string generated.
special bool
(default true) Include special characters in random string. These are !@#$%&*()-_=+[]{}<>:?
upper bool
(default true) Include uppercase alphabet characters in random string.

Import

Strings can be imported by just specifying the value of the string

 $ pulumi import random:index/randomString:RandomString test test

Package Details

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