0

我正在尝试以相同的代码访问虚拟网络中的资源组名称,已经使用 CSV 文件定义了一些参数,但是当我在代码中调用该参数时,它显示错误,

请检查以下代码

provider "azurerm" {
    features {}
}

locals {
 group_names = csvdecode(file("./test.csv"))
}

//Create a resource group and nsg

resource "azurerm_resource_group" "Customer" {
  count = length(local.group_names)
  name  = local.group_names[count.index].resource_group_name
  location = local.group_names[count.index].region
} 


//Create a Vnet
resource "azurerm_virtual_network" "Customer" {
  count               = length(local.group_names)
  name                = local.group_names[count.index].virtual_network_name
  location            = azurerm_resource_group.Customer.location 
  resource_group_name = azurerm_resource_group.Customer.name
  address_space       = [local.group_names[count.index].address_space] 
}

//create Subnet
resource "azurerm_subnet" "Customer" {
  count                = length(local.group_names)
  name                 = local.group_names[count.index].subnet_name
  resource_group_name  = azurerm_resource_group.Customer.name                                           
  virtual_network_name = azurerm_virtual_network.Customer.name                         
  address_prefix       = local.group_names[count.index].address_prefix_subnet   
}

发生以下错误

4

1 回答 1

0

如错误所示,您可以像这样更改代码

resource "azurerm_virtual_network" "Customer" {
  count               = length(local.group_names)
  name                = local.group_names[count.index].virtual_network_name
  location            = azurerm_resource_group.Customer[count.index].location # add [count.index]
  resource_group_name = azurerm_resource_group.Customer[count.index].name  # add [count.index]
  address_space       = [local.group_names[count.index].address_space] 
}
于 2020-04-30T10:16:30.660 回答