【问题标题】:How to give default value to resource group field in ARM template deployment?如何在 ARM 模板部署中为资源组字段赋予默认值?
【发布时间】:2020-08-20 09:17:17
【问题描述】:

我有下面给出的示例 ARM 模板。字段订阅、资源组和位置在部署时提供给用户的第一部分 ARM 模板,之后提供参数部分。资源组是 Azure ARM 本身提供的下拉字段,我需要在其中提供任何一个资源组作为列表中存在的默认资源组。这怎么可能?

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "writePermission": {
            "defaultValue": "No",
            "allowedValues": [
                "No",
                "Yes"
            ],
            "type": "String",
            "metadata": {
                "description": "the permission type"
            }
        }
    },
    "variables": {
        "location": "[resourceGroup().location]",
        "templateUri": "[deployment().properties.templateLink.uri]"
    },
    "resources": [
    ],
    "outputs": {
        "result": {
            "type": "String",
            "value": "[variables('templateUri')]"
        }
    }
}   

这就是模板的渲染方式。

预期的解决方案: 而不是资源组中的空白值,它应该预先填充资源组下拉列表中的第一个字段。

【问题讨论】:

  • 如果这是可能的,我会感到惊讶
  • 就像我们为用户提供的带有选项的参数提供默认值一样,我们可以为 ARM 基本块做同样的事情吗? @Paolo
  • 问题是 subscriptionresource group 是由 Azure 管理的。你可以做这样的事情stackoverflow.com/questions/48183581/… 作为一个黑客

标签: azure arm-template


【解决方案1】:

使用 ARM 模板的部署始终提供模板之外的部署资源组。部署始终基于您作为模板外部参数提供的资源组。使用 PS 部署的命令名称为:New-AzResourceGroupDeployment,表示您以提供的资源组为基础,选择资源组的参数命名为:-ResourceGroup

所以基本上你不能在你的 ARM 模板中选择基本资源组,因为它是在外部提供的,以便 API 知道从哪里开始部署。

这是执行部署的 PS 命令:

New-AzResourceGroupDeployment
   [-Name <String>]
   -ResourceGroupName <String>
   [-Mode <DeploymentMode>]
   [-DeploymentDebugLogLevel <String>]
   [-RollbackToLastDeployment]
   [-RollBackDeploymentName <String>]
   [-Tag <Hashtable>]
   [-WhatIfResultFormat <WhatIfResultFormat>]
   [-WhatIfExcludeChangeType <String[]>]
   [-Force]
   [-AsJob]
   -TemplateFile <String>
   [-SkipTemplateParameterPrompt]
   [-ApiVersion <String>]
   [-Pre]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

PS命令使用的是ARM Rest API,与Azure Portal使用的API相同,查看Rest API你还可以看到ResourceGroup是一个需要在ARM模板之外提供的参数:

https://docs.microsoft.com/en-us/rest/api/resources/deployments/createorupdate

所以我要说的是,您不能使用模板来操作基本资源组的下拉框,您可以这样做的唯一方法是限制使用 RBAC 的用户的访问权限,以便用户只能看到该用户应该能够部署到的资源组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2023-03-14
    • 2020-07-21
    相关资源
    最近更新 更多