gpt4 book ai didi

Azure ARM 模板取决于 : Resource Not Defined in Template

转载 作者:行者123 更新时间:2023-12-03 13:51:57 25 4
gpt4 key购买 nike

我想使用 Visual Studio 2015 在 Azure 中的资源组中创建一个新的虚拟机。新虚拟机依赖于同一资源组中的现有资源,但该资源未在模板中声明。但我得到“资源‘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只能引用同一个ARM模板中的资源?

感谢任何帮助。

问候,弗兰克。

最佳答案

DependsOn can only refer to resources in the same ARM template ?

来自此官方document关于在Azure资源管理器模板中定义依赖项,我们可以找到如下:

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.

根据我的测试,我可以重现这个问题。您需要在模板中添加存储资源,如下所示:

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

对于您的虚拟机资源,您可以在“属性 > 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"
}

存储资源将在与您的虚拟机相同的位置创建(如果不存在)。

关于Azure ARM 模板取决于 : Resource Not Defined in Template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41155546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com