Skip to content

Commit

Permalink
helper: Add resource.PrefixedUniqueId
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Simko committed Jun 30, 2015
1 parent 282e139 commit 70b7243
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions helper/resource/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import (

const UniqueIdPrefix = `terraform-`

// Helper for a resource to generate a unique identifier
// Helper for a resource to generate a unique identifier w/ default prefix
func UniqueId() string {
return PrefixedUniqueId(UniqueIdPrefix)
}

// Helper for a resource to generate a unique identifier w/ given prefix
//
// This uses a simple RFC 4122 v4 UUID with some basic cosmetic filters
// applied (base32, remove padding, downcase) to make visually distinguishing
// identifiers easier.
func UniqueId() string {
return fmt.Sprintf("%s%s", UniqueIdPrefix,
func PrefixedUniqueId(prefix string) string {
return fmt.Sprintf("%s%s", prefix,
strings.ToLower(
strings.Replace(
base32.StdEncoding.EncodeToString(uuidV4()),
Expand Down

0 comments on commit 70b7243

Please sign in to comment.