如何在虚拟网络中调用资源组资源组参数来CSV文件
how to call the resource group in virtual network the resource group parameter comes to CSV file
我试图在同一代码中访问虚拟网络中的资源组名称,使用 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
如错误所示,您可以像这样更改代码
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]
}
我试图在同一代码中访问虚拟网络中的资源组名称,使用 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
如错误所示,您可以像这样更改代码
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]
}