1

我觉得我的逻辑很糟糕!

我正在尝试将我的 Azure 网络组关联到我的子网

这是我的安全组配置

resource "azurerm_network_security_group" "azure_nsg" {
  depends_on = ["azurerm_virtual_network.vnet"]
  location = "${var.region}"
  name = "${var.nsg_names[count.index]}" // I think my problem is here
  resource_group_name = "${azurerm_resource_group.vnet.name}"
  count = "${length(var.nsg_names)}"
}

从这里count.index我试图导入

resource "azurerm_subnet" "subnet" {
  depends_on = ["azurerm_network_security_group.private"]
  name                      = "${var.subnet_names[count.index]}"
  virtual_network_name      = "${azurerm_virtual_network.vnet.name}"
  resource_group_name       = "${azurerm_resource_group.vnet.name}"
  address_prefix            = "${var.subnet_prefixes[count.index]}"
  network_security_group_id = "${lookup(var.nsg_ids,var.subnet_names[count.index],"")}"
  count                     = "${length(var.subnet_names)}"
}

但我无法 network_security_group_id使用 [count.index] 或地图进行访问。

 * azurerm_subnet.subnet.1: [ERROR] Unable to Parse Network Security Group ID 'databasensg': Cannot parse Azure ID: parse databasensg: invalid URI for request
    * module.azure_vnet.azurerm_subnet.subnet[2]: 1 error(s) occurred:

    * azurerm_subnet.subnet.2: [ERROR] Unable to Parse Network Security Group ID 'jumpboxnsg': Cannot parse Azure ID: parse jumpboxnsg: invalid URI for request
    * module.azure_vnet.azurerm_network_security_group.azure_nsg[1]: 1 error(s) occurred:

对于地球化专家来说,这将非常容易。

请在这里帮忙,

4

1 回答 1

0

Kiran,假设您的变量nsg_names是一个列表,您应该能够使用以下内容 -

resource "azurerm_network_security_group" "azure_nsg" {
  depends_on = ["azurerm_virtual_network.vnet"]
  location = "${var.region}"
  name = "${element(var.nsg_names, count.index)}"
  resource_group_name = "${azurerm_resource_group.vnet.name}"
  count = "${length(var.nsg_names)}"
}

您应该在其他资源中执行的其他查找中使用相同的内容。

您可以在此处阅读有关此插值函数的更多信息。

于 2018-10-15T03:01:45.120 回答