hashicorp / hashicorp/terraform-plugin-sdk
Rethink length of suffix generated by resource.PrefixedUniqueId
- Dominant language
- Go
- Stars
- 485
- Forks
- 244
- Avg merge
- 19h 57m
- Merged PRs (30d)
- 4
Description
Hi all,
I had some instances where name_prefix ended up being something very limiting (not entirely your fault, limits on the cloud platform too) and having to use a random_id instead, as a result of the (unnecessarily long IMHO) UniqueId suffix generated by tf.
Do you really need to set such a long unique Id?
I, personally, don't need or see the point for a timestamp, plus an index, plus 'terraform' word.
You could shorten this by using shorter versions of the values you propose, and a smaller max value for the index (4294967295 updates would probably be a hefty amount of years beyond the life expectancy of this tech :P).
Sample:
```go
package main
import (
"fmt"
"strings"
"time"
)
func main() {
var old_idx uint32
old_str := "terraform-"
old_t := strings.Replace(time.Now().UTC().Format("20060102150405.0000"), ".", "", 1)
old_idx = 4294967295
var new_idx uint32
new_str := "tf"
new_t := time.Now().UTC().Unix()
new_idx = 16777215
fmt.Printf("Old suffix is %s%s%08x\n", old_str, old_t, old_idx)
fmt.Printf("New suffix is %s%v%06x\n", new_str, new_t, new_idx)
}
```
Output:
```
Old suffix is terraform-202006141048156188ffffffff
New suffix is tf1592131695ffffff
```
Readability counts I agree... but there is a boundary between it and practicality :)
Thank you,
Ed
Contributor guide
Research direction
Start at the resource.PrefixedUniqueId entry point and trace how the timestamp, index, and Terraform prefix are assembled. Compare the current suffix with the proposed shorter format, then determine and document the accepted format and its compatibility implications before implementing and validating the change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100