gpt4 book ai didi

azure - ARM 模板 - 不允许主模板中存在多个链接模板

转载 作者:行者123 更新时间:2023-12-03 01:40:20 35 4
gpt4 key购买 nike

我们正在尝试使用链接模板创建 ARM 模板。所以我从 vnet 和子网开始,创建了 2 个不同的链接模板。现在我尝试创建 master.json 和 master.parameters.json 。参数文件具有网络和一个子网的名称和地址空间的值。现在,在主模板中,我尝试使用 2 个链接模板,但 azure devops 中的发布失败并出现以下错误:部署模板验证失败:“第 37 行和第 5 列的资源“Microsoft.Resources/deployments/LinkedTemplate”在模板中定义了多次。创建或更新模板部署时任务失败。

networkSubnetTest.json

"{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetName": {
"type": "string",
"metadata": {
"description": "Name of the Virtual Network"
}
},
"vnetAddressPrefix": {
"type": "string",
"metadata": {
"description": "The IP Address pool for the virtual network in CIDR format."
}
},
"subnetPrefix": {
"type": "string",
"metadata": {
"description": "The IP Address pool for the Subnet in CIDR format."
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "Name of the Subnet"
}
}
},

"variables": {
"templateBaseUrl": "https://github.com/something/",
"virtualNetworkTemplateUrl": "[concat(variables('templateBaseUrl'), 'VirtualNetwork.json')]",
"subnetTemplateUrl": "[concat(variables('templateBaseUrl'), 'Subnet.json')]",
"parametersUrl": "[concat(variables('templateBaseUrl'), 'networksubnetnsgtest.parameters.json')]"
},

"resources": [
{
"apiVersion": "2017-05-10",
"name": "LinkedTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri":"[parameters('virtualNetworkTemplateUrl')]"
},
"parameters": {
"uri":"[parameters('parametersUrl')]"
}
}
},
{
"apiVersion": "2017-05-10",
"name": "LinkedTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri":"[parameters('subnetTemplateUrl')]"
},
"parameters": {
"uri":"[parameters('parametersUrl')]"
},
"dependsOn": [
"LinkedTemplate",
"[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
]
}
},
],

"outputs": {
"returnedVnetName": {
"type": "string",
"value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
},
"returnedVnetAddressPrefix": {
"type": "string",
"value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetAddressPrefix'))]"
}
}
}

这里的问题是,是否不可能拥有一个主模板并拥有多个链接模板?我知道有一个巨大的模板,其中包含所有内容,但我们不想要它。

最佳答案

这是我的可用 ARM 模板版本。在同时部署期间,模板 name 值肯定需要不同。如部署记录所示,一个主模板创建了三个部署。

我做了三项值得注意的更改以及其他更改来处理 URI。请参阅底部的差异输出。

enter image description here

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetName": {
"type": "string",
"metadata": {
"description": "Name of the Virtual Network"
}
},
"vnetAddressPrefix": {
"type": "string",
"metadata": {
"description": "The IP Address pool for the virtual network in CIDR format."
}
},
"subnetPrefix": {
"type": "string",
"metadata": {
"description": "The IP Address pool for the Subnet in CIDR format."
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "Name of the Subnet"
}
}
},
"variables": {
"templateBaseUrl": "[deployment().properties.templateLink.uri]",
"virtualNetworkTemplateUrl": "[uri(variables('templateBaseUrl'), 'VirtualNetwork.json')]",
"subnetTemplateUrl": "[uri(variables('templateBaseUrl'), 'Subnet.json')]",
"parametersUrl": "[uri(variables('templateBaseUrl'), 'networksubnetnsgtest.parameters.json')]"
},
"resources": [
{
"apiVersion": "2017-05-10",
"name": "VnetDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('virtualNetworkTemplateUrl')]"
},
"parameters": {
"uri": {
"value": "[variables('parametersUrl')]"
}
}
}
},
{
"apiVersion": "2017-05-10",
"name": "SubnetDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('subnetTemplateUrl')]"
},
"parameters": {
"uri": {
"value": "[variables('parametersUrl')]"
}
}
},
"dependsOn": [
"VnetDeployment"
]
}
],
"outputs": {
"returnedVnetName": {
"type": "string",
"value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
},
"returnedVnetAddressPrefix": {
"type": "string",
"value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetAddressPrefix'))]"
}
}
}

差异输出 enter image description here

用于执行的 PowerShell 部分:

$templateUri = 'https://<storageAccountName>.blob.core.windows.net/<containerName>/Lab/Master-Fixed.json'
$parameters = @{ 'vnetName' = 'myvnet'; 'vnetAddressPrefix' = '10.0.0.0/16'; 'subnetPrefix' = '10.0.0.0/24'; 'subnetName' = 'mysubnet'; }
New-AzureRmResourceGroupDeployment -Name "brstring-20190124" -ResourceGroupName $resourceGroupName -TemplateUri $templateUri @parameters

关于azure - ARM 模板 - 不允许主模板中存在多个链接模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54355229/

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