Azure ARM模板-参数加上属性的静态值

问题描述 投票:0回答:1

我有一个ARM模板,其中包含“ Microsoft.Web / sites”资源类型。我正在尝试配置资源的“ ipSecurityRestrictions”属性。

“ ipSecurityRestrictions”块的配置如下:

"ipSecurityRestrictions": [{
    "vnetSubnetResourceId": "[resourceId(parameters(''Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), variables('subnetName'))]",
    "action": "Allow",
    "description": "Grants the subnet access to this web app."
  },
  {
    "vnetSubnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName2'), variables('subnetName2'))]",
    "action": "Allow",
    "description": "Grants the subnet2 access to this web app."
  }
]

这按预期工作。但是,我也想将IP地址添加到“ ipSecurityRestrictions”中,如果我将另一个对象添加到数组中,则可以正常工作,例如:

{
  "ipAddress": "12.123.123.12/32",
  "action": "Allow",
  "description": "Grants the IP access to this web app."
}

事实是,我希望能够通过参数指定应允许访问Web应用程序的IP地址。

因此,我需要能够组合一个包含ipAddress securityRestrictions的参数,以便在添加vnet之后添加它。一个对象参数,其中包含多个“ ipSecurityRestrictions”。

这在Azure Sql Server上是可行的,因为防火墙规则是从它自己的资源“ Microsoft.Sql / servers / firewallRules”创建的,所以我可以为每个vnet创建一个硬编码资源,然后使用一个对象参数(填充通过json)使用复制功能具有多个值。

例如,密钥保管库,因为它具有vnet(“ virtualNetworkRules”)和ip地址(“ ipRules”)的专有属性。因此,我可以对vnet进行硬编码,然后为IP地址使用参数。

我已经尝试了许多方法,包括所有(从Microsoft记录到的)模板函数等。

如果无法实现,我也可以使用同时包含vnet和ip地址的object参数来解决。但是,我该如何在模板中自动获取vnet的resourceId,以便我可以引用正确的vnet,而无需事先知道resourceId?

感谢所有输入!

最诚挚的问候

azure azure-resource-manager arm-template
1个回答
0
投票

您可以将两个或多个数组连接在一起。可以将带有VNet /子网的一个定义为模板中的变量,而另一个可以作为带有ipAddress对象列表的array类型的参数传递。

"variables": {
  "ipSecurityRestrictionsSubnets": [
    {
      "vnetSubnetResourceId": "[resourceId(parameters(''Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), variables('subnetName'))]",
      "action": "Allow",
      "description": "Grants the subnet access to this web app."
    },
    {
      "vnetSubnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName2'), variables('subnetName2'))]",
      "action": "Allow",
      "description": "Grants the subnet2 access to this web app."
    }
  ]
},

然后通过串联两个数组来设置属性。

"ipSecurityRestrictions": "[concat(variables('ipSecurityRestrictionsSubnets'), parameters('ipSet'))]",

参考:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-array#concat

© www.soinside.com 2019 - 2024. All rights reserved.