I have something like this
resource “random_string” “rss” {
lower=true
}
tag {
key = “mykey”
value = “${random_string.rss.result}”
}
Everytime I launch terraform plan and apply the key is always the same random string. Is there a way to dynamically have it genrate another random string at each plan/apply?
maxb
May 5, 2022, 8:21pm
2
The Terraform builtin function uuid() might suit your purpose?
The UUID is too long. I need my value to be only 5 characters and lower case.
Also, for every launch is a new UUID created?
maxb
May 5, 2022, 8:28pm
4
Take just a 5 character substring of a UUID, then?
for every launch is a new UUID created?
I have some other requirements for my random string.
maxb
May 5, 2022, 9:00pm
6
Please read the documentation I provided a link to:
This function produces a new value each time it is called
ok, how can I trim it and have the first charcter be a [a-z]? Is there a way to enforce that?
maxb
May 5, 2022, 10:13pm
8
No, there isn’t. UUIDs are composed of hexadecimal characters and dashes.
Ok. Maybe there is another way than UUIDs
Anyone have a way to acheive this?
You can use the uuid function as a value in the keepers argument to the random_string resource to cause it to be recreated on every plan. Like so:
resource "random_string" "rss" {
lower = true
length = 5
keepers = {
uuid = uuid()
}
}
output "rss" {
value = random_string.rss.id
}