terraform icon indicating copy to clipboard operation
terraform copied to clipboard

uuid() generates UUID with incorrect version fields. Wrong V4 format

Open filol opened this issue 4 years ago • 2 comments

Terraform Version

Terraform v1.0.5

Terraform Configuration Files

output "uuid" {
  value = "${uuid()}"
}

Expected Behavior

As write here : https://www.terraform.io/docs/language/functions/uuid.html

The id is a generated and formatted as required by RFC 4122 section 4.4, producing a Version 4 UUID. The result is a UUID generated only from pseudo-random numbers.

So the uuid should respect the RFC

Actual Behavior

Terraform outputs a UUID which doesn't encode the correct RFC 4122 v4 version information, for example, 800e82e5-b042-9ebd-944c-831673b7fc5d

References

It's a duplicate of this issue #18808 but the doc is still wrong

filol avatar Aug 31 '21 22:08 filol

Thanks for reporting this, @filol!

Given that even we seem to keep confusing ourselves about having a function called uuid that doesn't actually generate a UUID, my instinct here is to reverse our previous position and switch this function to generating a standards-compliant version 4 UUID.

Something that's changed since our original discussion about this is that we ended up adding a standards-compliant UUID library to Terraform's dependencies anyway, to implement the uuidv5 function, and so making the uuid function also use that library (uuid.NewRandom, specifically) wouldn't increase our dependency burden at all.

This does mean that the result of uuid will, as a practical matter, be slightly less random than it was before, due to including the fixed version portions you're talking about here, but that shouldn't be a material difference for any reasonable existing use of this function, and our documentation has never promised that the result would be exactly 128 bits of random number. I think it's more intuitive to match the standard definition of what a UUID is, and thus allow folks to bring the same expectations they might make about version 4 UUIDs generated in other systems (122 bits of random).

apparentlymart avatar Aug 31 '21 22:08 apparentlymart

I'd still appreciate if uuid was UUIDv4 compliant

leventyalcin avatar Jun 28 '24 15:06 leventyalcin