How to Generate a Random Number/String in Terraform


If you need to generate a random number or string in Terraform, then you can use the following:

resource "random_id" "myrandom" {
  keepers = {
    first = "${timestamp()}"
  }     
  byte_length = 8
}

Then refer to it as:

random_id.myrandom.hex