找不到使用部署模板资源并接收资源组,但所有其他部署均正常工作

时间:2020-07-25 02:10:30

标签: azure arm-template

在部署以下内容时,最终部署始终会失败,并且找不到资源组。以前的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": {}
  }

我收到以下信息:

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."
  }
}

我不确定如果所有其他资源(最后一次部署)都部署到该资源,为什么会收到此错误消息。我不确定listkeys函数是否由于某些依赖性而导致部署错误。

我将代码更改为

{
    "$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": {}
  }

我将得到与以前相同的错误

  "error": {
    "code": "ResourceGroupNotFound",
    "message": "Resource group 'devcloud4-rg' could not be found."
  }
}

现在,一旦失败,我又重新部署,它就会成功。在FuncApp部署中它将失败。我不确定以前的服务是否存在争用情况或某些功能没有完全解决。

我不确定是否可以根据服务计划下的“应用功能参考”来确定依赖于检测键和存储键的方式。

1 个答案:

答案 0 :(得分:0)

由于在最后一个资源(第209行)中缺少先前资源中的dependsOn,所以您遇到了该错误。

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 628, in run
    testMethod()
  File "/Users/xxxxx/PycharmProjects/setup/test.py", line 184, in test_403_forbidden
    self.assertTrue("403 Error" in response.data)
TypeError: a bytes-like object is required, not 'str'

因此,部署尝试创建Microsoft.Resources / deployments,而不等待创建ResourceGroup。