{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "0.0.0.1",
    "parameters": {
        "functionAppName": {
            "type": "string",
            "defaultValue": "myfunctionAppDemo",
            "metadata": {
                "description": "Specify the name of the function application"
              }
        },
        "TagName": {
            "type": "string",
            "defaultValue": "RestartPolicy",
            "metadata": {
                "description": "Specify the name of the tag for the restart policy"
              }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Specify the location for the function application resources"
              }
        },

        "runtimeStack": {
            "type": "string",
            "defaultValue": "powershell",
            "allowedValues": [
                "powershell",
                "dotnet",
                "node",
                "java"
            ],
            "metadata": {
                "description": "Pick the language runtime that you want enabled"
              }
        },
        "timezone": {
            "type": "string",
            "defaultValue": "UTC",        
            "metadata": {
                "description": "Pick the timezone to use for the function"
              }
        }
    },
    "variables": {
        "hostingPlanName": "[concat(parameters('functionAppName'), '-plan')]",
        "storageAccountName": "[concat('stofunc', uniquestring(resourceGroup().id))]",
        "BlobContainerName": "logs"
    },
    "resources": [
        {
            "name": "[parameters('functionAppName')]",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-02-01",
            "location": "[parameters('location')]",
            "kind": "functionapp",            
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]",
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
            ],
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "[parameters('runtimeStack')]"
                        },
                        {
                            "name": "TagName",
                            "value": "[parameters('TagName')]"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2017-06-01').keys[0].value)]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')),'2017-06-01').keys[0].value)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower(parameters('functionAppName'))]"
                        },
                        {
                            "name": "WEBSITE_TIME_ZONE",
                            "value": "[parameters('timezone')]"
                        }
                    ]
                },
                "name": "[parameters('functionAppName')]",
                "clientAffinityEnabled": false,
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
            }
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2015-08-01",
            "name": "[variables('hostingPlanName')]",
            "location": "[parameters('location')]",
            "properties": {
                "name": "[variables('hostingPlanName')]"
            },
            "sku": {
                "name": "Y1",
                "tier": "Dynamic",
                "size": "Y1",
                "family": "Y",
                "capacity": 0
            }
        },
        {
            "name": "[variables('storageAccountName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2018-07-01",
            "location": "[parameters('location')]",
            "kind": "StorageV2",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            },
            "properties": {
                "accessTier": "Hot"
            },
            "resources": [
                {
                    "name": "[concat('default/', variables('BlobContainerName'))]",
                    "type": "blobServices/containers",
                    "apiVersion": "2018-07-01",
                    "dependsOn": [
                        "[variables('storageAccountName')]"
                    ]
                }
            ]
        }
    ],
    "outputs": {

    }
}