[英]Using Deployment Template resource and receiving resource group not found but all other deployments work
When deploying the following the final deployment always fails with resourcegroup not found.部署以下内容时,最终部署总是失败,找不到资源组。 The previous for will work.
以前的 for 将起作用。
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appBaseName": {
"type": "string",
"metadata": {
"description": "Name of the application. Used in the name of resources."
},
"minLength": 5,
"maxLength": 12,
"defaultValue": "[deployment().name]"
},
"tenantId": {
"type": "string",
"defaultValue": "[subscription().tenantId]",
"metadata": {
"description": "Tenant ID for deployment"
}
},
"location": {
"type": "string",
"defaultValue": "eastus2",
"metadata": {
"description": "Location for deployment"
}
},
"administratorLogin": {
"type": "string",
"metadata": {
"description": "The administrator username of the SQL logical server.",
"defaultValue": "admingod"
}
},
"administratorLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL logical server.",
"defaultValue": "Passw0rd10s"
}
}
},
"variables": {
"AppInsightsName": "[concat(parameters('appBaseName'), '-AppInsights')]",
"AppServicePlanName": "[concat(parameters('appBaseName'), '-ASP')]",
"SQLServer": "[concat(parameters('appBaseName'), '-sqlserver')]",
"SQLDB": "[concat(parameters('appBaseName'), '-sqldb')]",
"WebAppName": "[concat(parameters('appBaseName'), '-web')]",
"ResourceGroupName": "[concat(parameters('appBaseName'), '-rg')]",
"storageAccountName": "[concat('stg',parameters('appBaseName'))]",
"storageAccountId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'),'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"functionName": "[concat(parameters('appBaseName'),'-fn')]",
"KeyVaultName": "[concat(parameters('appBaseName'), '-kv')]",
"appInsightsId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'),'/providers/','Microsoft.Insights/components/', variables('AppInsightsName'))]",
"ResourceGroupId": "[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2019-10-01",
"name": "[variables('ResourceGroupName')]",
"location": "[parameters('location')]",
"properties": {}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(deployment().name,'-KeyVault')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[variables('KeyVaultName')]",
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2016-10-01",
"location": "[parameters('location')]",
"tags": {
"displayName": "[variables('KeyVaultName')]"
},
"properties": {
"enabledForDeployment": true,
"enabledForTemplateDeployment": true,
"enabledForDiskEncryption": true,
"tenantId": "[parameters('tenantId')]",
"accessPolicies": [
],
"sku": {
"name": "standard",
"family": "A"
}
}
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(deployment().name,'-SQL')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[variables('SQLServer')]",
"location": "[parameters('location')]",
"properties": {
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]"
},
"resources": [
{
"type": "databases",
"apiVersion": "2019-06-01-preview",
"name": "[variables('SQLDB')]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"location": "[parameters('location')]",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"edition": "Basic",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "Basic"
},
"dependsOn": [
"[variables('SQLServer')]"
]
}
]
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(deployment().name,'-App')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"apiVersion": "2019-08-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('AppServicePlanName')]",
"location": "[parameters('location')]",
"properties": {
"name": "[variables('AppServicePlanName')]"
},
"sku": {
"name": "F1",
"capacity": 1
}
},
{
"apiVersion": "2019-08-01",
"type": "Microsoft.Web/sites",
"name": "[variables('WebAppName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Web/serverfarms/', variables('AppServicePlanName'))]"
],
"properties": {
"name": "[variables('WebAppName')]",
"serverFarmId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Web/serverfarms/', variables('AppServicePlanName'))]"
}
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(deployment().name,'-FuncApp')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"location": "[parameters('location')]",
"name": "[variables('storageAccountName')]",
"sku": {
"name": "Standard_RAGRS"
},
"kind": "StorageV2",
"properties": {}
},
{
"name":"[variables('AppInsightsName')]",
"type":"Microsoft.Insights/components",
"apiVersion":"2015-05-01",
"location":"[parameters('location')]",
"kind":"web",
"properties":{
"application_Type":"web",
"ApplicationId": "[variables('appInsightsName')]"
}
},
{
"name": "[variables('functionName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"location": "[parameters('location')]",
"kind": "functionapp",
"properties": {
"serverFarmId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Web/serverfarms/', variables('AppServicePlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listKeys(variables('storageAccountId'),'2019-06-01').keys[0].value)]"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Insights/components/', variables('AppInsightsName')), '2015-05-01').InstrumentationKey]"
},
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower('functionName')]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet"
}
]
}
}
}
],
"outputs": {}
}
}
}
],
"outputs": {}
}
I receive the following:我收到以下信息:
cli.azure.cli.core.util : Deployment failed. Correlation ID: 0cca46d7-6342-4a87-8f94-c12ba9b595f9. {
"error": {
"code": "ResourceGroupNotFound",
"message": "Resource group 'devcloud15-rg' could not be found."
}
}
Deployment failed. Correlation ID: 0cca46d7-6342-4a87-8f94-c12ba9b595f9. {
"error": {
"code": "ResourceGroupNotFound",
"message": "Resource group 'devcloud15-rg' could not be found."
}
}
I'm not sure why I'm receiving this error message if all other resources are deployed to the resource but the last deployment.如果所有其他资源都部署到资源但最后一次部署,我不确定为什么我会收到此错误消息。 I'm not sure if the listkeys function is causing the error with the deployment due to some dependency.
我不确定 listkeys function 是否由于某些依赖性而导致部署错误。
I changed the code to我将代码更改为
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appBaseName": {
"type": "string",
"metadata": {
"description": "Name of the application. Used in the name of resources."
},
"minLength": 5,
"maxLength": 12
},
"tenantId": {
"type": "string",
"defaultValue": "[subscription().tenantId]",
"metadata": {
"description": "Tenant ID for deployment"
}
},
"location": {
"type": "string",
"defaultValue": "eastus2",
"metadata": {
"description": "Location for deployment"
}
},
"administratorLogin": {
"type": "string",
"metadata": {
"description": "The administrator username of the SQL logical server.",
"defaultValue": "admingod"
}
},
"administratorLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL logical server.",
"defaultValue": "Passw0rd10s"
}
}
},
"variables": {
"AppInsightsName": "[concat(parameters('appBaseName'), '-AppInsights')]",
"AppServicePlanName": "[concat(parameters('appBaseName'), '-ASP')]",
"SQLServer": "[concat(parameters('appBaseName'), '-sqlserver')]",
"SQLDB": "[concat(parameters('appBaseName'), '-sqldb')]",
"WebAppName": "[concat(parameters('appBaseName'), '-web')]",
"ResourceGroupName": "[concat(parameters('appBaseName'), '-rg')]",
"storageAccountName": "[concat('stg',parameters('appBaseName'))]",
"storageAccountId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'),'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"functionName": "[concat(parameters('appBaseName'),'-fn')]",
"KeyVaultName": "[concat(parameters('appBaseName'), '-kv')]",
"ResourceGroupId": "[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2019-10-01",
"name": "[variables('ResourceGroupName')]",
"location": "[parameters('location')]",
"properties": {}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(parameters('appBaseName'),'-Storage')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"location": "[parameters('location')]",
"name": "[variables('storageAccountName')]",
"sku": {
"name": "Standard_RAGRS"
},
"kind": "StorageV2",
"properties": {}
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(parameters('appBaseName'),'-AppInsights')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[concat(parameters('appBaseName'),'-Storage')]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name":"[variables('AppInsightsName')]",
"type":"Microsoft.Insights/components",
"apiVersion":"2015-05-01",
"location":"[parameters('location')]",
"kind":"web",
"properties":{
"application_Type":"web",
"ApplicationId": "[variables('appInsightsName')]"
}
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(parameters('appBaseName'),'-KeyVault')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[concat(parameters('appBaseName'),'-AppInsights')]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[variables('KeyVaultName')]",
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2016-10-01",
"location": "[parameters('location')]",
"tags": {
"displayName": "[variables('KeyVaultName')]"
},
"properties": {
"enabledForDeployment": true,
"enabledForTemplateDeployment": true,
"enabledForDiskEncryption": true,
"tenantId": "[parameters('tenantId')]",
"accessPolicies": [
],
"sku": {
"name": "standard",
"family": "A"
}
}
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(parameters('appBaseName'),'-SQL')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[concat(parameters('appBaseName'),'-KeyVault')]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[variables('SQLServer')]",
"location": "[parameters('location')]",
"properties": {
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]"
},
"resources": [
{
"type": "databases",
"apiVersion": "2019-06-01-preview",
"name": "[variables('SQLDB')]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"location": "[parameters('location')]",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"edition": "Basic",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "Basic"
},
"dependsOn": [
"[variables('SQLServer')]"
]
}
]
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(parameters('appBaseName'),'-App')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[concat(parameters('appBaseName'),'-SQL')]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"apiVersion": "2019-08-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('AppServicePlanName')]",
"location": "[parameters('location')]",
"properties": {
"name": "[variables('AppServicePlanName')]"
},
"sku": {
"name": "F1",
"capacity": 1
}
},
{
"apiVersion": "2019-08-01",
"type": "Microsoft.Web/sites",
"name": "[variables('WebAppName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Web/serverfarms/', variables('AppServicePlanName'))]"
],
"properties": {
"name": "[variables('WebAppName')]",
"serverFarmId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Web/serverfarms/', variables('AppServicePlanName'))]"
}
}
],
"outputs": {}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "[concat(parameters('appBaseName'),'-FuncApp')]",
"resourceGroup": "[variables('ResourceGroupName')]",
"dependsOn": [
"[concat(parameters('appBaseName'),'-AppInsights')]",
"[concat(parameters('appBaseName'),'-Storage')]",
"[concat(parameters('appBaseName'),'-App')]",
"[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[variables('functionName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"location": "[parameters('location')]",
"kind": "functionapp",
"properties": {
"serverFarmId": "[concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Web/serverfarms/', variables('AppServicePlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(concat(subscription().id,'/resourcegroups/', variables('ResourceGroupName'), '/providers/Microsoft.Insights/components/', variables('AppInsightsName')), '2015-05-01').InstrumentationKey]"
},
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower('functionName')]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet"
}
]
}
}
}
],
"outputs": {}
}
}
}
],
"outputs": {}
}
I will get the same error as before我会得到和以前一样的错误
"error": {
"code": "ResourceGroupNotFound",
"message": "Resource group 'devcloud4-rg' could not be found."
}
}
Now as soon as it fails and I deploy again, it succeeds.现在,一旦它失败并且我再次部署,它就会成功。 It will fail on the FuncApp Deployment.
它将在 FuncApp 部署上失败。 I'm not sure if there is a race condition or something is not fully up with previous services.
我不确定是否存在竞争条件或以前的服务没有完全满足。
I'm not sure if there is a way to put a depends on the instrumentation key and storage key for the app Function reference under the service Plan.我不确定是否有办法将依赖于服务计划下的应用程序 Function 参考的仪器密钥和存储密钥。
You are getting that error because in the last resource(line 209) you are missing the dependsOn that you have in the previous resources.您收到该错误是因为在最后一个资源(第 209 行)中,您缺少之前资源中的dependsOn。
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
],
So the deployment try to create the Microsoft.Resources/deployments without waiting for the ResourceGroup to be created.因此,部署尝试创建 Microsoft.Resources/deployments 而无需等待创建 ResourceGroup。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.