Search code examples
azureazure-resource-managerazure-rm-template

Azure ARM Template - conditional input parameter


In Short:

Is it possible to have condition field (or something else to achieve this functionality), inside a parameter, so that this parameter input will be asked to the user, only based on another parameter's value.

i.e., Only if user selects Create New on a parameter, the input for the name of that parameter should be asked.


In Detail:

I have a parameter virtualNetworkCreateNewOrUseExisting which will accept two values - Create New and Use Existing.

"parameters": {
    "virtualNetworkCreateNewOrUseExisting": {
        "type": "string",
        "defaultValue": "Create New",
        "allowedValues": [
            "Create New",
            "Use Existing"
        ]
    },
    // Other parameters
}

I am trying to create a Virtual Network based on an input from user. If user selects Create New, it will be created, and if they select Use Existing, it will be skipped. I see that this is achievable by using condition field inside the resource.

"resources": [
    {
        "condition": "[equals(parameters('virtualNetworkCreateNewOrUseExisting'), 'Create New')]",
        // Other fields
    }
    // Other resources
]

Now, my question here is that,

Similar to this, is it possible to have condition field, inside another parameter, so that this parameter input will be asked to the user, only based on the previous parameter value.

i.e., Only if user selects Create New, the input for Virtual Network Name should be asked.

Something like this, by using a condition field:

"parameters": {
    "virtualNetworksName": {
        "condition": "[equals(parameters('virtualNetworkCreateNewOrUseExisting'), 'Create New')]",
        "defaultValue": "vn-1",
        "type": "string"
    },
    // Other parameters
}

But, I see that condition field, is not supported inside parameters (at least as of now).

Or, is it at least possible to have, if statements, like this (So that, the value of the field will be displayed empty by default if user selects Use Existing.):

"parameters": {
    "virtualNetworksName": {
        "defaultValue": "[if(equals(parameters('virtualNetworkCreateNewOrUseExisting'),'Create New'), 'vn-1', '')]",
        "type": "string"
    },
    // Other parameters
}

Or, any other way to achieve this goal?


Solution

  • You can't do this natively in the template file, but in the portal user experiences for deploying the template you can... See:

    https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-specs-create-portal-forms

    and

    https://learn.microsoft.com/en-us/azure/azure-resource-manager/managed-applications/create-uidefinition-overview

    You don't have to use a templateSpec or managedApp (see the "Deploy to Azure button here: https://github.com/Azure/azure-quickstart-templates/tree/master/demos/100-marketplace-sample )

    but templateSpec or managedApp will give you a better experience if that's an option.