ID

RandomID

The random_id resource allows the creation of random IDs.


resource "random_id" "name" {
  ...
}

Attributes

Attribute
Description

ByteLength byte_length required type: int64

The number of random bytes to produce. The minimum value is 1, which produces eight bits of randomness.

byte_length = 4

Computed Attributes

These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.

Attribute
Description

Meta ID meta.id string

The full ID of the resource e.g. `resource.type.name`. This is computed from the full resource path:

// given the following resource
resource "container" "ubuntu" {
  ...
}

// the resulting id will be
resource.container.ubuntu

Meta Type meta.type string

The type of the resource. This taken from the type label of the resource definition.

// given the following resource
resource "container" "ubuntu" {
  ...
}

// the resulting type will be
container

Meta Name meta.name string

The name of the resource. This taken from the name label of the resource definition.

// given the following resource
resource "container" "ubuntu" {
  ...
}

// the resulting name will be
ubuntu

Base64 base64 type: string

The generated ID presented in base64.

Hex hex type: string

The generated ID presented in padded hexadecimal digits. This result will always be twice as long as the requested byte length.

Dec dec type: string

The generated ID presented in non-padded decimal digits.

Examples


resource "random_id" "id" {
    byte_length = 4
}

output "id_base64" {
    value = resource.random_id.meta.id.base64
}

output "id_hex" {
    value = resource.random_id.meta.id.hex
}

output "id_dec" {
    value = resource.random_id.meta.id.dec
}

Last updated