azure-devops - 如何在 ARM 模板中引用已存在的 Azure 门户创建的存储帐户
问题描述
我想使用 ARM 模板创建一个函数应用程序,以便 ARM 模板引用我已经参数化的现有存储帐户( inputtgdev和outputstgdev )。我希望 ARM 模板使用inputtgdev存储帐户作为其附加的存储帐户,这样它就不必创建新的存储帐户。函数应用程序的源代码控制引用了一个 Gitrepo,我也在 ARM 模板中对其进行了参数化。每次运行 ARM 模板时,都会收到以下错误消息
##[错误]部署模板验证失败:'资源'/subscriptions/bea8ac84-24a4-4e53-9198-e3b0107547d4/resourceGroups/dev-rgp/providers/Microsoft.Web/sites/functionapp/sourcecontrols/web'在行' 1'和列'3069'不依赖于父资源'/subscriptions/bea8ac84-24a4-4e53-9198-e3b0107547d4/resourceGroups/dev-rgp/providers/Microsoft.Web/sites/functionapp'。请使用“dependsOn”语法显式添加依赖项。请参阅 aka.ms/arm-template/#resources 了解
任何建议可能是什么问题或可能的解决方案。我期待着您的回复
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"InputstorageAccount": {
"defaultValue": "inputstgdev",
"type": "String"
},
"GitrepoBranch": {
"type": "string",
"defaultValue": "master",
"metadata": {
"description": "Name of the branch to use when deploying (Default = master)."
}
},
"GitrepoURL": {
"type": "string",
"defaultValue": "https://github.com/FBoucher/AzUnzipEverything.git",
"metadata": {
"description": "URL to repo (Default = master)."
}
},
"InputcontainerName": {
"type": "string",
"defaultValue": "inputcontainer",
"metadata": {
"description": "Specifies the name of the blob container."
}
},
"OutputstorageAccount": {
"defaultValue": "outputstgdev",
"type": "String"
},
"OutputcontainerName": {
"type": "string",
"defaultValue": "outputcontainer",
"metadata": {
"description": "Specifies the name of the blob container."
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2019-06-01",
"name": "[concat(parameters('InputstorageAccount'), '/default/', parameters('InputcontainerName'))]",
"properties": {
"publicAccess": "None"
}
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2019-06-01",
"name": "[concat(parameters('OutputstorageAccount'), '/default/', parameters('OutputcontainerName'))]",
"properties": {
"publicAccess": "None"
}
},
{
"name": "serviceplan",
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2018-02-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "F1",
"capacity": 1
},
"tags": {
"displayName": "serviceplan"
},
"properties": {
"name": "serviceplan"
}
},
{
"name": "functionapp",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"location": "[resourceGroup().location]",
"kind": "functionapp",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', 'serviceplan')]",
"[resourceId('Microsoft.Storage/storageAccounts', parameters('InputstorageAccount'))]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'serviceplan')]",
"siteConfig": {
"appSettings": [
{
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('InputstorageAccount'), ';AccountKey=', listKeys(parameters('InputcontainerName'),'2015-05-01-preview').key1)]"
},
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('InputstorageAccount'), ';AccountKey=', listKeys(parameters('InputcontainerName'),'2015-05-01-preview').key1)]"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('InputstorageAccount'), ';AccountKey=', listKeys(parameters('InputcontainerName'),'2015-05-01-preview').key1)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower('functionapp')]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('microsoft.insights/components/', 'applicationInsightsName'), '2015-05-01').InstrumentationKey]"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet"
}
]
}
},
"resources":[
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "sourcecontrols",
"dependsOn": [
"[resourceId('Microsoft.Web/sites/', parameters('InputstorageAccount'))]"
],
"properties": {
"RepoUrl": "[parameters('GitrepoURL')]",
"branch": "[parameters('GitrepoBranch')]",
"publishRunbook": true,
"IsManualIntegration": true
}
}
]
}
]
}
解决方案
由于错误的依赖关系,您遇到了此错误消息。
您应该使用"[resourceId('Microsoft.Web/sites/', 'functionapp')]"
而不是"[resourceId('Microsoft.Web/sites/', parameters('InputstorageAccount'))]"
.
你应该删除存储依赖。
"[resourceId('Microsoft.Storage/storageAccounts', parameters('InputstorageAccount'))]"
顺便说一句,由于您已经有一个存储帐户,您只需将连接字符串粘贴到AzureWebJobsStorage和AzureWebJobsDashboard的值中。
就像
{
"name": "AzureWebJobsDashboard",
"value": "{connectionstring}"
}
推荐阅读
- xpath - 如何将 IMPORTHTML 用于不带参数的 URL?
- sql-server - SQL Server:重新运行相同的行
- amazon-web-services - Cloudformation - 在不同区域创建资源
- android - Admob 中介降低填充率
- r - 连接嵌套和未嵌套的数据框/小标题
- html - 表单服务无法使用应用程序建立连接,但可以在浏览器中使用
- c# - 下载邮件附件损坏文件
- javascript - 如何在反应原生渲染的无限循环中返回数组项视图?
- javascript - 如何使用 Redux-Form 进行客户端和服务器端验证
- android - _TypeError(类型'列表
' 不是类型 'Map 的子类型 ') 颤动