Setting Up an Azure Environment
- Getting Started - Azure Developer CLI (Recommended)
- Alternative - PowerShell Scripts
- Notes on Unit Testing
- SQL Express for local testing
- Visual Studio Installer Project
Getting Started - Azure Developer CLI (Recommended)
The simplest way to provision all Azure resources is using the Azure Developer CLI (azd). This approach uses Bicep templates in the /infra folder for Infrastructure as Code deployment.
Prerequisites
- Azure Developer CLI (azd)
- Azure CLI
- PowerShell 7+
Steps
- Open a terminal at the repository root (where
azure.yamlis located) - Login to Azure:
azd auth login az login - Initialize the environment (first time only):
azd initYou will be prompted for:
- Environment name - This becomes the resource prefix (3-10 characters, lowercase)
- Azure subscription - Select your target subscription
- Azure location - Select the region for deployment
- Provision the resources:
azd up
What happens during azd up
Pre-provision Hook (scripts/preprovision.ps1)
- Captures your current IP address (for SQL firewall rules)
- Retrieves your Azure AD user info (for RBAC and SQL admin)
- Sets default environment variables for post-provision steps
Infrastructure Deployment (infra/main.bicep)
Creates the following Azure resources with the environment name as prefix:
- Resource Group (
{prefix}-rg) - Virtual Network with subnets for AKS, Container Apps, ACI, Batch, and Private Endpoints
- Managed Identity (
{prefix}identity) - Used for all service-to-service authentication - Storage Account (
{prefix}storage) - For runtime logs and Kubernetes package staging - Service Bus Namespace (
{prefix}servicebus) - Topic-based message queue for database targets - Event Hub (
{prefix}eventhubnamespace/{prefix}eventhub) - Progress event tracking - Log Analytics Workspace (
{prefix}loganalytics) - Container Registry (
{prefix}containerregistry) - Private registry for SQL Build Manager images - Batch Account (
{prefix}batchacct) - Pre-configured with Linux/Windows application slots - AKS Cluster (
{prefix}aks) - Kubernetes cluster with workload identity federation - Container App Environment (
{prefix}containerappenv) - Azure SQL Servers (
{prefix}sql-aand{prefix}sql-b) - Each with test databases
Post-provision Hook (scripts/postprovision.ps1)
- Grants managed identity SQL permissions on all test databases
- Creates Kubernetes namespace and service account (if AKS deployed)
- Generates MI-only settings files for integration testing
- Creates database override configuration files
- Builds and uploads Batch application packages (if
BUILD_BATCH_PACKAGES=true) - Builds and pushes container images to ACR (if
BUILD_CONTAINER_IMAGES=true)
Configuration Parameters
You can customize the deployment by setting environment variables before running azd up:
# Deployment toggles
azd env set DEPLOY_BATCH_ACCOUNT true # Deploy Azure Batch (default: true)
azd env set DEPLOY_CONTAINER_REGISTRY true # Deploy ACR (default: true)
azd env set DEPLOY_CONTAINERAPP_ENV true # Deploy Container Apps (default: true)
azd env set DEPLOY_AKS true # Deploy AKS (default: true)
# Database settings
azd env set TEST_DB_COUNT_PER_SERVER 10 # Test databases per server (default: 10)
# Post-provision options
azd env set BUILD_BATCH_PACKAGES true # Build and upload Batch packages
azd env set BUILD_CONTAINER_IMAGES true # Build and push Docker images
azd env set GENERATE_MI_SETTINGS true # Generate settings files (default: true)
# Security options
azd env set USE_PRIVATE_ENDPOINT false # Use private endpoints (default: false)
Output Files
After successful deployment, the following files are generated in src/TestConfig:
settingsfile-batch-*.json- Batch settings with MI authenticationsettingsfile-aci-*.json- ACI settingssettingsfile-containerapp-*.json- Container App settingssettingsfile-k8s-*.json- Kubernetes settingssettingsfilekey.txt- Encryption key for settings filesdatabasetargets.cfg- Database listing for SBM file integration testsclientdbtargets.cfg- Database listing for DACPAC integration tests
Notes on Unit Testing
NOTE: There are currently some concurrency issues with the unit tests. You may get some failures in a full run that will then succeed after running aain, selecting only the failed tests
There are three types of Tests included in the solution:
- True unit tests with no external dependency - found in the
~UnitTest.csprojprojects - Those that are dependent on a local SQLEXPRESS database - found in the
~.Dependent.UnitTest.csprojprojects. If you want to be able to run the database dependent tests, you will need to install SQL Express as per the next section.
IMPORTANT: If running the SQLEXPRESS dependent tests for the first time on your local machine, you need to run the tests in theSqlSync.SqlBuild.Dependent.UnitTest.csprojfirst. This project has the scripts to create the necessary SQLEXPRESS databases. - Integration tests that leverage Azure resources for Batch and Kubernetes. These are found in the
SqlBuildManager.Console.ExternalTest.csprojproject. To run these tests, first runcreate_azure_resources.ps1with the -testDatabaseCountvalue >1 (the default is 10). This will create the necessary resources and test config files (in/src/TestConfigfolder) needed to run the tests.
SQL Express
In order to get some of the unit tests to succeed, you need to have a local install of SQLExpress. You can find the installer from here [https://www.microsoft.com/en-us/sql-server/sql-server-editions-express] (https://www.microsoft.com/en-us/sql-server/sql-server-editions-express). You should be able to leverage the basic install.
Visual Studio Installer Project
For Visual Studio 2015 and beyond, you will need to install an extension to load the installer project (.vdproj)
Visual Studio 2022
https://marketplace.visualstudio.com/items?itemName=VisualStudioClient.MicrosoftVisualStudio2022InstallerProjects
Visual Studio 2017 and 2019
https://marketplace.visualstudio.com/items?itemName=VisualStudioClient.MicrosoftVisualStudio2017InstallerProjects
Visual Studio 2015
https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9
If you are having trouble with the installer project loading try disable extension “Microsoft Visual Studio Installer Projects”, reenable, then reload the projects.