简体   繁体   English

ARM模板部署中资源组字段如何赋默认值?

[英]How to give default value to resource group field in ARM template deployment?

I have sample ARM template given below.我有下面给出的示例 ARM 模板。 The fields subscription, resource group and location are provided in first section ARM template to user while deploying and parameters section is provided after this.字段订阅、资源组和位置在第一部分 ARM 模板中提供给用户,同时部署和参数部分在此之后提供。 Resource group is drop down field provided by Azure ARM itself, where I need to provide any one resource group as default resource group present in list.资源组是由 Azure ARM 本身提供的下拉字段,我需要在其中提供任何一个资源组作为列表中存在的默认资源组。 How can this possible?这怎么可能?

{
    "$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')]"
        }
    }
}   

This is how template is rendered.这就是模板的呈现方式。

自定义部署

Expected solution : Instead of blank value in resource group, it should be pre-populated with first field from drop-down of resource group.预期的解决方案:而不是资源组中的空白值,它应该预先填充资源组下拉列表中的第一个字段。

A deployment with ARM templates is always providing the deployment resource group outside the template.具有 ARM 模板的部署始终在模板外部提供部署资源组。 A deployment is always based in a resource group that you provide as a parameter outside the template.部署始终基于您作为模板外部参数提供的资源组。 The name of the command to deploy using PS is: New-AzResourceGroupDeployment indicating that you have the provided resource group as a base and the argument to choose the Resource Group is named: -ResourceGroup使用 PS 部署的命令的名称是:New-AzResourceGroupDeployment,表示您将提供的资源组作为基础,选择资源组的参数名为:-ResourceGroup

So basically you can't choose the base resource group inside your ARM template since that's provided outside for the API to know where to start the deployment.所以基本上你不能在你的 ARM 模板中选择基本资源组,因为它在外部提供给 API 知道从哪里开始部署。

This is the PS command to do the deployment:这是执行部署的 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>]

The PS command is using the ARM Rest API which is the same API used by the Azure Portal, looking at the Rest API you can also see that ResourceGroup is a parameter that needs to be provided outside the ARM template: PS命令使用ARM Rest API,它是API使用的883587606064488 PORTAL。

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

So what I'm saying is that you can't use the template to manipulate the drop down box for the base Resource Group, the only way you can do this is by limiting the access for the users using RBAC so that the user only can see the resource groups the user is supposed to be able to deploy to.所以我要说的是,您不能使用模板来操作基本资源组的下拉框,唯一可以做到这一点的方法是使用 RBAC 限制用户的访问权限,以便用户只能查看用户应该能够部署到的资源组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM