github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/website/source/docs/providers/random/r/id.html.md (about)

     1  ---
     2  layout: "random"
     3  page_title: "Random: random_id"
     4  sidebar_current: "docs-random-resource-id"
     5  description: |-
     6    Generates a random identifier.
     7  ---
     8  
     9  # random\_id
    10  
    11  The resource `random_id` generates random numbers that are intended to be
    12  used as unique identifiers for other resources.
    13  
    14  Unlike other resources in the "random" provider, this resource *does* use a
    15  cryptographic random number generator in order to minimize the chance of
    16  collisions, making the results of this resource when a 32-byte identifier
    17  is requested of equivalent uniqueness to a type-4 UUID.
    18  
    19  This resource can be used in conjunction with resources that have,
    20  the `create_before_destroy` lifecycle flag set, to avoid conflicts with
    21  unique names during the brief period where both the old and new resources
    22  exist concurrently.
    23  
    24  ## Example Usage
    25  
    26  The following example shows how to generate a unique name for an AWS EC2
    27  instance that changes each time a new AMI id is selected.
    28  
    29  ```hcl
    30  resource "random_id" "server" {
    31    keepers = {
    32      # Generate a new id each time we switch to a new AMI id
    33      ami_id = "${var.ami_id}"
    34    }
    35  
    36    byte_length = 8
    37  }
    38  
    39  resource "aws_instance" "server" {
    40    tags = {
    41      Name = "web-server ${random_id.server.hex}"
    42    }
    43  
    44    # Read the AMI id "through" the random_id resource to ensure that
    45    # both will change together.
    46    ami = "${random_id.server.keepers.ami_id}"
    47  
    48    # ... (other aws_instance arguments) ...
    49  }
    50  ```
    51  
    52  ## Argument Reference
    53  
    54  The following arguments are supported:
    55  
    56  * `byte_length` - (Required) The number of random bytes to produce. The
    57    minimum value is 1, which produces eight bits of randomness.
    58  
    59  * `keepers` - (Optional) Arbitrary map of values that, when changed, will
    60    trigger a new id to be generated. See
    61    [the main provider documentation](../index.html) for more information.
    62  
    63  * `prefix` - (Optional) Arbitrary string to prefix the output value with. This
    64    string is supplied as-is, meaning it is not guaranteed to be URL-safe or
    65    base64 encoded.
    66  
    67  ## Attributes Reference
    68  
    69  The following attributes are exported:
    70  
    71  * `b64` - The generated id presented in base64, using the URL-friendly character set: case-sensitive letters, digits and the characters `_` and `-`.
    72  * `hex` - The generated id presented in padded hexadecimal digits. This result will always be twice as long as the requested byte length.
    73  * `dec` - The generated id presented in non-padded decimal digits.