簡體   English   中英

未找到使用部署模板資源和接收資源組,但所有其他部署工作

[英]Using Deployment Template resource and receiving resource group not found but all other deployments 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": {}
  }

我收到以下信息:

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 function 是否由於某些依賴性而導致部署錯誤。

我將代碼更改為

{
    "$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 部署上失敗。 我不確定是否存在競爭條件或以前的服務沒有完全滿足。

我不確定是否有辦法將依賴於服務計划下的應用程序 Function 參考的儀器密鑰和存儲密鑰。

您收到該錯誤是因為在最后一個資源(第 209 行)中,您缺少之前資源中的dependsOn。

 "dependsOn": [
      "[resourceId('Microsoft.Resources/resourceGroups/', variables('ResourceGroupName'))]"
    ],

因此,部署嘗試創建 Microsoft.Resources/deployments 而無需等待創建 ResourceGroup。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM