random - 在 Terraform 中创建随机资源名称

标签 random azure-storage terraform

我正在使用 Terraform 在 Azure 中创建内容,

在 ARM 中,我曾经使用 uniqueString() 来生成存储帐户名称,

那么是否可以使用 Terraform 为存储帐户生成随机名称?

最佳答案

您可以在 Terraform 中使用多种随机资源

https://www.terraform.io/docs/providers/random/index.html

资源

random_id
random_pet
random_shuffle
random_string

使用 random_id作为示例,以及resource azurerm_storage_account中的官方代码

您可以定义资源 azurerm_storage_account轻松取名。
resource "random_id" "storage_account" {
  byte_length = 8
}

resource "azurerm_storage_account" "testsa" {
  name                = "tfsta${lower(random_id.storage_account.hex)}"
  resource_group_name = "${azurerm_resource_group.testrg.name}"

  location     = "westus"
  account_type = "Standard_GRS"

  tags {
    environment = "staging"
  }
}

关于random - 在 Terraform 中创建随机资源名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46391821/

相关文章:

azure - 更改Azure存储模拟器的运行IP

azure - 如何使用 terraform 创建多个 azure 广告用户?

java - while循环输出

javascript - JS中带有随机数的时间戳

javascript - 超链接到随机 HTML 页面

python - 如何从给定范围内生成在每次执行中产生相同输出的固定随机数

azure - 使用 Azure 上传和访问图像

C# 生成 Azure 表存储 ConnectionString

azure - 对象在 Terraform 之外发生了更改,后续的 "terraform apply"删除了资源,而脚本中没有任何更改

node.js - 尽管指定了 Kubernetes 部署/服务端口,但连接端口错误