我正在使用ARM模板进行
A。部署资源组 B.部署ASE环境。
要做到这两者,据我所知,我需要在范围订阅级别上运行部署
New-AzDeployment -Name TestingASE -TemplateFile $HOME/azuredeploy.json -TemplateParameterFile $HOME/parameters.json -Location 'West Europe'
我的模板已经很长了-所以这是最重要的部分(我认为)。
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
....
"resources": [
// Resource Group
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2018-05-01",
"location": "[parameters('Location')]",
"name": "[parameters('rgName')]",
"properties": {}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-05-01",
"name": "storageDeployment",
"resourceGroup": "[parameters('rgName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('rgName'))]"
],
"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-04-01",
"name": "[parameters('asevnetname')]",
"type": "Microsoft.Network/virtualNetworks",
"location": "[parameters('Location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('addressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
...
{
"apiVersion": "2019-02-01",
"type": "Microsoft.Web/hostingEnvironments",
"name": "[parameters('aseName')]",
"kind": "ASEV2",
"location": "[parameters('Location')]",
"properties": {
"name": "[parameters('aseName')]",
"location": "[parameters('Location')]",
"InternalLoadBalancingMode": "[parameters('ilbMode')]",
"virtualNetwork": {
"Id": "[resourceId(subscription().id, resourceGroup().Id, 'Microsoft.Network/virtualNetworks/subnets',parameters('asevnetname'),parameters('subnetName'))]"
}
....
这给了我一个输出“在此位置不期望模板函数'RESOURCEGROUP'” 据我了解,我正在遵循准则 https://docs.microsoft.com/en-gb/azure/azure-resource-manager/templates/template-functions-resource#resourcegroup
在订阅级别部署的模板中不能使用resourceGroup()函数。它只能在已部署到资源组的模板中使用。您可以在以资源组为目标的链接或嵌套模板(具有内部作用域)中使用resourceGroup()函数,即使将父模板部署到订阅中也是如此。在这种情况下,链接或嵌套的模板将部署在资源组级别。
感谢您的帮助。
答案 0 :(得分:1)
错误发生在resourceId格式,应该是
resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2], ...)
要获取同一预订中资源的资源ID, 不同的资源组,请提供资源组名称。
"[resourceId('otherResourceGroup', 'Microsoft.Storage/storageAccounts', 'examplestorage')]"
因此,在这种情况下,virtualNetwork
属性中的Microsoft.Web/hostingEnvironments
ID应该是
"virtualNetwork": {
"Id": "[resourceId(parameters('rgName'), 'Microsoft.Network/virtualNetworks/subnets',parameters('asevnetname'),parameters('subnetName'))]"
}
或
"Id": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets',parameters('asevnetname'),parameters('subnetName'))]"
有关更多信息,您可以从this template获得更多参考来在子网中部署ASE。