【发布时间】:2021-07-09 21:22:08
【问题描述】:
我有一个主 ARM 模板,我们称之为 azuredeploy.json,还有一个链接模板,我们称之为 privateEndpoint.json。我有一个决定是否部署资源的参数,我们称之为enablePrivateEndpoints。它当前设置为“false”,因此不会发生此资源的部署。
在相反的情况下,应读取“privateEndpoint.json”的输出以获取专用端点的 networkInterface id。
azuredeploy.json
{
"condition": "[not(equals(parameters('enablePrivateEndpoints'), 'false'))]",
"name": "keyvault-privateendpoint",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"dependsOn": [
"keyvault"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(variables('templateFolderUrl'), '/', variables('privateEndpointTemplateFileName'), parameters('_artifactsLocationSasToken'))]"
},
"parameters": {
...
...
"enablePrivateEndpoints": "[parameters('enablePrivateEndpoints')]"
}
}
},
},
{
"condition": "[not(equals(parameters('enablePrivateEndpoints'), 'false'))]",
"name": "networkInterface-kv",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(variables('templateFolderUrl'), '/', variables('networkInterfaceTemplateFileName'), parameters('_artifactsLocationSasToken'))]"
},
"parameters": {
"networkInterfaceId": {
"value": "[reference('keyvault-privateendpoint', '2021-04-01').outputs.networkInterfaceId.value]"
}
}
}
}
privateEndpoint.json
...
"enablePrivateEndpoints": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"name": "[parameters('privateEndpointName')]",
"type": "Microsoft.Network/privateEndpoints",
"apiVersion": "2021-04-01",
"location": "[resourceGroup().location]",
"dependsOn": [],
"properties": "[parameters('privateEndpointProperties')]"
}
],
"outputs": {
"networkInterfaceId": {
"condition": "[not(equals(parameters('enablePrivateEndpoints'), 'false'))]",
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/privateEndpoints', parameters('privateEndpointName'))).networkInterfaces[0].id]"
}
}
问题在于这段代码:
"networkInterfaceId": {
"value": "[reference('keyvault-privateendpoint', '2021-04-01').outputs.networkInterfaceId.value]"
}
尽管条件停止了引用资源的部署,但仍在评估引用函数。部署失败并显示 “DeploymentNotFound: The deployment 'keyvault-privateendpoint' could not be found”
以下是我尝试解决此问题的一些方法:
尝试 #1
您可以看到我已经尝试向输出本身添加条件
"outputs": {
"networkInterfaceId": {
"condition": "[not(equals(parameters('enablePrivateEndpoints'), 'false'))]",
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/privateEndpoints', parameters('privateEndpointName'))).networkInterfaces[0].id]"
}
}
这并没有解决问题
尝试 #2
我尝试将 if 添加到正在查看输出本身的值,仅在 enablePrivateEndpoints 参数为 true 时评估参考函数。
"networkInterfaceId": {
"value": "[if(parameters(enablePrivateEndpoints), reference('keyvault-privateendpoint', '2021-04-01').outputs.networkInterfaceId.value, '')]"
}
这也没有解决问题。
我不明白为什么仍在尝试引用不存在的部署。
我的意思是即使是进行引用的部署资源本身也是有条件的。
注意:这些资源还没有成功部署,所以是新的。
【问题讨论】:
标签: azure azure-resource-manager arm-template