gpt4 book ai didi

json - Azure Bicep/Json - 无法正确解析 JSON

转载 作者:行者123 更新时间:2023-12-03 05:22:15 25 4
gpt4 key购买 nike

我在从 JSON 文件解析网络安全组时遇到问题,因此我们可以使用单个模板创建多个 NSG

param NSGs array = array(json(loadTextContent('./shared-rules.json')))
resource nsg 'Microsoft.Network/networkSecurityGroups@2020-05-01' = [for (ns, index) in NSGs: {
name: ?????
location: resourceGroup().location
properties: {
securityRules: ????
}
}]

这是我的模板文件的副本:

{
"NSG-1": [
{
"name": "Allow_RDP_from_company_IP_address",
"properties": {
"description": "Allow inbound RDP from the company's IP address range.",
"protocol": "Tcp",
"sourceAddressPrefix": "203.0.113.0/24",
"sourcePortRange": "*",
"destinationAddressPrefix": "VirtualNetwork",
"destinationPortRange": "3389",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
},
{
"name": "Allow_VirtualNetwork_to_Storage",
"properties": {
"description": "Allow outbound connections to the Azure Storage service tag.",
"protocol": "Tcp",
"sourceAddressPrefix": "VirtualNetwork",
"sourcePortRange": "*",
"destinationAddressPrefix": "Storage",
"destinationPortRange": "*",
"access": "Allow",
"priority": 100,
"direction": "Outbound"
}
}
],
"NSG-2": [
{
"name": "Allow_RDP_from_company_IP_address",
"properties": {
"description": "Allow inbound RDP from the company's IP address range.",
"protocol": "Tcp",
"sourceAddressPrefix": "203.0.113.0/24",
"sourcePortRange": "*",
"destinationAddressPrefix": "VirtualNetwork",
"destinationPortRange": "3389",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
},
{
"name": "Allow_VirtualNetwork_to_Storage",
"properties": {
"description": "Allow outbound connections to the Azure Storage service tag.",
"protocol": "Tcp",
"sourceAddressPrefix": "VirtualNetwork",
"sourcePortRange": "*",
"destinationAddressPrefix": "Storage",
"destinationPortRange": "*",
"access": "Allow",
"priority": 100,
"direction": "Outbound"
}
}
]
}

我认为只需填写两行即可使其正常工作:即二头肌模板中的名称和 securityRules((第一个代码块)

假设我的 JSON 文件也是正确的 - 想知道是否有人有任何想法?

最佳答案

正如已经建议的,您可以使用 items function .

可以在此处找到有关如何使用它的示例:Dictionary object .

对于您的用例,它应该如下所示:

param sharedRules object = json(loadTextContent('./shared-rules.json'))

resource nsgs 'Microsoft.Network/networkSecurityGroups@2020-05-01' = [for rule in items(sharedRules): {
name: rule.key
location: resourceGroup().location
properties: {
securityRules: rule.value
}
}]

关于json - Azure Bicep/Json - 无法正确解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71259586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com