Pulumi Random
The `pulumi-random` provider enables the safe use of randomness in Pulumi programs, allowing users to generate resource properties, such as names or passwords, that incorporate randomness in a way that aligns with Pulumi's goal state-oriented approach. It avoids constant re-convergence by managing random values within the Pulumi state. The library is actively maintained, with frequent releases, and is currently at version 4.19.2.
Warnings
- breaking In version `v4.18.4`, there was a breaking schema change for the `pulumi:providers:random/terraformConfig` function. The input type of `__self__` changed from `#/resources/pulumi:providers:random` to `#/provider`.
- gotcha The `pulumi-random` provider manages randomness by generating values once during resource creation and then holding them steady until the inputs change. To explicitly trigger recreation of a random value, use the `keepers` input property. Changes to the `keepers` map will force the resource to regenerate its random output.
- gotcha The default random results generated by this provider are generally not suitable for cryptographic use unless explicitly stated otherwise (e.g., `RandomPassword` which uses a cryptographic random number generator).
- gotcha Choose the appropriate random resource: `RandomString` generates a random alphanumeric string, `RandomPassword` generates a sensitive random string (suitable for passwords and treated as sensitive in Pulumi state), and `RandomId` generates unique identifiers (e.g., for resource names).
- gotcha When defining dynamic provider resources, if your `Output` object contains more data elements than your `Input` (e.g., a field generated by the provider), these additional output fields might be undefined when attempting to access them later, even if they exist in the state file.
Install
-
pip install pulumi_random
Imports
- RandomPassword
from pulumi_random import RandomPassword
- pulumi_random
import pulumi_random as random
- pulumi
import pulumi
Quickstart
import pulumi
import pulumi_random as random
# Generate a random password for a database user
# The result is treated as sensitive and not displayed in console output
password = random.RandomPassword("db-password",
length=16,
special=True,
override_special="_@%",
keepers={
"purpose": "db_user_password"
}
)
pulumi.export("generated_password_result_hash", password.bcrypt_hash)