0
votes

I have sample ARM template given below. 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. 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. 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.

custom deployment

Expected solution: Instead of blank value in resource group, it should be pre-populated with first field from drop-down of resource group.

1
I'll be surprised if this is possiblePaolo
like we provide default value to user provided parameter with choices, in same way can we do for ARM basic block? @PaoloAkash Pagar
The problem is that subscription and resource group are managed by Azure. You may do something like this stackoverflow.com/questions/48183581/… as a hackPaolo

1 Answers

2
votes

A deployment with ARM templates is always providing the deployment resource group outside the template. 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

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.

This is the PS command to do the deployment:

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:

https://docs.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.