arm-artifacts/shared-templates/storage-account.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_ZRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Premium_LRS"
      ]
    },
    "storageAccessTier": {
      "type": "string",
      "defaultValue": "Hot",
      "allowedValues": [
        "Cool",
        "Hot"
      ]
    },
    "storageAccountName": {
      "type": "string",
      "minLength": 1
    },
    "storageAccountLocation": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    },
    "storageContainerNames": {
      "type": "array",
      "metadata": {
          "description": "Array of names to create storage containers."
      },
      "defaultValue": []
    },
    "supportsHttpsTrafficOnly": {
      "type": "bool",
      "defaultValue": true
    },
    "isHnsEnabled": {
        "type": "bool",
        "defaultValue": false
    },
    "tagValues": {
      "type": "object",
      "defaultValue": {}
    },
    "enabledAdlsPrivateEndpoint": {
      "type": "bool",
      "defaultValue": false
    },
    "subnetResourceId": {
      "type": "string",
      "defaultValue": ""
    }
  },
  "variables": {
    "ownerRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635')]",
    "localTags": {
      "displayName": "[parameters('storageAccountName')]"
    },
    "isHnsEnabledBackwardsCompatValue": "[if(equals(parameters('isHnsEnabled'),json('false')), '', parameters('isHnsEnabled'))]",
    "tags": "[union(parameters('tagValues'), variables('localTags'))]"
  },
  "resources": [
    {
      "name": "[parameters('storageAccountName')]",
      "type": "Microsoft.Storage/storageAccounts",
      "location": "[parameters('storageAccountLocation')]",
      "apiVersion": "2018-07-01",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "properties": {
        "accessTier": "[parameters('storageAccessTier')]",
        "supportsHttpsTrafficOnly": "[parameters('supportsHttpsTrafficOnly')]",
        "isHnsEnabled": "[variables('isHnsEnabledBackwardsCompatValue')]"
      },
      "dependsOn": [],
      "tags": "[variables('tags')]",
      "kind": "StorageV2"
    },
    {
      "condition": "[not(empty(parameters('storageContainerNames')))]",
      "name": "[concat(parameters('storageAccountName'), '/default/', if(not(empty(parameters('storageContainerNames'))), parameters('storageContainerNames')[copyIndex()], 'null'))]",
      "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
      "apiVersion": "2018-07-01",
      "dependsOn": [
          "[parameters('storageAccountName')]"
      ],
      "copy": {
          "name": "storageContainers",
          "count": "[if(not(empty(parameters('storageContainerNames'))), length(parameters('storageContainerNames')), 1)]"
      }
    },
    {
      "condition": "[parameters('enabledAdlsPrivateEndpoint')]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "[concat(deployment().name, '-private-endpoints')]",
      "dependsOn": [
        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
      ],
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "storageAccountName": {
            "value": "[parameters('storageAccountName')]"
          },
          "subnetResourceId": {
            "value": "[parameters('subnetResourceId')]"
          },
          "location": {
            "value": "[parameters('storageAccountLocation')]"
          },
          "tags": {
            "value": "[parameters('tagValues')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
            "storageAccountName": {
              "type": "string"
            },
            "subnetResourceId": {
              "type": "string"
            },
            "location": {
              "type": "string"
            },
            "tags": {
              "type": "object",
              "defaultValue": {}
            }
          },
          "variables": {
            "privateEndpointBaseName": "[concat('private-endpoint-adls-', parameters('storageAccountName'))]"
          },
          "resources": [
            {
              "type": "Microsoft.Network/privateEndpoints",
              "apiVersion": "2020-06-01",
              "name": "[toLower(variables('privateEndpointBaseName'))]",
              "location": "[parameters('location')]",
              "properties": {
                "subnet": {
                  "id": "[parameters('subnetResourceId')]"
                },
                "privateLinkServiceConnections": [
                  {
                    "name": "[toLower(variables('privateEndpointBaseName'))]",
                    "properties": {
                      "privateLinkServiceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                      "groupIds": [
                        "dfs"
                      ]
                    }
                  }
                ]
              },
              "tags": "[parameters('tags')]"
            }
          ]
        }
      }
    }
  ],
  "outputs": {
    "storageAccountKey": {
      "type": "string",
      "value": "[listKeys(parameters('storageAccountName'), '2019-04-01').keys[0].value]"
    },
    "storageAccountConnectionString": {
      "type": "string",
      "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=', listKeys(parameters('storageAccountName'), '2019-04-01').keys[0].value)]"
    }
  }
}