How to check if name already exists? Azure Ressource Manager Template

倾然丶 夕夏残阳落幕 提交于 2019-12-11 04:39:38

问题


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!



来源:https://stackoverflow.com/questions/49006914/how-to-check-if-name-already-exists-azure-ressource-manager-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!