简体   繁体   中英

Azure Bicep\ARM - Get shortened region name for resource naming

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,

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM