0

编辑新帖子以添加更多说明:

在当前架构中,我们运行 ansible playbook (infrastructure.yml) 以在 Azure 中部署基础架构。我们能够毫无问题地创建资源,包括许多其他 NSG 规则。

使用新的 NSG 规则,我们的 terraform 运行失败,并显示以下信息:

我的 Azurerm 版本为:

provider "azurerm" {
  version = "2.58.0"
  ...

地形版本:

Terraform v0.13.4

我可以通过 Azure CLI 命令创建相同的规则,如下所示:

az network nsg rule create -g 'MyGroup' --nsg-name 'MyNSG' -n 'AllowAzureMonitorOutbound' --priority 1200 --source-address-prefixes "*" --destination-address-prefixes AzureMonitor --destination-port-ranges 443  --direction Outbound --access Allow --protocol Tcp --description "AzureMonitor rule CLI creation."

但是我在通过 Terraform 创建 NSG 规则时收到此错误:

**-- Original Error: Code="SecurityRuleParameterContainsUnsupportedValue" Message="Security rule parameter DestinationAddressPrefix for rule with Id /subscriptions/XXXXXXXXXXXXXX/resourceGroups/MyGroup/providers/Microsoft.Network/networkSecurityGroups/UMyNSG/securityRules/AllowAzureMonitorOutbound cannot specify existing VIRTUALNETWORK, INTERNET, AZURELOADBALANCER, '*' or system tags. Unsupported value used: AzureMonitor."** 

<------------- 代码和 HashicoVault 值---------------->

terraform 的代码片段:

resource "azurerm_network_security_group" "prx" {
  name                = "${var.prx_hosts.name}-NSG"
  resource_group_name = azurerm_resource_group.MYPROJECT.name
  location            = var.location
  dynamic "security_rule" {
    for_each = var.prx_hosts.security_group.rules
    content {
      name                         = security_rule.value.name
      description                  = security_rule.value.description
      access                       = security_rule.value.access
      direction                    = security_rule.value.direction
      protocol                     = security_rule.value.protocol
      priority                     = security_rule.value.priority
      source_address_prefix        = security_rule.value.source_address_prefixes == ["any"] ? "*" : null
      source_address_prefixes      = security_rule.value.source_address_prefixes == ["any"] ? null : tolist(security_rule.value.source_address_prefixes)
      destination_address_prefix   = security_rule.value.destination_address_prefixes == ["any"] ? "*" : null
      destination_address_prefixes = security_rule.value.destination_address_prefixes == ["any"] ? null : tolist(security_rule.value.destination_address_prefixes)
      source_port_range            = security_rule.value.source_port_ranges == ["any"] ? "*" : null
      source_port_ranges           = security_rule.value.source_port_ranges == ["any"] ? null : tolist(security_rule.value.source_port_ranges)
      destination_port_range       = security_rule.value.destination_port_ranges == ["any"] ? "*" : null
      destination_port_ranges      = security_rule.value.destination_port_ranges == ["any"] ? null : tolist(security_rule.value.destination_port_ranges)
    }
  }
}

我们传递给 terraform 的 HashicoVault 值如下:

        "security_group": {
          "name": "MY_PROJECT_NAME",
          "rules": [
            {
              "access": "allow",
              "description": "AzureMonitor rule CLI creation.",
              "destination_address_prefixes": ["AzureMonitor"],
              "destination_port_ranges": [
                443
              ],
              "direction": "Outbound",
              "name": "AllowAzureMonitorOutbound",
              "priority": 100,
              "protocol": "TCP",
              "source_address_prefixes": [
                "any"
              ],
              "source_port_ranges": [
                "any"
              ]
            }
          ]
        }
4

2 回答 2

0

我认为实际上在提供程序中声明 source_address_prefix 将采用标签,而 source_address_prefixes 将仅采用 CIDR 块和 IP

资源:

source_address_prefix - (可选)CIDR 或源 IP 范围或 * 以匹配任何 IP。也可以使用“VirtualNetwork”、“AzureLoadBalancer”和“Internet”等标签。如果未指定 source_address_prefixes,则这是必需的。

source_address_prefixes -(可选)源地址前缀列表。不得使用标签。如果未指定 source_address_prefix,则这是必需的。

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule#source_address_prefixes

于 2022-03-04T02:59:27.483 回答
0

我对“AzureLoadBalancer”有同样的问题——例如它适用于“source_address_prefix”,但不适用于“source_address_prefixes”——可能是提供程序错误

于 2021-07-20T14:23:59.253 回答