简体   繁体   English

Azure ARM模板DependOn:模板中未定义资源

[英]Azure ARM Template dependsOn: Resource Not Defined in Template

I want to create a new vm to resource group in azure with visual studio 2015. the new vm depends on an existing resource in the same resource group , that isn't declared in the template. 我想使用Visual Studio 2015在azure中为资源组创建一个新的vm。新的vm取决于模板中未声明的同一资源组中的现有资源。 but I got "The resource 'Microsoft.Storage/storageAccounts/***' is 02:21:10 - not defined in the template" 但我收到“资源'Microsoft.Storage/storageAccounts/***'是02:21:10-未在模板中定义”

"resources": [
{
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[variables('vmName')]",
  "location": "[resourceGroup().location]",
  "tags": {
    "displayName": "VirtualMachine"
  },
  "dependsOn": [
    "[resourceId('0abb7c58-93b4-45f4-b1be-61a98ac347a3','securitydata','Microsoft.Storage/storageAccounts', parameters('storageAccounts_simscitestrg6892_name'))]"
  ],

DependsOn can only refer to resources in the same ARM template ? DependsOn只能引用同一ARM模板中的资源吗?

Any help appreciated. 任何帮助表示赞赏。

Regards, Frank. 问候,弗兰克。

DependsOn can only refer to resources in the same ARM template ? DependsOn只能引用同一ARM模板中的资源吗?

From this official document about defining dependencies in Azure Resource Manager templates, we could find as follows: 从这份有关在Azure Resource Manager模板中定义依赖项的正式文档中,我们可以找到以下内容:

Resource Manager evaluates the dependencies between resources, and deploys them in their dependent order. 资源管理器评估资源之间的依赖关系,并按其依赖顺序进行部署。 When resources are not dependent on each other, Resource Manager deploys them in parallel. 当资源彼此不依赖时,资源管理器将并行部署它们。 You only need to define dependencies for resources that are deployed in the same template . 您只需要为部署在同一模板中的资源定义依赖关系

Based on my test, I could reproduce this issue. 根据我的测试,我可以重现此问题。 You need to add the Storage resource within your template as follows: 您需要按照以下步骤在模板中添加存储资源:

{
    "name": "[parameters('storageAccounts_simscitestrg6892_name')]",
    "type": "Microsoft.Storage/storageAccounts",
    "location": "[resourceGroup().location]",
    "apiVersion": "2015-06-15",
    "dependsOn": [],
    "tags": {
      "displayName": "StorageAccountResourceName"
    },
    "properties": {
      "accountType": "[parameters('StorageAccountType')]"
    }
}

For your VM resource, you could configure the osDisk under the "properties > storageProfile" section as follows: 对于您的VM资源,可以在“属性> storageProfile”部分下配置osDisk ,如下所示:

"osDisk": {
  "name": "Your-VMOSDisk",
  "vhd": {
    "uri": "[concat('https://', parameters('storageAccounts_simscitestrg6892_name'), '.blob.core.windows.net/', variables('Your-VMStorageAccountContainerName'), '/', variables('Your-VMOSDiskName'), '.vhd')]"
  },
  "caching": "ReadWrite",
  "createOption": "FromImage"
}

The storage resource would be created under the same location as your VM, if not exists. 如果不存在,将在与VM相同的位置创建存储资源。

No, this makes no sense, the dependsOn property is meant to track dependencies inside the ARM template, so it can provision resources in specific order. 不,这没有任何意义,dependsOn属性用于跟踪ARM模板内部的依赖关系,因此它可以按特定顺序配置资源。 If a resource is there, there's no sense to track it. 如果有资源,就没有追踪的可能。 It's already there. 它已经在那里。 You just reference it when you use it. 您只在使用时引用它。

Yes. 是。 DependsOn is used when you are creating a resources which depends on another resource which you are creating via the same template. 当您创建依赖于通过同一模板创建的另一个资源的资源时,将使用DependsOn。 If the resource is already created then you just add a reference to it. 如果资源已经创建,则只需添加对该资源的引用。 In your case, you can add properties key for the VM like this: 根据您的情况,您可以为VM添加属性键,如下所示:

"properties": {
                "hardwareProfile": {
                    "vmSize": "Standard_DS1"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "MicrosoftWindowsServerHPCPack",
                        "offer": "WindowsServerHPCPack",
                        "sku": "2012R2",
                        "version": "latest"
                    },
                    "osDisk": {
                        "name": "[parameters('virtualMachines_APP01_name')]",
                        "createOption": "FromImage",
                        "vhd": {
                            "uri": "[concat('https', '://', parameters('storageAccounts_vmdkstorageacct_name'), '.blob.core.windows.net', concat('/vhds/', parameters('virtualMachines_APP01_name'),'APP01.vhd'))]"
                        },
                        "caching": "ReadWrite"
                    },
                    "dataDisks": []
                },
                "osProfile": {
                    "computerName": "[parameters('virtualMachines_APP01_name')]",
                    "adminUsername": "vmadmin",
                    "windowsConfiguration": {
                        "provisionVMAgent": true,
                        "enableAutomaticUpdates": true
                    },
                    "secrets": [],
                    "adminPassword": "[parameters('virtualMachines_APP01_adminPassword')]"
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_app01_name'))]"
                        }
                    ]
                }
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM