【问题标题】:How to add the multiple existing virtual networks and subnets in storage account ARM template using iterator concept?如何使用迭代器概念在存储帐户 ARM 模板中添加多个现有虚拟网络和子网?
【发布时间】:2021-10-26 17:00:03
【问题描述】:

我通过使用以下 ARM 模板添加现有虚拟网络创建了 Azure 存储帐户。

    {
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "type": "string",
            "metadata": {
                "description": "Specifies the name of the Azure Storage account."
            }
        },
        "storageAccountType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "allowedValues": [
                "Standard_LRS",
                "Standard_GRS",
                "Standard_RAGRS",
                "Standard_ZRS",
                "Premium_LRS"
            ],
            "metadata": {
                "description": "Storage Account type."
            }
        },
        "storageAccessTier": {
            "type": "string",
            "defaultValue": "Hot",
            "allowedValues": [
                "Hot",
                "Cool"
            ],
            "metadata": {
                "description": "Set the access tier of the Storage Account."
            }
        },
        "storageKind": {
            "type": "string",
            "defaultValue": "StorageV2",
            "allowedValues": [
                "StorageV2",
                "Storage"
            ],
            "metadata": {
                "description": "Set the storage kind of the Storage Account."
            }
        },
        "storageAccounthttpsTrafficOnlyEnabled": {
            "type": "bool",
            "defaultValue": true,
            "metadata": {
                "description": "Enable or disable enforcing HTTPS only access."
            }
        },
        "allowBlobPublicAccess": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Enable or disable blob public access"
            }
        },
        "isHnsEnabled": {
            "type": "bool",
            "defaultValue": true,
            "metadata": {
                "description": "Enable or disable ADLS Gen2 hierarchical namespace"
            }
        },
        "containerNames": {
            "type": "array",
            "metadata": {
                "description": "The container names"
            }
        },
        "location": {
            "type": "string",
            "metadata": {
                "description": "Specifies the location in which the Azure Storage resources should be deployed."
            }
        },
        "environment": {
            "type": "string",
            "metadata": {
                "description": "Specify the environment name"
            }
        },
        "subscriptionOwner": {
            "type": "string",
            "metadata": {
                "description": "Specify the email address of the subscription owner"
            }
        },
        "vnetResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "The name of the existing resource group which contains the virtual network"
            }
        },
        "vnetName": {
            "type": "string",
            "metadata": {
                "description": "The name of the existing virtual network"
            }
        },
        "subnet01Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the db subnet"
            }
        },
        "subnet02Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the default subnet"
            }
        },
        "subnet03Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the ise1 subnet"
            }
        },
        "subnet04Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the ise2 subnet"
            }
        },
        "subnet05Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the ise3 subnet"
            }
        },
        "subnet06Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the ise4 subnet"
            }
        },
        "subnet07Name": {
            "type": "string",
            "metadata": {
                "description": "The name of the tools subnet"
            }
        }
    },
    "variables": {
        "vnetResourceId": "[resourceId(parameters('vnetResourceGroupName'),'Microsoft.Network/virtualNetworks',parameters('vnetName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2020-08-01-preview",
            "name": "[parameters('storageAccountName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "[parameters('storageAccountType')]",
                "tier": "Standard"
            },
            "kind": "[parameters('storageKind')]",
            "properties": {
                "accessTier": "[parameters('storageAccessTier')]",
                "allowBlobPublicAccess": "[parameters('allowBlobPublicAccess')]",
                "isHnsEnabled": "[parameters('isHnsEnabled')]",
                "supportsHttpsTrafficOnly": "[parameters('storageAccounthttpsTrafficOnlyEnabled')]",
                "networkAcls": {
                    "resourceAccessRules": [
                    ],
                    "bypass": "AzureServices",
                    "virtualNetworkRules": [
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet01Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        },
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet02Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        },
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet03Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        },
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet04Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        },
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet05Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        },
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet06Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        },
                        {
                            "id": "[concat(variables('vnetResourceId'), '/subnets/',parameters('subnet07Name'))]",
                            "action": "Allow",
                            "state": "Succeeded"
                        }
                    ],
                    "ipRules": [
                        {
                            "value": "xxxxxxxx",
                            "action": "Allow"
                        }
                    ],
                    "defaultAction": "Deny"
                }
            }
        },
        {
            "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
            "apiVersion": "2020-08-01-preview",
            "name": "[concat(parameters('storageAccountName'),'/default/', parameters('containerNames')[copyIndex()])]",
            "copy": {
                "name": "containercopy",
                "count": "[length(parameters('containerNames'))]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
            ]
        }
    ],
    "outputs": {
        "storageAccountName": {
            "type": "string",
            "value": "[parameters('storageAccountName')]"
        },
        "containerNames": {
            "type": "array",
            "value": "[parameters('containerNames')]"
        }
    }
   }

在上面的模板中,我使用了多个参数来提供虚拟网络和子网。但我想使用复制操作符来添加现有的虚拟网络和子网。

【问题讨论】:

    标签: azure azure-storage arm-template azure-virtual-network subnet


    【解决方案1】:

    这是我采用的一种方法。

      "parameters": {
        ...
        "ipRules": {
          "type": "array"
        },
        "virtualNetworkSubnetsIds": {
          "type": "array"
        }
      },
      "variables": {
        "copy": [
          {
            "name": "ipRules",
            "count": "[length(parameters('ipRules'))]",
            "input": {
              "value": "[parameters('ipRules')[copyIndex('ipRules')]]"
            }
          },
          {
            "name": "virtualNetworkRules",
            "count": "[length(parameters('virtualNetworkSubnetsIds'))]",
            "input": {
              "id": "[parameters('virtualNetworkSubnetsIds')[copyIndex('virtualNetworkRules')]]",
              "action": "Allow",
              "ignoreMissingVNetServiceEndpoint": false
            }
          }
        ]
      },
    
    

    在存储帐户部署中,我将变量分配给属性。

            "networkAcls": {
              "defaultAction": "Deny",
              "bypass": "AzureServices",
              "ipRules": "[variables('ipRules')]",
              "virtualNetworkRules": "[variables('virtualNetworkRules')]"
            },
    
    

    【讨论】:

    • 谢谢@Stringfellow,我不想为virtualNetworkSubnetsIds 创建数组类型参数。我想为虚拟网络和子网创建数组类型参数,然后获取子网resourceid并将其分配给virtualNetworkRules
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2019-07-27
    • 1970-01-01
    • 2021-12-09
    • 2020-08-24
    • 1970-01-01
    相关资源
    最近更新 更多