2

I am trying to write a generic Bicep file that creates a storage account. I am trying to following the standard naming convention when creating the resource, eg: it would be something like st<storage name><location-code><###>. What I want to do is parameterize the 'location' value. If I do this though, how can I get the abbreviated 'region code' to put in the name. Eg: If I pass in Central US as the region, the name would be sttestcus001. If I put in East US, the name would be sttesteus001.

Thanks,

Thomas
  • 24,234
  • 6
  • 81
  • 125
dan
  • 45
  • 3

1 Answers1

3

You could always maintain an object that will do the mapping for you:

param location string = 'Central US'

// Object containing a mapping for location / region code
var regionCodes = {
  centralus: 'cus'
  eastus: 'eus'
}

// remove space and make sure all lower case
var satinatizedLocation = toLower(replace(location, ' ', ''))

// get the region code
var regionCode = regionCodes[satinatizedLocation]
Thomas
  • 24,234
  • 6
  • 81
  • 125
  • It would be really nice to be able to readily convert these in bicep, so like from australiaeast to aue, but within the bicep itself. Anyone know of a way? – Ben Power Aug 09 '23 at 00:19