Allan Xu
Allan Xu

Reputation: 9298

Looking for techniques to add suffix to resources to make their name unique

I am creatig a few azure resources (Such as storage accounts) that their name must be unique accross Azure.

Is there any technique in Terraform scripting that allows adding a random string to the end of resources so their name become uniqu accorss Azure?

What is the common pattern to deal with this requirement?

Upvotes: 2

Views: 4366

Answers (2)

Christian Pearce
Christian Pearce

Reputation: 1026

If you are using Azure there is a really descent Naming module. It helps with consistent and randomized naming. You can reference it here.

Upvotes: 1

FN_
FN_

Reputation: 853

Sure yes, you can create resource random_string and use in in names:

resource "random_string" "random" {
  length = 16
  special = true
  override_special = "/@£$"
}

resource "aws_ecr_repository" "foo" {
  name                 = "bar-${random_string.random.result}"
  ...
}

https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string

Upvotes: 3

Related Questions