Package com.pulumi.random
Class RandomId
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.random.RandomId
-
public class RandomId extends com.pulumi.resources.CustomResourceThe resource `random.RandomId` generates random numbers that are intended to be used as unique identifiers for other resources. If the output is considered sensitive, and should not be displayed in the CLI, use `random.RandomBytes` instead. This resource *does* use a cryptographic random number generator in order to minimize the chance of collisions, making the results of this resource when a 16-byte identifier is requested of equivalent uniqueness to a type-4 UUID. This resource can be used in conjunction with resources that have the `create_before_destroy` lifecycle flag set to avoid conflicts with unique names during the brief period where both the old and new resources exist concurrently. ## Example Usage ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.random.RandomId; import com.pulumi.random.RandomIdArgs; import com.pulumi.aws.ec2.Instance; import com.pulumi.aws.ec2.InstanceArgs; 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 serverRandomId = new RandomId("serverRandomId", RandomIdArgs.builder() .keepers(Map.of("ami_id", var_.ami_id())) .byteLength(8) .build()); var serverInstance = new Instance("serverInstance", InstanceArgs.builder() .tags(Map.of("Name", serverRandomId.hex().applyValue(hex -> String.format("web-server %s", hex)))) .ami(serverRandomId.keepers().applyValue(keepers -> keepers.amiId())) .build()); } } ``` ## Import Random IDs can be imported using the b64_url with an optional prefix. This can be used to replace a config value with a value interpolated from the random provider without experiencing diffs. Example with no prefix ```sh $ pulumi import random:index/randomId:RandomId server p-9hUg ``` Example with prefix (prefix is separated by a ,) ```sh $ pulumi import random:index/randomId:RandomId server my-prefix-,p-9hUg ```
-
-
Constructor Summary
Constructors Constructor Description RandomId(java.lang.String name)RandomId(java.lang.String name, RandomIdArgs args)RandomId(java.lang.String name, RandomIdArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.pulumi.core.Output<java.lang.String>b64Std()com.pulumi.core.Output<java.lang.String>b64Url()com.pulumi.core.Output<java.lang.Integer>byteLength()com.pulumi.core.Output<java.lang.String>dec()static RandomIdget(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, RandomIdState state, com.pulumi.resources.CustomResourceOptions options)Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.com.pulumi.core.Output<java.lang.String>hex()com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>>keepers()com.pulumi.core.Output<java.util.Optional<java.lang.String>>prefix()
-
-
-
Constructor Detail
-
RandomId
public RandomId(java.lang.String name)
- Parameters:
name- The _unique_ name of the resulting resource.
-
RandomId
public RandomId(java.lang.String name, RandomIdArgs args)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.
-
RandomId
public RandomId(java.lang.String name, RandomIdArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.options- A bag of options that control this resource's behavior.
-
-
Method Detail
-
b64Std
public com.pulumi.core.Output<java.lang.String> b64Std()
- Returns:
- The generated id presented in base64 without additional transformations.
-
b64Url
public com.pulumi.core.Output<java.lang.String> b64Url()
- Returns:
- The generated id presented in base64, using the URL-friendly character set: case-sensitive letters, digits and the characters `_` and `-`.
-
byteLength
public com.pulumi.core.Output<java.lang.Integer> byteLength()
- Returns:
- The number of random bytes to produce. The minimum value is 1, which produces eight bits of randomness.
-
dec
public com.pulumi.core.Output<java.lang.String> dec()
- Returns:
- The generated id presented in non-padded decimal digits.
-
hex
public com.pulumi.core.Output<java.lang.String> hex()
- Returns:
- The generated id presented in padded hexadecimal digits. This result will always be twice as long as the requested byte length.
-
keepers
public com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>> keepers()
- Returns:
- Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
-
prefix
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> prefix()
- Returns:
- Arbitrary string to prefix the output value with. This string is supplied as-is, meaning it is not guaranteed to be URL-safe or base64 encoded.
-
get
public static RandomId get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable RandomIdState state, @Nullable com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.- Parameters:
name- The _unique_ name of the resulting resource.id- The _unique_ provider ID of the resource to lookup.state-options- Optional settings to control the behavior of the CustomResource.
-
-