如何在虚拟网络中调用资源组,资源组参数进入CSV文件

问题描述 投票:0回答:1

我正在尝试使用相同的代码访问虚拟网络中的资源组名称,已使用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   
}

following error is occured

terraform interrupt-handling terraform-provider-azure terraform-template-file terraform0.12+
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] }

© www.soinside.com 2019 - 2024. All rights reserved.