我尝试开始使用Azure RM模板,并在尝试部署从Azure门户中的资源组导出的模板时遇到一些问题。
当我尝试部署导出的模板时,出现以下错误:
{" telemetryId":" 5d4b90de-18fd-432f-a6c7-cfa65eb22bc8"" galleryItemId":" MyGalleryItem"&# 34; createBlade":" DeployToAzure"," code":" InvalidTemplate"," message":"部署模板验证失败:'模板资源' myVM-nic'在线' 1'和专栏' 3020'无效:无法评估模板语言功能' resourceId':函数只需要一个多段参数,该参数必须是资源类型,包括资源提供程序命名空间。当前函数参数' Microsoft.Network/virtualNetworks/subnets,vnet-myVnet/Subnet'。有关使用详情,请参阅Plunkr2 ..有关使用详情,请参阅https://aka.ms/arm-template-expressions/#resourceid。'。"}
以下是Azure生成的模板副本:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"disks_myVM_OsDisk_1_35091da3da6d4b0098638ba9569de541_name": {
"defaultValue": "myVM_OsDisk_1_35091da3da6d4b0098638ba9569de541",
"type": "String"
},
"virtualMachines_myVM_name": {
"defaultValue": "myVM",
"type": "String"
},
"networkInterfaces_myVM_nic_name": {
"defaultValue": "myVM-nic",
"type": "String"
},
"virtualNetworks_vnet_myVnet_name": {
"defaultValue": "vnet-myVnet",
"type": "String"
},
"subnets_Subnet_name": {
"defaultValue": "vnet-myVnet/Subnet",
"type": "String"
}
},
"variables": {},
"resources": [
{
"comments": "Generalized from resource: '/subscriptions/293f1da7-6528-4a0a-a699-afea0f33f605/resourceGroups/simplelinuxvmtest/providers/Microsoft.Compute/disks/myVM_OsDisk_1_35091da3da6d4b0098638ba9569de541'.",
"type": "Microsoft.Compute/disks",
"name": "[parameters('disks_myVM_OsDisk_1_35091da3da6d4b0098638ba9569de541_name')]",
"apiVersion": "2016-04-30-preview",
"location": "australiaeast",
"tags": {
"Role": "Web"
},
"scale": null,
"properties": {
"accountType": "Standard_LRS",
"osType": "Linux",
"creationData": {
"createOption": "FromImage",
"imageReference": {
"id": "/Subscriptions/293f1da7-6528-4a0a-a699-afea0f33f605/Providers/Microsoft.Compute/Locations/australiaeast/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.5-LTS/Versions/latest"
}
},
"diskSizeGB": 30
},
"dependsOn": []
},
{
"comments": "Generalized from resource: '/subscriptions/293f1da7-6528-4a0a-a699-afea0f33f605/resourceGroups/simplelinuxvmtest/providers/Microsoft.Compute/virtualMachines/myVM'.",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('virtualMachines_myVM_name')]",
"apiVersion": "2016-04-30-preview",
"location": "australiaeast",
"tags": {
"Role": "Web"
},
"scale": null,
"properties": {
"hardwareProfile": {
"vmSize": "Standard_A1"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "14.04.5-LTS",
"version": "latest"
},
"osDisk": {
"osType": "Linux",
"name": "[concat(parameters('virtualMachines_myVM_name'),'_OsDisk_1_35091da3da6d4b0098638ba9569de541')]",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS",
"id": "[resourceId('Microsoft.Compute/disks', parameters('disks_myVM_OsDisk_1_35091da3da6d4b0098638ba9569de541_name'))]"
},
"diskSizeGB": 30
},
"dataDisks": []
},
"osProfile": {
"computerName": "[parameters('virtualMachines_myVM_name')]",
"adminUsername": "simplelinuxvmtest",
"linuxConfiguration": {
"disablePasswordAuthentication": false
},
"secrets": []
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_myVM_nic_name'))]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Compute/disks', parameters('disks_myVM_OsDisk_1_35091da3da6d4b0098638ba9569de541_name'))]",
"[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_myVM_nic_name'))]"
]
},
{
"comments": "Generalized from resource: '/subscriptions/293f1da7-6528-4a0a-a699-afea0f33f605/resourceGroups/simplelinuxvmtest/providers/Microsoft.Network/networkInterfaces/myVM-nic'.",
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('networkInterfaces_myVM_nic_name')]",
"apiVersion": "2017-06-01",
"location": "australiaeast",
"tags": {
"Role": "Web Server"
},
"scale": null,
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "2ed4e85c-c451-4eeb-9ca3-6d7f4e97288e",
"ipConfigurations": [
{
"name": "ipconfig1",
"etag": "W/\"53f452fd-21b6-42e9-9b61-84123c4ede84\"",
"properties": {
"provisioningState": "Succeeded",
"privateIPAddress": "10.0.0.4",
"privateIPAllocationMethod": "Static",
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('subnets_Subnet_name'))]"
},
"primary": true,
"privateIPAddressVersion": "IPv4"
}
}
],
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": [],
"internalDomainNameSuffix": "3f5fso43uj3ehpjjv2hnsf0ynf.px.internal.cloudapp.net"
},
"macAddress": "00-0D-3A-D1-47-FC",
"enableAcceleratedNetworking": false,
"enableIPForwarding": false,
"primary": true,
"virtualMachine": {
"id": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_myVM_name'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('subnets_Subnet_name'))]",
"[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_myVM_name'))]"
]
},
{
"comments": "Generalized from resource: '/subscriptions/293f1da7-6528-4a0a-a699-afea0f33f605/resourceGroups/simplelinuxvmtest/providers/Microsoft.Network/virtualNetworks/vnet-myVnet'.",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('virtualNetworks_vnet_myVnet_name')]",
"apiVersion": "2017-06-01",
"location": "australiaeast",
"scale": null,
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "3b597ee9-a2dd-437a-bd29-af0ed917586d",
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "Subnet",
"etag": "W/\"733f320c-fce1-4a70-9a2c-166f61f0b543\"",
"properties": {
"provisioningState": "Succeeded",
"addressPrefix": "10.0.0.0/24"
}
}
],
"virtualNetworkPeerings": []
},
"dependsOn": []
},
{
"comments": "Generalized from resource: '/subscriptions/293f1da7-6528-4a0a-a699-afea0f33f605/resourceGroups/simplelinuxvmtest/providers/Microsoft.Network/virtualNetworks/vnet-myVnet/subnets/Subnet'.",
"type": "Microsoft.Network/virtualNetworks/subnets",
"name": "[parameters('subnets_Subnet_name')]",
"apiVersion": "2017-06-01",
"scale": null,
"properties": {
"provisioningState": "Succeeded",
"addressPrefix": "10.0.0.0/24"
},
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworks_vnet_myVnet_name'))]"
]
}
]
}
我做错了什么?如果您无法从现有资源组导出工作模板,那么ARM模板的重点是什么?
答案 0 :(得分:2)
你的问题在于:
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('subnets_Subnet_name'))]"
},
错误明确指出
'resourceId':函数只需要一个多分段参数 必须是资源类型,包括资源提供者命名空间。 当前函数参数 'Microsoft.Network/virtualNetworks/subnets,vnet-myVnet/Subnet'。
因此,您必须重做模板以不将子网作为单独的资源包含,或者创建一个从parameters('subnets_Subnet_name')
中提取正确的vnet \ subnet名称并将每个名称传递给resourceId函数的变量,因此它看起来像此
"[resourceId(`Microsoft.Network/virtualNetworks/subnets, 'vnet-myVnet', 'Subnet')]"
添加如下变量:
variables: {
...
"subnetSplit": "[split(parameters('subnets_subnet_name))]"
...
}
像这样引用它:
"subnet" {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('subnetSplit')[0], variables('subnetSplit')[1])]"
}