用于存储帐户上文件共享的 ARM 模板

ARM Template for FileShare on Storage Account

我已经使用 Azure Functions 等创建了一个存储帐户。 设置相当简单 - 我现在已将其导出到 ARM 模板。

为了测试它,我从 Azure 中删除了资源,并尝试使用模板来创建东西。

但是,我有这个部分来创建所需的文件共享:

{
    "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
    "apiVersion": "2021-08-01",
    "name": "funcstoretest/default/scale-test1546",
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/fileServices', 'funcstoretest', 'default')]",
        "[resourceId('Microsoft.Storage/storageAccounts', 'funcstoretest')]"
    ],
    "properties": {
        "accessTier": "TransactionOptimized",
        "shareQuota": 5120,
        "enabledProtocols": "SMB"
    }
},

但是实际上使用这个导出的示例总是会导致以下错误:

There were errors in your deployment.

Error code: DeploymentFailed.

##[error]At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.

##[error]Details:

##[error]InvalidHeaderValue: The value for one of the HTTP headers is not in the correct format.

现在,删除定义属性(即 accessTier、shareQuota、enabledProtocols)的部分允许部署继续,但导致与 Azure Functions 的共享无法使用,抱怨它找不到运行时(并且没有函数当我部署时正在部署)。

关于这应该如何工作的任何想法?

请试试这个。它完美运行。

确保通过必要的应用程序设置,因为功能应用程序将尝试连接到存储帐户,如果不添加,它将面临运行时无法访问的错误。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appName": {
      "type": "string",
      "defaultValue": "[concat('fnapp', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "The name of the function app that you wish to create."
      }
    },
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "runtime": {
      "type": "string",
      "defaultValue": "node",
      "metadata": {
        "description": "The language worker runtime to load in the function app."
      }
    },
    "storageAccountName": {
      "type": "string"
      }
    
  },
  "variables": {
    "functionAppName": "[parameters('appName')]",
    "hostingPlanName": "[parameters('appName')]",
    "functionWorkerRuntime": "[parameters('runtime')]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "apiVersion": "2019-06-01",
      "location": "[parameters('location')]",
      "kind": "Storage",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      }
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2019-08-01",
      "name": "[variables('hostingPlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Y1",
        "tier": "Dynamic"
      },
      "properties": {
        "name": "[variables('hostingPlanName')]",
        "computeMode": "Dynamic"
      }
    },
    {
      "apiVersion": "2019-08-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ],
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(variables('functionAppName'))]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~2"
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "~10"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "[variables('functionWorkerRuntime')]"
            }
          ]
        }
      }
    }
   
  ]
}

将以下参数传递给它

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appName": {
      "metadata": {
        "description": "This Param will set the FA name & hostingPlanName"

      },
      "value": "yourappservicename_FunctionappName"
    },
    "storageAccountName": {
      "metadata": {
        "descrption": "Name of the storage account that will be conected & configured with teh function app"
      },
      "value": "Storage_Account_name"
    }
  }
}