Random String
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
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.random.RandomString;
import com.pulumi.random.RandomStringArgs;
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 random = new RandomString("random", RandomStringArgs.builder()
.length(16)
.overrideSpecial("/@£$")
.special(true)
.build());
}
}
Import
You can import external strings into your Pulumi programs as RandomString resources as follows:
$ import random:index/randomString:RandomString newString myspecialdata
This command will encode the myspecialdata
token in Pulumi state and generate a code suggestion to include a new RandomString resource in your Pulumi program. Include the suggested code and do a pulumi up
. Your data is now stored in Pulumi, and you can reference it in your Pulumi program as newString.result
. If the data needs to be stored securily as a secret, consider using the RandomPassword resource instead.