Azure 使用 Terraform 将安全组与多个网络接口(interface)和负载均衡器与多个子网关联

标签 azure azure-devops cloud terraform-provider-azure

我使用 Terraform 在 Azure 内构建了一个环境,其中创建了虚拟网络、多个子网、安全组(子网数量)、网络接口(interface)(虚拟机数量)、负载均衡器、虚拟机器等 我正在尝试将每个安全组与多个网络接口(interface)相关联,但尚未找到解决方案。此外,我在将负载均衡器与多个子网关联时遇到问题。

假设我的环境中有 4 个子网、4 个安全组、8 个 NIC(每个子网中有 2 个 NIC)和 1 个负载均衡器。我希望将特定子网内的每个 SG 与该子网内的 2 个 NIC 关联,然后将负载均衡器与 4 个子网中的 2 个子网关联。

在 Terraform 的文档中,将 SG 与 NIC 关联适用于一个特定的 NIC id,但数量不多: enter image description here

此外,在 Terraform 的文档中,将负载均衡器与子网关联起来适用于一个特定的子网 ID,但数量不多: enter image description here

我该如何处理这些多重关联? 谢谢。

最佳答案

您可以使用关联中的计数属性将多个 NIC 与一个 NSG 关联。这是一个例子:

resource "azurerm_network_interface_security_group_association" "example" {
  count                     = length(azurerm_network_interface.example.*.id)
  network_interface_id      = element(azurerm_network_interface.example.*.id, count.index)
  network_security_group_id = azurerm_network_security_group.example.id
}

关于Azure 使用 Terraform 将安全组与多个网络接口(interface)和负载均衡器与多个子网关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61134957/

相关文章:

Azure 管道。从资源库运行脚本

c# - 自定义工具警告 : unable to load one of the requested types

windows - 在 Windows 上使用 Azure CLI 颁发证书链中的自签名证书

html - 转换为 HTML Azure Powershell "Get-VM"

Azure租户是一个目录?

Azure 数据资源管理器 : How do Partitioning Policy and Merge Policy work?

ios - 解析100GB文件存储限制

sql-server - SQL Server 外部表中的计算列

git - 支持在 Azure DevOps 中签名标签和验证签名

tfs - 如何更改 VSTS 中的项目图标?