diff --git a/lang/funcs/crypto.go b/lang/funcs/crypto.go index 99e9422c1db5..be006f821c7d 100644 --- a/lang/funcs/crypto.go +++ b/lang/funcs/crypto.go @@ -57,7 +57,9 @@ var UUIDV5Func = function.New(&function.Spec{ case args[0].AsString() == "x500": namespace = uuidv5.NamespaceX500 default: - return cty.UnknownVal(cty.String), fmt.Errorf("uuidv5() doesn't support namespace %s", args[0].AsString()) + if namespace, err = uuidv5.FromString(args[0].AsString()); err != nil { + return cty.UnknownVal(cty.String), fmt.Errorf("uuidv5() doesn't support namespace %s (%v)", args[0].AsString(), err) + } } val := args[1].AsString() return cty.StringVal(uuidv5.NewV5(namespace, val).String()), nil diff --git a/lang/funcs/crypto_test.go b/lang/funcs/crypto_test.go index ef2a3215ff4a..a79b67f17056 100644 --- a/lang/funcs/crypto_test.go +++ b/lang/funcs/crypto_test.go @@ -51,6 +51,12 @@ func TestUUIDV5(t *testing.T) { cty.StringVal("7e12415e-f7c9-57c3-9e43-52dc9950d264"), false, }, + { + cty.StringVal("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), + cty.StringVal("tada"), + cty.StringVal("faa898db-9b9d-5b75-86a9-149e7bb8e3b8"), + false, + }, { cty.StringVal("tada"), cty.StringVal("tada"), diff --git a/lang/functions_test.go b/lang/functions_test.go index 4add9cf9f70b..cbf3d25cf578 100644 --- a/lang/functions_test.go +++ b/lang/functions_test.go @@ -759,6 +759,10 @@ func TestFunctions(t *testing.T) { `uuidv5("x500", "tada")`, cty.StringVal("7e12415e-f7c9-57c3-9e43-52dc9950d264"), }, + { + `uuidv5("6ba7b810-9dad-11d1-80b4-00c04fd430c8", "tada")`, + cty.StringVal("faa898db-9b9d-5b75-86a9-149e7bb8e3b8"), + }, }, "values": { diff --git a/website/docs/configuration/functions/uuidv5.html.md b/website/docs/configuration/functions/uuidv5.html.md index beba8e1f9d2b..ca4c82d7d9f3 100644 --- a/website/docs/configuration/functions/uuidv5.html.md +++ b/website/docs/configuration/functions/uuidv5.html.md @@ -12,7 +12,8 @@ description: |- earlier, see [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). -`uuidv5` generates a uuid v5 string representation of the value in the specified namespace. +`uuidv5` generates a uuid v5 string representation of the value in the specified namespace. Following namespace shortcuts are defined: +`dns`, `url`, `oid`, `x500`, but You can also specify a custom namespace in uuid format, e.g. `6ba7b810-9dad-11d1-80b4-00c04fd430c8`. The id is a generated and formatted as required by [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), @@ -33,4 +34,7 @@ af9d40a5-7a36-5c07-b23a-851cd99fbfa5 > uuidv5("x500", "io.terraform.www") 3ebe33fd-b2a1-546b-9867-2ca38768d5d6 +> uuidv5("6ba7b810-9dad-11d1-80b4-00c04fd430c8", "www.terraform.io") +a5008fae-b28c-5ba5-96cd-82b4c53552d6 + ```