寻找为资源添加后缀以使其名称独一无二的技术

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

我正在创建一些 Azure 资源(例如存储帐户),它们的名称在整个 Azure 中必须是唯一的。

Terraform 脚本中是否有任何技术允许将随机字符串添加到资源的末尾,以便它们的名称在 Azure 中变得唯一?

处理此要求的常用模式是什么?

当然可以,您可以创建资源 random_string 并在名称中使用:

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

如果您使用的是 Azure,则有一个真正的命名模块。它有助于一致和随机命名。大家可以参考一下here.