Dynamic tag at each plan

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?

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?

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.

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?

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
}