我正在使用 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/