-->

How to check if name already exists? Azure Ressour

2019-08-15 13:55发布

问题:

is it possible to check, in an ARM Template, if the name for my Virtual Machine already exists?

I am developing a Solution Template for the Azure Marketplace. Maybe it is possible to set a paramter in the UiDefinition uniqe?

The goal is to reproduce this green Hook

回答1:

A couple notes...

  • VM Names only need to be unique within a resourceGroup, not within the subscription
  • Solution Templates must be deployed to empty resourceGroups, so collisions with existing resources aren't possible
  • For solution templates the preference is that you simply name the VMs for the user, rather than asking - use something that is appropriate for the workload (e.g. jumpbox) - not all solutions do this but we're trying to improve that experience

Given that it's not likely we'll ever build a control that checks for naming collisions on resources without globally unique constraints.

That help?



回答2:

This looks impossible, according to the documentation.

There are no validation scenarious.



回答3:

I assume that you should be using the Microsoft.Common.TextBox UI element in your createUiDefinition.json.

I have tried to reproduce a green check by creating a simple createUiDefinition.json as below with a Microsoft.Common.TextBox UI element as shown below.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json",
  "handler": "Microsoft.Compute.MultiVm",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "textBoxA",
        "type": "Microsoft.Common.TextBox",
        "label": "VM Name",
        "defaultValue": "",
        "toolTip": "Please enter a VM name",
        "constraints": {
            "required": true
        },
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {}
  }
}  

I am able to reproduce the green check beside the VM Name textbox as shown below:

However, this green check DOES NOT imply the VM Name is Available. This is because based on my testing, even if I use an existing VM Name in the same subscription, it is still showing the green check.

Based on the official documented constraints that are supported by the Microsoft.Common.TextBox UI element, it DOES NOT VALIDATE Name Availability.

Hope this helps!