Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to obtain the paired/failover region #15987

Open
Gijsreyn opened this issue Dec 31, 2024 · 9 comments
Open

Function to obtain the paired/failover region #15987

Gijsreyn opened this issue Dec 31, 2024 · 9 comments
Assignees
Labels
enhancement New feature or request Needs: Triage 🔍

Comments

@Gijsreyn
Copy link

As a user, I would like the ability to pick the zone related to the redunacy. It's better to explain it by example. Imagine the following Bicep file:

module cosmosDb 'br/public:avm/res/document-db/database-account:0.10.1' = {
  name: 'cosmosDb'
  params: {
    name: cosmosDbName
    location: 'westus'
    disableLocalAuth: true
    networkRestrictions: {
      publicNetworkAccess: 'Enabled'
      networkAclBypass: 'AzureServices'
      ipRules: [
        '13.91.105.215'
        '4.210.172.107'
        '13.88.56.148'
        '40.91.218.243'
        '0.0.0.0'
      ]
    }
    locations: [
        {
            failoverPriority: 0
            locationName: 'West US'
            isZoneRedundant: false
        }
        {
            failoverPriority: 1
            locationName: 'Central US'
            isZoneRedundant: false
        }
    ]
    enableFreeTier: false
    databaseAccountOfferType: 'Standard'
    backupPolicyType: 'Periodic'
    backupIntervalInMinutes: 240
    backupRetentionIntervalInHours: 720
    backupStorageRedundancy: 'Geo'
    defaultConsistencyLevel: 'Session'
    maxStalenessPrefix: 100
    maxIntervalInSeconds: 5
    sqlDatabases: [
      {
        name: 'test'
          }
        ]
      }
    ]
  }
}

The location parameter can be set, which takes me to the locations parameter. For the failover priority, I can use: pickZones('Microsoft.DocumentDB', 'databaseAccounts', location). The challenge is in the second part. It would be beneficial if there were a function like: pickZoneReferenceName('Microsoft.DocumentDB', 'databaseAccounts', location).

If this issue has already been captured or if such a function exists, I hope you can steer me in the right direction.

@jeskew
Copy link
Member

jeskew commented Dec 31, 2024

@Gijsreyn what value would pickZoneReferenceName return? Is it the location name?

@Gijsreyn
Copy link
Author

Gijsreyn commented Jan 1, 2025

Hey @jeskew, depending on the scenario, it should be able to return the location name in short or long e.g. westus or West US.

@majastrz majastrz changed the title Zone redunacy picker Zone redundancy picker Jan 15, 2025
@majastrz
Copy link
Member

@Gijsreyn It seems we may be mixing up logical availability zone names (1, 2, 3, ...) and location/region names such as westus. Are you asking for a function that will return the "long" location name (West US 2, for example) given a short location name (westus2, for example)?

@majastrz majastrz added the Needs: Author Feedback Awaiting feedback from the author of the issue label Jan 15, 2025
@Gijsreyn
Copy link
Author

@majastrz Marcin, you're totally correct! In the above example, there are three locations:

  1. The first one is simple, the location property. Of course, this could have been parameterized, but you get the point.
  2. The second and third ones are in the locations property.

What I'm looking for in this case is that if a user passes in the 'westus' location as a parameter, it is able to resolve the redundant "long" name, so I don't have to explicitly create three separate parameters and mess up the configuration if a user, say, puts in 'westeurope'.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Author Feedback Awaiting feedback from the author of the issue label Jan 16, 2025
@majastrz majastrz changed the title Zone redundancy picker Function to obtain the "long" location name from the "short" one Jan 16, 2025
@majastrz
Copy link
Member

@Gijsreyn Yeah, the feature request makes sense. Until the solution is available, my suggestion would be to use the "long" name convention in all your parameters and convert to short name as needed. The conversion from long to short name can be done reliably for all regions by removing whitespace in the location name and converting to lowercase.

Here's an example UDF that you could use to perform this conversion in Bicep:

func toShortName(longLocation string) string => toLower(replace(longLocation, ' ', ''))

output weu string = toShortName('West Europe')
output wus2 string = toShortName('West US 2')

This file produces the following outputs when deployed:

DeploymentName          : test
ResourceGroupName       : majastrz-test
ProvisioningState       : Succeeded
Timestamp               : 1/16/2025 1:53:50 AM
Mode                    : Incremental
TemplateLink            :
Parameters              :
Outputs                 :
                          Name             Type                       Value
                          ===============  =========================  ==========
                          weu              String                     "westeurope"
                          wus2             String                     "westus2"

DeploymentDebugLogLevel :

@Gijsreyn
Copy link
Author

@majastrz Wow, thanks Marcin! That was done quickly! The only thing that's missing is the difficulty of determining the right region in this use case. By that, I mean how can I be certain what the 'redundant' location is going to be? It would still require two (or even three) parameters to be defined.

@majastrz
Copy link
Member

@Gijsreyn By "redundant" location, do you mean the paired region to where storage and other services may fail over during a region outage?

@majastrz majastrz added the Needs: Author Feedback Awaiting feedback from the author of the issue label Jan 29, 2025
@Gijsreyn
Copy link
Author

@majastrz Correct. So in it's basic form, let's take this as example with a fictional function:

param location string = 'westeurope'

var primaryRegion string = getRegionShortName(location)[0] // <--- This should return 'West EU'
var seconaRegion string = getRegionShortName(location)[1] // <--- This should return 'North EU'

I can imagine that there are some complications whenever you create such a function, as you've to know the key pairs between the regions, as well as other regions within the same boundary?

Note

I guessed the short names in this example, but you get the point (I was a bit tired).

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Author Feedback Awaiting feedback from the author of the issue label Jan 30, 2025
@majastrz
Copy link
Member

I understand now. Currently, we do not have any functions to figure out the failover/secondary/paired region given another region, but the ask absolutely makes sense. I'm going to update the title to match this.

The only way today to find out the paired region in Bicep is to populate that information via parameters like you're doing.

It can be scripted via the Locations API. We also support it in PS via the Get-AzLocation cmdlet and its CLI equivalent.

@majastrz majastrz changed the title Function to obtain the "long" location name from the "short" one Function to obtain the paired/failover region Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Needs: Triage 🔍
Projects
Status: Todo
Development

No branches or pull requests

3 participants