使用 terraform,如何使用 Azure 的 list/count 创建具有唯一且不同名称的多个相同类型的资源?

2024-01-08

这是我想要实现的目标的一个基本示例。我有两个文件(main.tf)和(variable.tf),我想创建两个资源组,变量文件中是我希望资源组占用的名称列表。第一个资源组的名字,以后类似。 所以请帮助我了解如何实现它。我正在使用 terraform v0.13。

main.tf 文件:

provider "azurerm" {
 features {}
}


resource "azurerm_resource_group" "test" {
  count    = 2
  name     = var.resource_group_name
  location = var.location
}

变量.tf 文件:

  variable "resource_group_name" {
  description = "Default resource group name that the network will be created in."
  type        = list
  default     = ["asd-rg","asd2-rg"]

}



variable "location" {
  description = "The location/region where the core network will be created.
  default     = "westus"
}

您只需要像这样更改资源组块:

resource "azurerm_resource_group" "test" {
  count    = 2
  name     = element(var.resource_group_name, count.index)
  location = var.location
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 terraform,如何使用 Azure 的 list/count 创建具有唯一且不同名称的多个相同类型的资源? 的相关文章

随机推荐