mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-21 10:47:34 -05:00
Over time the discussion about "lifecycle" blocks in the documentation became confusing because the docs originally written for managed resource lifecycle got partially generalized for resources of other modes and for module calls, even though each of those has a completely different lifecycle and thus a different set of lifecycle settings. This is a first pass at trying to reorganize that so that the "lifecycle" page is really just an index of all of the different kinds of lifecycle block that exist in the language, while the main documentation for each use of that block type now belongs with the documentation of the block it's nested within. While working on this I also found that there was some duplication inside the "data sources" page where the same information was described multiple times, and a few other cases where things had become inconsistent over time. This also includes a little extra content to try to clarify the difference between managed, data, and ephemeral resources and to make it explicit that the "Resources" section is focused only on managed resources because that is the primary resource mode. As usual there's lots more that could be done here -- this documentation has gradually evolved over time and is full of weird quirks due to that evolution -- but I decided to draw a line here so that the diff wouldn't get too large. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
38 lines
1.4 KiB
Plaintext
38 lines
1.4 KiB
Plaintext
---
|
|
sidebar_label: uuid
|
|
description: The uuid function generates a unique id.
|
|
---
|
|
|
|
# `uuid` Function
|
|
|
|
`uuid` generates a unique identifier string.
|
|
|
|
The id is generated and formatted as required by
|
|
[RFC 4122 section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4),
|
|
producing a Version 4 UUID. The result is a UUID generated only from
|
|
pseudorandom numbers.
|
|
|
|
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.
|