Я хочу развернуть ресурсы для учетной записи хранения, служебной шины, функции Azure и веб-приложения, используя шаблоны ARM.Также я хочу записать строки подключений хранилища и служебной шины к настройкам приложения и функции приложения.Поэтому я создал основной шаблон, который ссылается на 2 дочерних шаблона: один для функции и один для веб-приложения.Оба дочерних шаблона ссылаются на одни и те же связанные шаблоны для служебной шины и учетной записи хранения.Мой составной шаблон успешно проверен, но при попытке развертывания у меня появляются следующие ошибки:
Невозможно изменить или заменить развертывание serviceBus
: предыдущее развертывание из [datetime] все еще активно
Похоже, Azure пытается развернуть служебную шину и учетную запись хранения дважды.Как я могу сказать ARM использовать одно и то же serviceBus
развертывание как для веб-приложения, так и для функции?
Текущая упрощенная схема:
Main ARM template(azuredeploy.json)
/ \
Web App(nestedtemplates/webApp.json) Function App(nestedtemplates/functions/resourceAllocationFunction.json)
\ /
Service Bus(nestedtemplates/serviceBus.json)
Шаблоны:
azuredeploy.json
"resources": [
{
"name": "webApp",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('webAppTemplateFolder'), '/', variables('webAppTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"mainStorageAccountType": { "value": "[parameters('mainStorageAccountType')]" },
"location": { "value": "[parameters('location')]" },
"_artifactsLocation": { "value": "[parameters('_artifactsLocation')]" },
"_artifactsLocationSasToken": { "value": "[parameters('_artifactsLocationSasToken')]" }
}
}
},
{
"name": "resourceAllocationFunction",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('resourceAllocationFunctionTemplateFolder'), '/', variables('resourceAllocationFunctionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"mainStorageAccountType": { "value": "[parameters('mainStorageAccountType')]" },
"location": { "value": "[parameters('location')]" },
"_artifactsLocation": { "value": "[parameters('_artifactsLocation')]" },
"_artifactsLocationSasToken": { "value": "[parameters('_artifactsLocationSasToken')]" }
}
}
}
],
nestedtemplates / webApp.json
"resources": [
{
"name": "[parameters('servicePlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"sku": {
"name": "[parameters('servicePlanSkuName')]"
},
"dependsOn": [],
"properties": {
"name": "[parameters('servicePlanName')]",
"numberOfWorkers": 1
}
},
{
"name": "[variables('webAppName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('servicePlanName'))]"
],
"properties": {
"name": "[variables('webAppName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('servicePlanName'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('webAppName'))]",
"[resourceId('microsoft.insights/components/', variables('appInsightsName'))]"
],
"properties": {
"ServiceBus:ConnectionString": "[reference('serviceBus').outputs.connectionString.value]",
"ServiceBus:QueueName": "[reference('serviceBus').outputs.queueName.value]",
"StorageAccounts:WritableAccountName": "[reference('mainStorage').outputs.storageAccountName.value]",
"StorageAccounts:ConnectionString": "[reference('mainStorage').outputs.storageAccountConnString.value]",
}
}
]
},
{
"name": "serviceBus",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [ ],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('serviceBusTemplateFolder'), '/', variables('serviceBusTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"location": { "value": "[parameters('location')]" }
}
}
},
{
"name": "mainStorage",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [ ],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('mainStorageTemplateFolder'), '/', variables('mainStorageTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"location": { "value": "[parameters('location')]" },
"mainStorageAccountType": { "value": "[parameters('mainStorageAccountType')]" }
}
}
}
]
nestedtemplates / functions / resourceAllocationFunction.json
"resources": [
{
"name": "functionStorageAccount",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('functionStorageAccountTemplateFolder'), '/', variables('functionStorageAccountTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"location": { "value": "[parameters('location')]" }
}
}
},
{
"name": "consumptionPlan",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('consumptionPlanTemplateFolder'), '/', variables('consumptionPlanTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"location": { "value": "[parameters('location')]" }
}
}
},
{
"apiVersion": "2016-08-01",
"type": "Microsoft.Web/sites",
"name": "[variables('functionAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp",
"dependsOn": [
"[resourceId('microsoft.insights/components', variables('appInsightsName'))]"
],
"properties": {
"name": "[variables('functionAppName')]",
"serverFarmId": "[reference('consumptionPlan').outputs.resourceID.value]",
"siteConfig": {
"appSettings": [
{
"name": "AzureWebJobsDashboard",
"value": "[reference('functionStorageAccount').outputs.storageAccountConnString.value]"
},
{
"name": "AzureWebJobsStorage",
"value": "[reference('functionStorageAccount').outputs.storageAccountConnString.value]"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[reference('functionStorageAccount').outputs.storageAccountConnString.value]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower(variables('functionAppName'))]"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet"
},
{
"name": "AccoutLogin",
"value": "[reference('mainStorage').outputs.storageAccountName.value]"
},
{
"name": "AccountConnString",
"value": "[reference('mainStorage').outputs.storageAccountConnString.value]"
},
{
"name": "ServiceBusConnectionString",
"value": "[reference('serviceBus').outputs.connectionString.value]"
},
{
"name": "QueueName",
"value": "[reference('serviceBus').outputs.queueName.value]"
}
]
}
}
},
{
"name": "serviceBus",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('serviceBusTemplateFolder'), '/', variables('serviceBusTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"location": { "value": "[parameters('location')]" }
}
}
},
{
"name": "mainStorage",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('mainStorageTemplateFolder'), '/', variables('mainStorageTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"location": { "value": "[parameters('location')]" },
"mainStorageAccountType": { "value": "[parameters('mainStorageAccountType')]" }
}
}
}
],
nestedtemplates / mainStorage.json
"resources": [
{
"name": "[variables('mainStorageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"location": "[parameters('location')]",
"apiVersion": "2018-02-01",
"sku": {
"name": "[parameters('mainStorageAccountType')]"
},
"dependsOn": [],
"kind": "StorageV2",
"resources": [
{
"name": "[concat('default/', variables('containerName'))]",
"type": "blobServices/containers",
"apiVersion": "2018-03-01-preview",
"dependsOn": [
"[variables('mainStorageAccountName')]"
]
}
]
}
],
"outputs": {
"resourceID": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', variables('mainStorageAccountName'))]"
},
"storageAccountName": {
"type": "string",
"value": "[variables('mainStorageAccountName')]"
},
"storageAccountContainer": {
"type": "string",
"value": "[variables('containerName')]"
},
"storageAccountConnString": {
"type": "string",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('mainStorageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('mainStorageAccountName')),'2015-05-01-preview').key1)]"
}
}
nestedtemplates / serviceBus.json
"resources": [
{
"type": "Microsoft.ServiceBus/namespaces",
"name": "[variables('serviceBusNamespaceName')]",
"apiVersion": "2017-04-01",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {},
"resources": [
{
"apiVersion": "2017-04-01",
"name": "[parameters('serviceBusQueueName1')]",
"type": "Queues",
"dependsOn": [
"[concat('Microsoft.ServiceBus/namespaces/', variables('serviceBusNamespaceName'))]"
],
"properties": {
"lockDuration": "PT5M",
"maxSizeInMegabytes": "1024",
"requiresDuplicateDetection": "false",
"requiresSession": "false",
"defaultMessageTimeToLive": "P10675199DT2H48M5.4775807S",
"deadLetteringOnMessageExpiration": "false",
"duplicateDetectionHistoryTimeWindow": "PT10M",
"maxDeliveryCount": "10",
"autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",
"enablePartitioning": "false",
"enableExpress": "false"
}
}
]
}
],
"outputs": {
"resourceID": {
"type": "string",
"value": "[resourceId('Microsoft.ServiceBus/namespaces', variables('serviceBusNamespaceName'))]"
},
"connectionString": {
"type": "string",
"value": "[listkeys(variables('authRuleResourceId'), '2017-04-01').primaryConnectionString]"
},
"sharedAccessPolicyPrimaryKey": {
"type": "string",
"value": "[listkeys(variables('authRuleResourceId'), '2017-04-01').primaryKey]"
},
"queueName": {
"type": "string",
"value": "[parameters('serviceBusQueueName1')]"
}
}