Provide a template Function to generate a name
I've been modelling some infrastructure with Azure Resource Manager Templates, and feel like there's a bit of effort required to pick names for resources I don't really care so much about having a 'pretty' name (ie storage accounts, NIC names etc). I'd really like either an option to randomly generate a name, or ideally a template function that allows a random name to be created, possibly with a partial string of my choosing.
generateName('Microsoft.Storage/storageAccount') # return a valid, random name for a storage account
generateName('Microsoft.Storage/storageAccount', parameter('vmName')) # return a valid name for a storage account that begins with whatever the parameter 'vmName' is set to
In this way, it's sort of like the padLeft() function, but instead of zeros, it's random chars. And needs to be resource aware, because storage accounts can't have hyphens in the name, but Virtual Machines could.
Hopefully I've explained the use case in a way that makes sense!
While we certainly understand the benefit of such a feature, we should probably not implement it inside Resource Manager for a few reasons:
1) Resource Manager doesn’t have intrinsic knowledge of the resources we manage. Therefore, functions cannot have resource-specific logic in them.
2) Resource Manager templates are idempotent and deterministic. As a result, running a template multiple times must result in the same outcome. Introducing a rand/generate function breaks this model – and also breaks the behaviors many folks expect from templates today – it’s what allows you to re-run a template deployment to “retry.”
Unfortunately, many students undermine the importance of writing as they consider this paper part a waste of time. Still, if you need to prepare some large writing project, such as a term paper, a thesis paper or a dissertation of PhD level, writing is a must if you want to properly structure such a long writing project. Here you can find how to do it https://thesisleader.com/buy-outline/
Have you read a tutorial on the uniqueString() function? It's used exactly when you should create a unique name for a resource: https://www.codeisahighway.com/use-uniquestring-function-to-generate-unique-names-for-resources-in-arm-template/
Kia Zhi Tang commented
Alternatively, you can use the uniqueString() function to generate a hash that is pretty unique depending on what you have input into the function.
For example, as below:
[uniqueString(parameters('VMName'), parameters('VMAdminUsername'), parameters('VMAdminPassword'), resourceGroup().id, resourceGroup().location, deployment().name)]
Someone Who Despises You commented
I am wondering why these morons in Microsoft are so freaking stupid.
There are a million ways to skin a cat and there is always a reason to do something in software development and specially in automation. Thankfully, these morons as just trying to be like AWS.
Good luck with that!
Sure, I've considered it. How exactly do you do that in combination with the "Deploy to Azure" button functionality from the Azure Quickstart Templates on GitHub. This is really a pain when you do *anything* requiring a storage account. As it stands there is no way to select an existing sa, nor can you generate a random string. So if the end user accidently selects a "newStorageAccountName" that already exists anywhere on Earth the template fails. So being able to generate a random string would be really useful actually. Without resorting to kludging a js hack into your "Deploy to Azure" button functionality.