gpt4 book ai didi

json - ARM 模板中的预定义资源组

转载 作者:行者123 更新时间:2023-12-02 23:46:40 25 4
gpt4 key购买 nike

我正在制作自定义 ARM 模板。

我希望将特定的资源组硬编码到 JSON 中,以便打开模板时,它将模拟“资源组:使用现有:预定义的选定资源组”

我已经摸索了几个小时并深入搜索了网络,我还尝试导出现有资源组模板并将其导入到自定义部署,但它仍然显示

资源组*创建新的*使用现有的

有没有办法在 JSON 模板中定义现有的 RG?

最佳答案

您可以使用嵌套模板,如 @4c74356b41 所说,但您仍然会在门户上看到丑陋的“选择资源组”字段。

我也有类似的问题(即使@4c74356b41反复声称它没有任何意义)。我想从参数生成资源组名称。

您可以在此处找到有关如何使用嵌套模板的更多信息:Create resource group and deploy resources

{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
"someName": {
"type": "string"
}
},
"variables": {
"rgName": "[concat('rg-', parameters('someName'))]"
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2018-05-01",
"location": "[parameters('rgLocation')]",
"name": "[variables('rgName')]",
"properties": {}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2018-05-01",
"name": "rgDeployment",
"resourceGroup": "[variables('rgName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', variables('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": [
{
// PUT YOUR RESOURCES TEMPLATES HERE! //
}
],
"outputs": {}
}
}
}
],
"outputs": {}
}

只需将 rgName 变量替换为您的实际资源组名称。

关于json - ARM 模板中的预定义资源组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48183581/

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