Templates/Storage.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Virtual Network Name."
      }
    },
    "vnetResourceGroupName": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Virtual Network Resource Group."
      }
    },
    "storageAllowedSubnets": {
      "type": "array",
      "defaultValue": [],
      "metadata": {
        "description": "A list of subnet names that will be translated into allowed access rules."
      }
    },
    "storageName": {
      "type": "string",
      "defaultValue": "sass%UID%",
      "metadata": {
        "description": "Storage Account Name"
      }
    },
    "storageLocation": {
      "type": "string",
      "defaultValue": "%LOCATION%",
      "metadata": {
        "description": "Storage Account Location."
      }
    },
    "storageType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "metadata": {
        "description": "Geo-replication type of Storage account"
      },
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_ZRS",
        "Premium_LRS"
      ]
    },
    "storageTier": {
      "type": "string",
      "defaultValue": "Standard",
      "metadata": {
        "description": "The tier of the Storage Account"
      }
    },
    "storageTags": {
      "type": "object",
      "defaultValue": {
        "Date": "%DATE%"
      },
      "metadata": {
        "description": "Storage Account Tags."
      }
    }
  },
  "variables": {
    "storageLocation": "[if(empty(parameters('storageLocation')), resourceGroup().location, parameters('storageLocation'))]",
    "networkAclCollection": {
      "bypass": "AzureServices",
      "copy": [
        {
          "name": "virtualNetworkRules",
          "count": "[max(length(parameters('storageAllowedSubnets')), 1) ]",
          "input": {
            "id": "[concat(resourceId(parameters('vnetResourceGroupName'), 'Microsoft.Network/virtualNetworks/', parameters('vnetName')), '/', 'subnets', '/', if(greater(length(parameters('storageAllowedSubnets')), 0), parameters('storageAllowedSubnets')[copyIndex('virtualNetworkRules')], ''))]",
            "service": "[if(greater(length(parameters('storageAllowedSubnets')), 0), parameters('storageAllowedSubnets')[copyIndex('virtualNetworkRules')], '')]",
            "action": "Allow"
          }
        }
      ],
      "ipRules": [],
      "defaultAction": "Deny"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "sku": {
        "name": "[parameters('storageType')]",
        "tier": "[parameters('storageTier')]"
      },
      "kind": "StorageV2",
      "name": "[parameters('storageName')]",
      "apiVersion": "2018-02-01",
      "location": "[variables('storageLocation')]",
      "tags": "[parameters('storageTags')]",
      "scale": null,
      "properties": {
        "networkAcls": "[if(greater(length(parameters('storageAllowedSubnets')), 0), variables('networkAclCollection'), json('null'))]",
        "supportsHttpsTrafficOnly": false,
        "encryption": {
          "services": {
            "file": {
              "enabled": true
            },
            "blob": {
              "enabled": true
            }
          },
          "keySource": "Microsoft.Storage"
        }
      },
      "dependsOn": []
    }
  ],
  "outputs": {}
}