Lombiq/Infrastructure-Scripts

AzureWebAppSql scripts should support not having the DB (server) and App in the same Resource Group (INFRA-141)

Closed this issue · 0 comments

The scripts under PowerShell/Azure/Sql are built to work with databases whose connection strings are read from the consumer Web App's configuration. These scripts assume that the DB server lives in the same Resource Group as the App, which is true for our own Azure resources, but it cannot be enforced. Let's make the necessary changes to support this scenario. BTW Blob Storage Accounts don't have the same problem, because those are accessed by their name only, regardless of the Resource Group they are in.

The common entry point for these operations is Get-AzureWebAppSqlDatabase: this module needs to have a non-mandatory parameter added called DatabaseResourceGroupName, which is initialized to the existing ResourceGroupName parameter. Then, DatabaseResourceGroupName should be passed to the Get-AzSqlDatabase command instead of ResourceGroupName.

The same concept has to be applied to every module that calls Get-AzureWebAppSqlDatabase.

Copy-AzureWebAppSqlDatabase is a special case, since the copy operation has a source and a target, so it needs two parameters added instead of just one.

Better solution:
Get-AzureWebAppSqlDatabaseConnection was updated to grab the Server by its name (in contrast to fetching a Database, this one doesn't require a ResourceGroupName parameter), and pass on its ResourceGroupName property in the return object. The scripts calling it (including Get-AzureWebAppSqlDatabase) and/or Get-AzureWebAppSqlDatabase were updated to use and/or pass on this new ResourceGroupName property.

Jira issue