Bicep create random string with length of x

Copper Contributor

Hi

Trying to create a storage account and I run into problems that StorageAccountAlredyTaken. 

 

What is best practice of doing this. 

 

// getting paramerts from json file
param storageName string

//pseudo code
1. get length of storageName
2. add random string behind "storageName" and add a random length of x-characters so that the storage name get 24 characters

ex 
storageName = rg-supercode-dev-westeurope-<random>(total of 24 characters length)
1 Reply

@thunem25 

 

Try this: (replace the string interpolations with your own)

 

var storageAccountNameLong = '${environment}${uniqueString(resourceGroup().id)}'
var storageAccountName = substring(storageAccountNameLong, 0, 20)