在Terraform中创建随机资源名称

kag*_*kij 3 random azure-storage terraform

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

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

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

BMW*_*BMW 6

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

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

资源资源

random_id
random_pet
random_shuffle
random_string
Run Code Online (Sandbox Code Playgroud)

使用random_id作为样本,并在官方代码资源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"
  }
}
Run Code Online (Sandbox Code Playgroud)