mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-22 19:00:35 -04:00
45 lines
1.7 KiB
Plaintext
45 lines
1.7 KiB
Plaintext
---
|
|
sidebar_label: uuid
|
|
description: The uuid function generates a unique id.
|
|
---
|
|
|
|
# `uuid` Function
|
|
|
|
`uuid` generates a unique identifier string.
|
|
|
|
The result is 16 random bytes formatted in the UUID string layout
|
|
(`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`). All 128 bits are
|
|
pseudorandom — the function does **not** set the version or variant
|
|
bits described in [RFC 4122](https://tools.ietf.org/html/rfc4122),
|
|
so the output is not a standards-compliant Version 4 UUID.
|
|
|
|
:::note
|
|
If you need standards-compliant UUIDs (for example, Version 4 or
|
|
Version 7), consider using a provider that exposes UUID generation
|
|
through [provider-defined functions](../../language/functions/index.mdx#provider-defined-functions).
|
|
:::
|
|
|
|
This function produces a new value each time it is called, and so using it
|
|
directly in resource arguments will result in spurious diffs. We do not
|
|
recommend using the `uuid` function in resource configurations, but it can
|
|
be used with care in conjunction with
|
|
[the `ignore_changes` lifecycle meta-argument](../../language/resources/behavior.mdx#ignore_changes).
|
|
|
|
In most cases we recommend using [the `random` provider](https://registry.terraform.io/providers/hashicorp/random/latest/docs)
|
|
instead, since it allows the one-time generation of random values that are
|
|
then retained in the OpenTofu [state](../../language/state/index.mdx) for use by
|
|
future operations. In particular,
|
|
[`random_id`](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) can generate results with
|
|
equivalent randomness to the `uuid` function.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> uuid()
|
|
b5ee72a3-54dd-c4b8-551c-4bdc0204cedb
|
|
```
|
|
|
|
## Related Functions
|
|
|
|
* [`uuidv5`](../../language/functions/uuidv5.mdx), which generates name-based UUIDs.
|