generated by https://github.com/hashicorp/terraform-plugin-docs

page_title: “random_id Resource - terraform-provider-random” subcategory: "" description: |- The resource random_id 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_bytes 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.

random_id (Resource)

The resource random_id 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_bytes 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

# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug
from constructs import Construct
from cdktf import Fn, Token, TerraformStack
#
# Provider bindings are generated by running `cdktf get`.
# See https://cdk.tf/provider-generation for more details.
#
from imports.aws.instance import Instance
from imports.random.id import Id
class MyConvertedCode(TerraformStack):
    def __init__(self, scope, name):
        super().__init__(scope, name)
        server = Id(self, "server",
            byte_length=8,
            keepers={
                "ami_id": ami_id.string_value
            }
        )
        aws_instance_server = Instance(self, "server_1",
            ami=Token.as_string(Fn.lookup_nested(server, ["keepers", "ami_id"])),
            tags={
                "Name": "web-server ${" + server.hex + "}"
            }
        )
        # This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.
        aws_instance_server.override_logical_id("server")

Schema

Required

  • byte_length (Number) The number of random bytes to produce. The minimum value is 1, which produces eight bits of randomness.

Optional

  • keepers (Map of String) Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
  • prefix (String) 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.

Read-Only

  • b64_std (String) The generated id presented in base64 without additional transformations.
  • b64_url (String) The generated id presented in base64, using the URL-friendly character set: case-sensitive letters, digits and the characters _ and -.
  • dec (String) The generated id presented in non-padded decimal digits.
  • hex (String) The generated id presented in padded hexadecimal digits. This result will always be twice as long as the requested byte length.
  • id (String) The generated id presented in base64 without additional transformations or prefix.

Import

Import is supported using the following syntax:

# 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:
terraform import random_id.server p-9hUg

# Example with prefix (prefix is separated by a ,):
$ terraform import random_id.server my-prefix-,p-9hUg