1. Packages
  2. Random
  3. API Docs
  4. RandomBytes
random v4.16.6 published on Tuesday, Sep 24, 2024 by Pulumi

random.RandomBytes

Explore with Pulumi AI

random logo
random v4.16.6 published on Tuesday, Sep 24, 2024 by Pulumi

    The resource random.RandomBytes generates random bytes that are intended to be used as a secret, or key. Use this in preference to random.RandomId when the output is considered sensitive, and should not be displayed in the CLI.

    This resource does use a cryptographic random number generator.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as azurerm from "@pulumi/azurerm";
    import * as random from "@pulumi/random";
    
    const jwtSecret = new random.RandomBytes("jwt_secret", {length: 64});
    const jwtSecretKeyVaultSecret = new azurerm.index.KeyVaultSecret("jwt_secret", {
        keyVaultId: "some-azure-key-vault-id",
        name: "JwtSecret",
        value: jwtSecret.base64,
    });
    
    import pulumi
    import pulumi_azurerm as azurerm
    import pulumi_random as random
    
    jwt_secret = random.RandomBytes("jwt_secret", length=64)
    jwt_secret_key_vault_secret = azurerm.index.KeyVaultSecret("jwt_secret",
        key_vault_id=some-azure-key-vault-id,
        name=JwtSecret,
        value=jwt_secret.base64)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azurerm/sdk/go/azurerm"
    	"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 {
    		jwtSecret, err := random.NewRandomBytes(ctx, "jwt_secret", &random.RandomBytesArgs{
    			Length: pulumi.Int(64),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = azurerm.NewKeyVaultSecret(ctx, "jwt_secret", &azurerm.KeyVaultSecretArgs{
    			KeyVaultId: "some-azure-key-vault-id",
    			Name:       "JwtSecret",
    			Value:      jwtSecret.Base64,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Azurerm = Pulumi.Azurerm;
    using Random = Pulumi.Random;
    
    return await Deployment.RunAsync(() => 
    {
        var jwtSecret = new Random.RandomBytes("jwt_secret", new()
        {
            Length = 64,
        });
    
        var jwtSecretKeyVaultSecret = new Azurerm.Index.KeyVaultSecret("jwt_secret", new()
        {
            KeyVaultId = "some-azure-key-vault-id",
            Name = "JwtSecret",
            Value = jwtSecret.Base64,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.random.RandomBytes;
    import com.pulumi.random.RandomBytesArgs;
    import com.pulumi.azurerm.keyVaultSecret;
    import com.pulumi.azurerm.KeyVaultSecretArgs;
    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 jwtSecret = new RandomBytes("jwtSecret", RandomBytesArgs.builder()
                .length(64)
                .build());
    
            var jwtSecretKeyVaultSecret = new KeyVaultSecret("jwtSecretKeyVaultSecret", KeyVaultSecretArgs.builder()
                .keyVaultId("some-azure-key-vault-id")
                .name("JwtSecret")
                .value(jwtSecret.base64())
                .build());
    
        }
    }
    
    resources:
      jwtSecret:
        type: random:RandomBytes
        name: jwt_secret
        properties:
          length: 64
      jwtSecretKeyVaultSecret:
        type: azurerm:keyVaultSecret
        name: jwt_secret
        properties:
          keyVaultId: some-azure-key-vault-id
          name: JwtSecret
          value: ${jwtSecret.base64}
    

    Create RandomBytes Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new RandomBytes(name: string, args: RandomBytesArgs, opts?: CustomResourceOptions);
    @overload
    def RandomBytes(resource_name: str,
                    args: RandomBytesArgs,
                    opts: Optional[ResourceOptions] = None)
    
    @overload
    def RandomBytes(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    length: Optional[int] = None,
                    keepers: Optional[Mapping[str, str]] = None)
    func NewRandomBytes(ctx *Context, name string, args RandomBytesArgs, opts ...ResourceOption) (*RandomBytes, error)
    public RandomBytes(string name, RandomBytesArgs args, CustomResourceOptions? opts = null)
    public RandomBytes(String name, RandomBytesArgs args)
    public RandomBytes(String name, RandomBytesArgs args, CustomResourceOptions options)
    
    type: random:RandomBytes
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args RandomBytesArgs
    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 RandomBytesArgs
    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 RandomBytesArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args RandomBytesArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args RandomBytesArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var randomBytesResource = new Random.RandomBytes("randomBytesResource", new()
    {
        Length = 0,
        Keepers = 
        {
            { "string", "string" },
        },
    });
    
    example, err := random.NewRandomBytes(ctx, "randomBytesResource", &random.RandomBytesArgs{
    	Length: pulumi.Int(0),
    	Keepers: pulumi.StringMap{
    		"string": pulumi.String("string"),
    	},
    })
    
    var randomBytesResource = new RandomBytes("randomBytesResource", RandomBytesArgs.builder()
        .length(0)
        .keepers(Map.of("string", "string"))
        .build());
    
    random_bytes_resource = random.RandomBytes("randomBytesResource",
        length=0,
        keepers={
            "string": "string",
        })
    
    const randomBytesResource = new random.RandomBytes("randomBytesResource", {
        length: 0,
        keepers: {
            string: "string",
        },
    });
    
    type: random:RandomBytes
    properties:
        keepers:
            string: string
        length: 0
    

    RandomBytes Resource Properties

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

    Inputs

    The RandomBytes resource accepts the following input properties:

    Length int
    The number of bytes requested. The minimum value for length is 1.
    Keepers Dictionary<string, string>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The number of bytes requested. The minimum value for length is 1.
    Keepers map[string]string
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Integer
    The number of bytes requested. The minimum value for length is 1.
    keepers Map<String,String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length number
    The number of bytes requested. The minimum value for length is 1.
    keepers {[key: string]: string}
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length int
    The number of bytes requested. The minimum value for length is 1.
    keepers Mapping[str, str]
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Number
    The number of bytes requested. The minimum value for length is 1.
    keepers Map<String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.

    Outputs

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

    Base64 string
    The generated bytes presented in base64 string format.
    Hex string
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    Id string
    The provider-assigned unique ID for this managed resource.
    Base64 string
    The generated bytes presented in base64 string format.
    Hex string
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    Id string
    The provider-assigned unique ID for this managed resource.
    base64 String
    The generated bytes presented in base64 string format.
    hex String
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    id String
    The provider-assigned unique ID for this managed resource.
    base64 string
    The generated bytes presented in base64 string format.
    hex string
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    id string
    The provider-assigned unique ID for this managed resource.
    base64 str
    The generated bytes presented in base64 string format.
    hex str
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    id str
    The provider-assigned unique ID for this managed resource.
    base64 String
    The generated bytes presented in base64 string format.
    hex String
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing RandomBytes Resource

    Get an existing RandomBytes 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?: RandomBytesState, opts?: CustomResourceOptions): RandomBytes
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            base64: Optional[str] = None,
            hex: Optional[str] = None,
            keepers: Optional[Mapping[str, str]] = None,
            length: Optional[int] = None) -> RandomBytes
    func GetRandomBytes(ctx *Context, name string, id IDInput, state *RandomBytesState, opts ...ResourceOption) (*RandomBytes, error)
    public static RandomBytes Get(string name, Input<string> id, RandomBytesState? state, CustomResourceOptions? opts = null)
    public static RandomBytes get(String name, Output<String> id, RandomBytesState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    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.
    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:
    Base64 string
    The generated bytes presented in base64 string format.
    Hex string
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    Keepers Dictionary<string, string>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The number of bytes requested. The minimum value for length is 1.
    Base64 string
    The generated bytes presented in base64 string format.
    Hex string
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    Keepers map[string]string
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    Length int
    The number of bytes requested. The minimum value for length is 1.
    base64 String
    The generated bytes presented in base64 string format.
    hex String
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    keepers Map<String,String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Integer
    The number of bytes requested. The minimum value for length is 1.
    base64 string
    The generated bytes presented in base64 string format.
    hex string
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    keepers {[key: string]: string}
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length number
    The number of bytes requested. The minimum value for length is 1.
    base64 str
    The generated bytes presented in base64 string format.
    hex str
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    keepers Mapping[str, str]
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length int
    The number of bytes requested. The minimum value for length is 1.
    base64 String
    The generated bytes presented in base64 string format.
    hex String
    The generated bytes presented in lowercase hexadecimal string format. The length of the encoded string is exactly twice the length parameter.
    keepers Map<String>
    Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
    length Number
    The number of bytes requested. The minimum value for length is 1.

    Import

    Random bytes can be imported by specifying the value as base64 string.

    $ pulumi import random:index/randomBytes:RandomBytes basic "8/fu3q+2DcgSJ19i0jZ5Cw=="
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    random pulumi/pulumi-random
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the random Terraform Provider.
    random logo
    random v4.16.6 published on Tuesday, Sep 24, 2024 by Pulumi