The resource random.RandomUuid4 generates a random version 4 uuid string that is intended to be used as a unique identifier for other resources.
This resource uses google/uuid to generate a valid V4 UUID for use with services needing a unique string identifier.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as azurerm from "@pulumi/azurerm";
import * as random from "@pulumi/random";
// The following example shows how to generate a unique name for an Azure Resource Group.
const test = new random.RandomUuid4("test", {});
const testResourceGroup = new azurerm.index.ResourceGroup("test", {
name: `${test.result}-rg`,
location: "Central US",
});
import pulumi
import pulumi_azurerm as azurerm
import pulumi_random as random
# The following example shows how to generate a unique name for an Azure Resource Group.
test = random.RandomUuid4("test")
test_resource_group = azurerm.index.ResourceGroup("test",
name=f{test.result}-rg,
location=Central US)
package main
import (
"fmt"
"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 {
// The following example shows how to generate a unique name for an Azure Resource Group.
test, err := random.NewRandomUuid4(ctx, "test", nil)
if err != nil {
return err
}
_, err = azurerm.NewResourceGroup(ctx, "test", &azurerm.ResourceGroupArgs{
Name: pulumi.Sprintf("%v-rg", test.Result),
Location: "Central US",
})
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(() =>
{
// The following example shows how to generate a unique name for an Azure Resource Group.
var test = new Random.RandomUuid4("test");
var testResourceGroup = new Azurerm.Index.ResourceGroup("test", new()
{
Name = $"{test.Result}-rg",
Location = "Central US",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.random.RandomUuid4;
import com.pulumi.azurerm.ResourceGroup;
import com.pulumi.azurerm.ResourceGroupArgs;
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) {
// The following example shows how to generate a unique name for an Azure Resource Group.
var test = new RandomUuid4("test");
var testResourceGroup = new ResourceGroup("testResourceGroup", ResourceGroupArgs.builder()
.name(String.format("%s-rg", test.result()))
.location("Central US")
.build());
}
}
resources:
# The following example shows how to generate a unique name for an Azure Resource Group.
test:
type: random:RandomUuid4
testResourceGroup:
type: azurerm:ResourceGroup
name: test
properties:
name: ${test.result}-rg
location: Central US
Create RandomUuid4 Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new RandomUuid4(name: string, args?: RandomUuid4Args, opts?: CustomResourceOptions);@overload
def RandomUuid4(resource_name: str,
args: Optional[RandomUuid4Args] = None,
opts: Optional[ResourceOptions] = None)
@overload
def RandomUuid4(resource_name: str,
opts: Optional[ResourceOptions] = None,
keepers: Optional[Mapping[str, str]] = None)func NewRandomUuid4(ctx *Context, name string, args *RandomUuid4Args, opts ...ResourceOption) (*RandomUuid4, error)public RandomUuid4(string name, RandomUuid4Args? args = null, CustomResourceOptions? opts = null)
public RandomUuid4(String name, RandomUuid4Args args)
public RandomUuid4(String name, RandomUuid4Args args, CustomResourceOptions options)
type: random:RandomUuid4
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 RandomUuid4Args
- 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 RandomUuid4Args
- 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 RandomUuid4Args
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args RandomUuid4Args
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args RandomUuid4Args
- 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 randomUuid4Resource = new Random.RandomUuid4("randomUuid4Resource", new()
{
Keepers =
{
{ "string", "string" },
},
});
example, err := random.NewRandomUuid4(ctx, "randomUuid4Resource", &random.RandomUuid4Args{
Keepers: pulumi.StringMap{
"string": pulumi.String("string"),
},
})
var randomUuid4Resource = new RandomUuid4("randomUuid4Resource", RandomUuid4Args.builder()
.keepers(Map.of("string", "string"))
.build());
random_uuid4_resource = random.RandomUuid4("randomUuid4Resource", keepers={
"string": "string",
})
const randomUuid4Resource = new random.RandomUuid4("randomUuid4Resource", {keepers: {
string: "string",
}});
type: random:RandomUuid4
properties:
keepers:
string: string
RandomUuid4 Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The RandomUuid4 resource accepts the following input properties:
- Keepers Dictionary<string, string>
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- Keepers map[string]string
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- keepers Map<String,String>
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- keepers {[key: string]: string}
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- keepers Mapping[str, str]
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
- 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 RandomUuid4 resource produces the following output properties:
Look up Existing RandomUuid4 Resource
Get an existing RandomUuid4 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?: RandomUuid4State, opts?: CustomResourceOptions): RandomUuid4@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
keepers: Optional[Mapping[str, str]] = None,
result: Optional[str] = None) -> RandomUuid4func GetRandomUuid4(ctx *Context, name string, id IDInput, state *RandomUuid4State, opts ...ResourceOption) (*RandomUuid4, error)public static RandomUuid4 Get(string name, Input<string> id, RandomUuid4State? state, CustomResourceOptions? opts = null)public static RandomUuid4 get(String name, Output<String> id, RandomUuid4State state, CustomResourceOptions options)resources: _: type: random:RandomUuid4 get: id: ${id}- 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.
Import
The pulumi import command can be used, for example:
Random UUID’s can be imported. This can be used to replace a config
value with a value interpolated from the random provider without
experiencing diffs.
$ pulumi import random:index/randomUuid4:RandomUuid4 main 7e4436da-7c71-486e-a57c-830b25fff7bd
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
randomTerraform Provider.
