1

I'm using Azure java SDK as a client for creating resources on Azure. I'm trying to validate the resource name before creating it. I'm able to check if the resource with the given name already exists in that resource group, but I want to validate if the resource name is valid. Example: For creating a resource of type Microsoft.Storage/storageAccounts, the naming convention is to use a-z 0-9. Similarly, for different resource types, the naming convention is different like max length.

I tried using this API, but this API only checks if the resource name contains any reserved keywords.

Is there a way either in Azure java SDK or an Azure public API for achieving this?

HyperioN
  • 3,433
  • 2
  • 22
  • 36

3 Answers3

1

There now exists a tool that can do this. The Azure Naming Tool: https://azurenamingtool.azurewebsites.net/

I.E. for your Storage Account Example, it contains the corresponding RegEx and field length that would apply when creating the account.

enter image description here

The tool includes an API for programmatic integration and you could run it as a Docker container locally or deploy it into anything that can run containers.

holger
  • 788
  • 6
  • 8
0

In short, there is no such API or SDK to check resource names with different naming rules. Only an article summarizes naming rules and restrictions for Azure resources.

This blog summarizes some rules for almost all Azure resources: https://www.ironstoneit.com/blog/naming-conventions-for-azure.

Let's establish some rules that can be used for almost all Azure resources:

  • Use lowercase
  • Use hyphens where permitted
  • Include the service name
  • Prefix/Suffix with Azure Service abbreviation
  • No spaces! Resource names should be made up of a minimum of 3 parts joined together without delimiters. There should not be any spaces in the resource name. Use hyphens where permitted!
  • Highly available resources should include an instance number.
  • (Add your own rule(s) here)
unknown
  • 6,778
  • 1
  • 5
  • 14
0

If you want to check Azure Resource Name, we can use the following rest API

POST https://management.azure.com/providers/Microsoft.Resources/checkResourceName?api-version=2020-01-01


{
  "name": "",
  "type": "<resource type>",
 
}
Jim Xu
  • 21,610
  • 2
  • 19
  • 39