【问题标题】:how to call the resource group in virtual network the resource group parameter comes to CSV file如何在虚拟网络中调用资源组资源组参数来自CSV文件
【发布时间】:2020-08-14 09:03:14
【问题描述】:

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

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

    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] 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多