Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make UUIDv4 example RFC compliant #13229

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jobansd
Copy link

@jobansd jobansd commented Dec 13, 2024

Description

The output of the example on uuidv4 Function is not a valid RFC compliant UUIDv4. It indicates the usage of the uuidv4() function and outputs b5ee72a3-54dd-c4b8-551c-4bdc0204cedb which is not a valid UUIDv4.

I've corrected the example to output a UUIDv4 conforming to the RFC as such xxxxxxxx-xxxx-4xxx-Nxxx-xxxxxxxxxxxx, where:

  • The 13th character is always 4 (indicating version 4).
  • The 17th character must be either 8, 9, a, or b (indicating the first character of the variant).

Changes

 > uuidv4()
-  b5ee72a3-54dd-c4b8-551c-4bdc0204cedb
+  9fc99a70-7cd5-482d-bb2b-03af016e4e94

Replaces the old UUID output with a valid RFC compliant UUIDv4.

References

Misc.

To make sure this wasn't an issue with the uuidv4() function within Hashicorp's packer I tested the function in the following way:

Command executed:

> .\packer.exe inspect .\uuid.pkr.hcl

Contents of the uuid.pkr.hcl file:

locals {
  uuid_0 = uuidv4()
  uuid_1 = uuidv4()
  uuid_2 = uuidv4()
  uuid_3 = uuidv4()
  uuid_4 = uuidv4()
  uuid_5 = uuidv4()
  uuid_6 = uuidv4()
  uuid_7 = uuidv4()
  uuid_8 = uuidv4()
  uuid_9 = uuidv4()
}

Output:

Packer Inspect: HCL2 mode

> input-variables:


> local-variables:

local.uuid_0: "90877db8-5519-46ea-ae15-7dfb92594064"
local.uuid_1: "fe6a4649-97d9-4686-b981-3295175f941a"
local.uuid_2: "9944d83d-dab2-4cfb-a1db-572d19271e7a"
local.uuid_3: "547cddb7-c979-4b87-90d0-2bd9b68858b5"
local.uuid_4: "c13dc47a-552c-4dfb-a75d-2f63bb248b41"
local.uuid_5: "3db1ce29-bdde-4642-b010-1a41d47c22a3"
local.uuid_6: "4a020460-edd1-471d-b8a2-5956c0c68257"
local.uuid_7: "1845bf87-6908-4fc0-8f11-b5b4f36c60a7"
local.uuid_8: "f5c7e552-b799-45f3-8172-46162eadfd89"
local.uuid_9: "057c2eaf-6769-4a8d-90c8-775aec80496a"

> builds:

# Description

The output of the example on [uuidv4 Function](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/uuid/uuidv4) is not a valid RFC compliant UUIDv4. It indicates the usage of the `uuidv4()` function and outputs `b5ee72a3-54dd-c4b8-551c-4bdc0204cedb` which is not a valid UUIDv4.

I've corrected the example to output a UUIDv4 conforming to the RFC as such `xxxxxxxx-xxxx-4xxx-Nxxx-xxxxxxxxxxxx`, where:

- The 13th character is always `4` (indicating version 4).
- The 17th character must be either `8`, `9`, `a`, or `b` (indicating the first character of the variant).

# Changes

```diff
- b5ee72a3-54dd-c4b8-551c-4bdc0204cedb
+ 9fc99a70-7cd5-482d-bb2b-03af016e4e94
```

Replaces the old UUID output with a valid RFC compliant UUIDv4.

# References

- [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122)
- [RFC 9562](https://datatracker.ietf.org/doc/html/rfc9562)

# Misc.

To make sure this wasn't an issue with the `uuidv4()` function within Hashicorp's [packer](https://github.com/hashicorp/packer) I tested the function in the following way:

### Command executed:

```ps
> .\packer.exe inspect .\uuid.pkr.hcl
```

### Contents of the _uuid.pkr.hcl_ file:

```hcl
locals {
  uuid_0 = uuidv4()
  uuid_1 = uuidv4()
  uuid_2 = uuidv4()
  uuid_3 = uuidv4()
  uuid_4 = uuidv4()
  uuid_5 = uuidv4()
  uuid_6 = uuidv4()
  uuid_7 = uuidv4()
  uuid_8 = uuidv4()
  uuid_9 = uuidv4()
}
```

### Output:

```ps
Packer Inspect: HCL2 mode

> input-variables:


> local-variables:

local.uuid_0: "90877db8-5519-46ea-ae15-7dfb92594064"
local.uuid_1: "fe6a4649-97d9-4686-b981-3295175f941a"
local.uuid_2: "9944d83d-dab2-4cfb-a1db-572d19271e7a"
local.uuid_3: "547cddb7-c979-4b87-90d0-2bd9b68858b5"
local.uuid_4: "c13dc47a-552c-4dfb-a75d-2f63bb248b41"
local.uuid_5: "3db1ce29-bdde-4642-b010-1a41d47c22a3"
local.uuid_6: "4a020460-edd1-471d-b8a2-5956c0c68257"
local.uuid_7: "1845bf87-6908-4fc0-8f11-b5b4f36c60a7"
local.uuid_8: "f5c7e552-b799-45f3-8172-46162eadfd89"
local.uuid_9: "057c2eaf-6769-4a8d-90c8-775aec80496a"

> builds:
```
@jobansd jobansd requested review from a team as code owners December 13, 2024 16:40
Copy link

hashicorp-cla-app bot commented Dec 13, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@jobansd jobansd changed the title fix(example): make UUIDv4 example RFC compliant docs: make UUIDv4 example RFC compliant Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant