diff --git a/docs/AVMPostDeploymentGuide.md b/docs/AVMPostDeploymentGuide.md
new file mode 100644
index 000000000..5041ea51b
--- /dev/null
+++ b/docs/AVMPostDeploymentGuide.md
@@ -0,0 +1,124 @@
+# AVM Post Deployment Guide
+
+> **📋 Note**: This guide is specifically for post-deployment steps after using the AVM template. For complete deployment from scratch, see the main [Deployment Guide](./DeploymentGuide.md).
+
+---
+
+This document provides guidance on post-deployment steps after deploying the Multi-Agent Custom Automation Engine Solution Accelerator from the [AVM (Azure Verified Modules) repository](https://github.com/Azure/bicep-registry-modules/tree/main/avm/ptn/sa/multi-agent-custom-automation-engine).
+
+## Overview
+
+After deploying the infrastructure using AVM, you'll need to complete the application layer setup, which includes:
+- Configuring team agent configurations
+- Processing and uploading sample datasets
+- Setting up Azure AI Search indexes
+- Configuring blob storage containers
+- Setting up application authentication
+
+## Prerequisites
+
+Before starting the post-deployment process, ensure you have the following:
+
+### Required Software
+
+1. **[PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4)** (v7.0+ recommended) - Available for Windows, macOS, and Linux
+
+2. **[Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli)** (v2.50+) - Command-line tool for managing Azure resources
+
+3. **[Python](https://www.python.org/downloads/)** (v3.9+ recommended) - Required for data processing scripts
+
+4. **[Git](https://git-scm.com/downloads/)** - Version control system for cloning the repository
+
+### Azure Requirements
+
+5. **Azure Access** - One of the following roles on the subscription or resource group:
+ - `Contributor`
+ - `Owner`
+
+6. **Deployed Infrastructure** - A successful Multi-Agent Custom Automation Engine deployment from the [AVM repository](https://github.com/Azure/bicep-registry-modules/tree/main/avm/ptn/sa/multi-agent-custom-automation-engine)
+
+#### **Important Note for PowerShell Users**
+
+If you encounter issues running PowerShell scripts due to execution policy restrictions, you can temporarily adjust the `ExecutionPolicy` by running the following command in an elevated PowerShell session:
+
+```powershell
+Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
+```
+
+This will allow the scripts to run for the current session without permanently changing your system's policy.
+
+## Post-Deployment Steps
+
+### Step 1: Clone the Repository
+
+First, clone this repository to access the post-deployment scripts:
+
+```powershell
+git clone https://github.com/microsoft/Multi-Agent-Custom-Automation-Engine-Solution-Accelerator.git
+```
+```powershell
+cd Multi-Agent-Custom-Automation-Engine-Solution-Accelerator
+```
+
+### Step 2: Run the Post-Deployment Script
+
+The post-deployment process is automated through a single PowerShell or Bash script that completes the following tasks in approximately 5-10 minutes:
+
+#### What the Script Does:
+1. **Configure Team Agent Settings** - Upload HR, Marketing, and Retail team configurations
+2. **Process Sample Datasets** - Upload and index sample customer data, analytics, and business metrics
+3. **Set Up Azure AI Search** - Create and configure search indexes for agent data retrieval
+4. **Configure Blob Storage** - Set up containers for document and data storage
+
+#### Execute the Script:
+
+1. **Choose the appropriate command based on your deployment method and OS:**
+
+ **If you deployed using custom templates, ARM/Bicep deployments, or `az deployment group` commands:**
+
+ - **For PowerShell (Windows/Linux/macOS):**
+ ```powershell
+ .\infra\scripts\Team-Config-And-Data.ps1 -ResourceGroup ""
+ ```
+
+ - **For Bash (Linux/macOS/WSL):**
+ ```bash
+ bash infra/scripts/team_config_and_data.sh ""
+ ```
+
+ **If you deployed using `azd up` command:**
+
+ - **For PowerShell (Windows/Linux/macOS):**
+ ```powershell
+ .\infra\scripts\Team-Config-And-Data.ps1
+ ```
+
+ - **For Bash (Linux/macOS/WSL):**
+ ```bash
+ bash infra/scripts/team_config_and_data.sh
+ ```
+
+ > **Note**: Replace `` with the actual name of the resource group containing your deployed Azure resources.
+
+ > **💡 Tip**: Since this guide is for AVM deployments, you'll most likely use the first command with the `-ResourceGroup` parameter.
+
+### Step 3: Provide Required Information
+
+During script execution, you'll be prompted for:
+
+- You'll be prompted to authenticate with Azure if not already logged in
+- Select the appropriate Azure subscription
+
+#### Resource Validation
+- The script will automatically detect and validate your deployed Azure resources
+- Confirmation prompts will appear before making configuration changes
+
+### Step 4: Post Deployment Script Completion
+
+Upon successful completion, you'll see a success message.
+
+**🎉 Congratulations!** Your post-deployment configuration is complete.
+
+### Step 5: Set Up App Authentication (Optional)
+
+Follow the steps in [Set Up Authentication in Azure App Service](azure_app_service_auth_setup.md) to add app authentication to your web app running on Azure App Service.
\ No newline at end of file
diff --git a/infra/main.bicep b/infra/main.bicep
index ff538564a..08a3a109a 100644
--- a/infra/main.bicep
+++ b/infra/main.bicep
@@ -235,6 +235,7 @@ resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
TemplateName: 'MACAE'
Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF'
CreatedBy: createdBy
+ DeploymentName: deployment().name
}
}
}
diff --git a/infra/main_custom.bicep b/infra/main_custom.bicep
index 3003b0c21..77ee8afb5 100644
--- a/infra/main_custom.bicep
+++ b/infra/main_custom.bicep
@@ -234,6 +234,7 @@ resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
TemplateName: 'MACAE'
Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF'
CreatedBy: createdBy
+ DeploymentName: deployment().name
}
}
}
diff --git a/infra/scripts/Process-Sample-Data.ps1 b/infra/scripts/Process-Sample-Data.ps1
index eb03017f2..c6d67c817 100644
--- a/infra/scripts/Process-Sample-Data.ps1
+++ b/infra/scripts/Process-Sample-Data.ps1
@@ -5,7 +5,8 @@ param(
[string]$BlobContainer,
[string]$AiSearch,
[string]$AiSearchIndex,
- [string]$ResourceGroup
+ [string]$ResourceGroup,
+ [string]$AzSubscriptionId
)
# Get parameters from azd env, if not provided
@@ -29,7 +30,9 @@ if (-not $ResourceGroup) {
$ResourceGroup = $(azd env get-value AZURE_RESOURCE_GROUP)
}
-$AzSubscriptionId = $(azd env get-value AZURE_SUBSCRIPTION_ID)
+if (-not $AzSubscriptionId) {
+ $AzSubscriptionId = $(azd env get-value AZURE_SUBSCRIPTION_ID)
+}
# Check if all required arguments are provided
if (-not $StorageAccount -or -not $BlobContainer -or -not $AiSearch) {
diff --git a/infra/scripts/Team-Config-And-Data.ps1 b/infra/scripts/Team-Config-And-Data.ps1
index 1cd1fb796..7c1e188c7 100644
--- a/infra/scripts/Team-Config-And-Data.ps1
+++ b/infra/scripts/Team-Config-And-Data.ps1
@@ -1,54 +1,216 @@
#Requires -Version 7.0
param(
- [string]$backendUrl,
- [string]$DirectoryPath,
- [string]$StorageAccount,
- [string]$BlobContainer,
- [string]$AiSearch,
- [string]$AiSearchIndex,
[string]$ResourceGroup
)
-# Get parameters from azd env, if not provided
-if (-not $backendUrl) {
- $backendUrl = $(azd env get-value BACKEND_URL)
+# Variables
+$directoryPath = ""
+$backendUrl = ""
+$storageAccount = ""
+$blobContainer = ""
+$aiSearch = ""
+$aiSearchIndex = ""
+$azSubscriptionId = ""
+
+function Test-AzdInstalled {
+ try {
+ $null = Get-Command azd -ErrorAction Stop
+ return $true
+ } catch {
+ return $false
+ }
}
-if (-not $DirectoryPath) {
- $DirectoryPath = "data/agent_teams"
+
+function Get-ValuesFromAzdEnv {
+ if (-not (Test-AzdInstalled)) {
+ Write-Host "Error: Azure Developer CLI is not installed."
+ return $false
+ }
+
+ Write-Host "Getting values from azd environment..."
+
+ $script:directoryPath = "data/agent_teams"
+ $script:backendUrl = $(azd env get-value BACKEND_URL)
+ $script:storageAccount = $(azd env get-value AZURE_STORAGE_ACCOUNT_NAME)
+ $script:blobContainer = $(azd env get-value AZURE_STORAGE_CONTAINER_NAME)
+ $script:aiSearch = $(azd env get-value AZURE_AI_SEARCH_NAME)
+ $script:aiSearchIndex = $(azd env get-value AZURE_AI_SEARCH_INDEX_NAME)
+ $script:ResourceGroup = $(azd env get-value AZURE_RESOURCE_GROUP)
+
+ # Validate that we got all required values
+ if (-not $script:backendUrl -or -not $script:storageAccount -or -not $script:blobContainer -or -not $script:aiSearch -or -not $script:aiSearchIndex -or -not $script:ResourceGroup) {
+ Write-Host "Error: Could not retrieve all required values from azd environment."
+ return $false
+ }
+
+ Write-Host "Successfully retrieved values from azd environment."
+ return $true
}
-if (-not $StorageAccount) {
- $StorageAccount = $(azd env get-value AZURE_STORAGE_ACCOUNT_NAME)
+
+function Get-ValuesFromAzDeployment {
+ Write-Host "Getting values from Azure deployment outputs..."
+
+ $script:directoryPath = "data/agent_teams"
+
+ Write-Host "Fetching deployment name..."
+ $deploymentName = az group show --name $ResourceGroup --query "tags.DeploymentName" -o tsv
+ if (-not $deploymentName) {
+ Write-Host "Error: Could not find deployment name in resource group tags."
+ return $false
+ }
+
+ Write-Host "Fetching deployment outputs for deployment: $deploymentName"
+ $deploymentOutputs = az deployment group show --resource-group $ResourceGroup --name $deploymentName --query "properties.outputs" -o json | ConvertFrom-Json
+ if (-not $deploymentOutputs) {
+ Write-Host "Error: Could not fetch deployment outputs."
+ return $false
+ }
+
+ # Extract specific outputs
+ $script:storageAccount = $deploymentOutputs.azurE_STORAGE_ACCOUNT_NAME.value
+ $script:blobContainer = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME.value
+ $script:aiSearch = $deploymentOutputs.azurE_AI_SEARCH_NAME.value
+ $script:aiSearchIndex = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME.value
+ $script:backendUrl = $deploymentOutputs.backenD_URL.value
+
+ # Validate that we extracted all required values
+ if (-not $script:storageAccount -or -not $script:blobContainer -or -not $script:aiSearch -or -not $script:aiSearchIndex -or -not $script:backendUrl) {
+ Write-Host "Error: Could not extract all required values from deployment outputs."
+ return $false
+ }
+
+ Write-Host "Successfully retrieved values from deployment outputs."
+ return $true
}
-if (-not $BlobContainer) {
- $BlobContainer = $(azd env get-value AZURE_STORAGE_CONTAINER_NAME)
+# Authenticate with Azure
+try {
+ $null = az account show 2>$null
+ Write-Host "Already authenticated with Azure."
+} catch {
+ Write-Host "Not authenticated with Azure. Attempting to authenticate..."
+ Write-Host "Authenticating with Azure CLI..."
+ az login
}
-if (-not $AiSearch) {
- $AiSearch = $(azd env get-value AZURE_AI_SEARCH_NAME)
+# Get subscription ID from azd if available
+if (Test-AzdInstalled) {
+ try {
+ $azSubscriptionId = $(azd env get-value AZURE_SUBSCRIPTION_ID)
+ if (-not $azSubscriptionId) {
+ $azSubscriptionId = $env:AZURE_SUBSCRIPTION_ID
+ }
+ } catch {
+ $azSubscriptionId = ""
+ }
}
-if (-not $AiSearchIndex) {
- $AiSearchIndex = $(azd env get-value AZURE_AI_SEARCH_INDEX_NAME)
+# Check if user has selected the correct subscription
+$currentSubscriptionId = az account show --query id -o tsv
+$currentSubscriptionName = az account show --query name -o tsv
+
+if ($currentSubscriptionId -ne $azSubscriptionId -and $azSubscriptionId) {
+ Write-Host "Current selected subscription is $currentSubscriptionName ( $currentSubscriptionId )."
+ $confirmation = Read-Host "Do you want to continue with this subscription?(y/n)"
+ if ($confirmation -notin @("y", "Y")) {
+ Write-Host "Fetching available subscriptions..."
+ $availableSubscriptions = az account list --query "[?state=='Enabled'].[name,id]" --output tsv
+ $subscriptions = $availableSubscriptions -split "`n" | ForEach-Object { $_.Split("`t") }
+
+ do {
+ Write-Host ""
+ Write-Host "Available Subscriptions:"
+ Write-Host "========================"
+ for ($i = 0; $i -lt $subscriptions.Count; $i += 2) {
+ $index = ($i / 2) + 1
+ Write-Host "$index. $($subscriptions[$i]) ( $($subscriptions[$i + 1]) )"
+ }
+ Write-Host "========================"
+ Write-Host ""
+
+ $subscriptionIndex = Read-Host "Enter the number of the subscription (1-$(($subscriptions.Count / 2))) to use"
+
+ if ($subscriptionIndex -match '^\d+$' -and [int]$subscriptionIndex -ge 1 -and [int]$subscriptionIndex -le ($subscriptions.Count / 2)) {
+ $selectedIndex = ([int]$subscriptionIndex - 1) * 2
+ $selectedSubscriptionName = $subscriptions[$selectedIndex]
+ $selectedSubscriptionId = $subscriptions[$selectedIndex + 1]
+
+ try {
+ az account set --subscription $selectedSubscriptionId
+ Write-Host "Switched to subscription: $selectedSubscriptionName ( $selectedSubscriptionId )"
+ $azSubscriptionId = $selectedSubscriptionId
+ break
+ } catch {
+ Write-Host "Failed to switch to subscription: $selectedSubscriptionName ( $selectedSubscriptionId )."
+ }
+ } else {
+ Write-Host "Invalid selection. Please try again."
+ }
+ } while ($true)
+ } else {
+ Write-Host "Proceeding with the current subscription: $currentSubscriptionName ( $currentSubscriptionId )"
+ az account set --subscription $currentSubscriptionId
+ $azSubscriptionId = $currentSubscriptionId
+ }
+} else {
+ Write-Host "Proceeding with the subscription: $currentSubscriptionName ( $currentSubscriptionId )"
+ az account set --subscription $currentSubscriptionId
+ $azSubscriptionId = $currentSubscriptionId
}
+# Get configuration values based on strategy
if (-not $ResourceGroup) {
- $ResourceGroup = $(azd env get-value AZURE_RESOURCE_GROUP)
+ # No resource group provided - use azd env
+ if (-not (Get-ValuesFromAzdEnv)) {
+ Write-Host "Failed to get values from azd environment."
+ Write-Host "If you want to use deployment outputs instead, please provide the resource group name as an argument."
+ Write-Host "Usage: .\Team-Config-And-Data.ps1 [-ResourceGroup ]"
+ exit 1
+ }
+} else {
+ # Resource group provided - use deployment outputs
+ Write-Host "Resource group provided: $ResourceGroup"
+
+ if (-not (Get-ValuesFromAzDeployment)) {
+ Write-Host "Failed to get values from deployment outputs."
+ exit 1
+ }
}
+Write-Host ""
+Write-Host "==============================================="
+Write-Host "Values to be used:"
+Write-Host "==============================================="
+Write-Host "Resource Group: $ResourceGroup"
+Write-Host "Backend URL: $backendUrl"
+Write-Host "Storage Account: $storageAccount"
+Write-Host "Blob Container: $blobContainer"
+Write-Host "AI Search: $aiSearch"
+Write-Host "AI Search Index: $aiSearchIndex"
+Write-Host "Directory Path: $directoryPath"
+Write-Host "Subscription ID: $azSubscriptionId"
+Write-Host "==============================================="
+Write-Host ""
+
# Check if all required arguments are provided
-if (-not $backendUrl -or -not $DirectoryPath -or -not $StorageAccount -or -not $BlobContainer -or -not $AiSearch -or -not $AiSearchIndex -or -not $ResourceGroup) {
- Write-Host "Usage: .\Team-Config-And-Data.ps1 -backendUrl -DirectoryPath -StorageAccount -BlobContainer -AiSearch [-AiSearchIndex ] [-ResourceGroup ]"
+if (-not $backendUrl -or -not $directoryPath -or -not $storageAccount -or -not $blobContainer -or -not $aiSearch -or -not $aiSearchIndex -or -not $ResourceGroup) {
+ Write-Host "Error: Missing required configuration values."
+ Write-Host "Usage: .\Team-Config-And-Data.ps1 [-ResourceGroup ]"
exit 1
}
$isTeamConfigFailed = $false
$isSampleDataFailed = $false
+
# Upload Team Configuration
Write-Host "Uploading Team Configuration..."
try {
- .\infra\scripts\Upload-Team-Config.ps1 -backendUrl $backendUrl -DirectoryPath $DirectoryPath
+ .\infra\scripts\Upload-Team-Config.ps1 -backendUrl $backendUrl -DirectoryPath $directoryPath -AzSubscriptionId $azSubscriptionId
+ if ($LASTEXITCODE -ne 0) {
+ Write-Host "Error: Uploading team configuration failed."
+ $isTeamConfigFailed = $true
+ }
} catch {
Write-Host "Error: Uploading team configuration failed."
$isTeamConfigFailed = $true
@@ -60,7 +222,11 @@ Write-Host "----------------------------------------`n"
# Process Sample Data
Write-Host "Processing Sample Data..."
try {
- .\infra\scripts\Process-Sample-Data.ps1 -StorageAccount $StorageAccount -BlobContainer $BlobContainer -AiSearch $AiSearch -AiSearchIndex $AiSearchIndex -ResourceGroup $ResourceGroup
+ .\infra\scripts\Process-Sample-Data.ps1 -StorageAccount $storageAccount -BlobContainer $blobContainer -AiSearch $aiSearch -AiSearchIndex $aiSearchIndex -ResourceGroup $ResourceGroup -AzSubscriptionId $azSubscriptionId
+ if ($LASTEXITCODE -ne 0) {
+ Write-Host "Error: Processing sample data failed."
+ $isSampleDataFailed = $true
+ }
} catch {
Write-Host "Error: Processing sample data failed."
$isSampleDataFailed = $true
diff --git a/infra/scripts/Upload-Team-Config.ps1 b/infra/scripts/Upload-Team-Config.ps1
index 342524d87..4d406358a 100644
--- a/infra/scripts/Upload-Team-Config.ps1
+++ b/infra/scripts/Upload-Team-Config.ps1
@@ -2,7 +2,8 @@
param(
[string]$backendUrl,
- [string]$DirectoryPath
+ [string]$DirectoryPath,
+ [string]$AzSubscriptionId
)
# Get parameters from azd env, if not provided
@@ -13,7 +14,9 @@ if (-not $DirectoryPath) {
$DirectoryPath = "data/agent_teams"
}
-$AzSubscriptionId = $(azd env get-value AZURE_SUBSCRIPTION_ID)
+if (-not $AzSubscriptionId) {
+ $AzSubscriptionId = $(azd env get-value AZURE_SUBSCRIPTION_ID)
+}
# Check if all required arguments are provided
if (-not $backendUrl -or -not $DirectoryPath) {
diff --git a/infra/scripts/index_datasets.py b/infra/scripts/index_datasets.py
index 480407382..86a15d7b6 100644
--- a/infra/scripts/index_datasets.py
+++ b/infra/scripts/index_datasets.py
@@ -50,7 +50,7 @@
for idx, blob in enumerate(blob_list, start=1):
#if blob.name.endswith(".csv"):
title = blob.name.replace(".csv", "")
- title = blob.name.replace(".json", "")
+ title = title.replace(".json", "")
data = container_client.download_blob(blob.name).readall()
try:
diff --git a/infra/scripts/process_sample_data.sh b/infra/scripts/process_sample_data.sh
index a9521dc75..2253be08c 100644
--- a/infra/scripts/process_sample_data.sh
+++ b/infra/scripts/process_sample_data.sh
@@ -6,6 +6,7 @@ blobContainer="$2"
aiSearch="$3"
aiSearchIndex="$4"
resourceGroup="$5"
+azSubscriptionId="$6"
# get parameters from azd env, if not provided
if [ -z "$storageAccount" ]; then
@@ -28,7 +29,9 @@ if [ -z "$resourceGroup" ]; then
resourceGroup=$(azd env get-value AZURE_RESOURCE_GROUP)
fi
-azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID)
+if [ -z "$azSubscriptionId" ]; then
+ azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID)
+fi
# Check if all required arguments are provided
if [ -z "$storageAccount" ] || [ -z "$blobContainer" ] || [ -z "$aiSearch" ]; then
diff --git a/infra/scripts/team_config_and_data.sh b/infra/scripts/team_config_and_data.sh
index baa1a29a2..b917180f3 100644
--- a/infra/scripts/team_config_and_data.sh
+++ b/infra/scripts/team_config_and_data.sh
@@ -1,55 +1,186 @@
#!/bin/bash
# Variables
-backendUrl=$1
-directoryPath=$2
-storageAccount="$3"
-blobContainer="$4"
-aiSearch="$5"
-aiSearchIndex="$6"
-resourceGroup="$7"
-
-# get parameters from azd env, if not provided as arguments
-if [ -z "$directoryPath" ]; then
+resourceGroup="$1"
+
+directoryPath=""
+backendUrl=""
+storageAccount=""
+blobContainer=""
+aiSearch=""
+aiSearchIndex=""
+azSubscriptionId=""
+
+# check if azd cli is installed
+check_azd_installed() {
+ if command -v azd &> /dev/null; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+get_values_from_azd_env() {
+ check_azd_installed
+ if [ $? -ne 0 ]; then
+ echo "Error: Azure Developer CLI is not installed."
+ return 1
+ fi
+
+ echo "Getting values from azd environment..."
+
directoryPath="data/agent_teams"
-fi
-
-if [ -z "$backendUrl" ]; then
backendUrl=$(azd env get-value BACKEND_URL)
-fi
-
-if [ -z "$storageAccount" ]; then
storageAccount=$(azd env get-value AZURE_STORAGE_ACCOUNT_NAME)
-fi
-
-if [ -z "$blobContainer" ]; then
blobContainer=$(azd env get-value AZURE_STORAGE_CONTAINER_NAME)
-fi
-
-if [ -z "$aiSearch" ]; then
aiSearch=$(azd env get-value AZURE_AI_SEARCH_NAME)
+ aiSearchIndex=$(azd env get-value AZURE_AI_SEARCH_INDEX_NAME)
+ resourceGroup=$(azd env get-value AZURE_RESOURCE_GROUP)
+
+ # Validate that we got all required values
+ if [ -z "$backendUrl" ] || [ -z "$storageAccount" ] || [ -z "$blobContainer" ] || [ -z "$aiSearch" ] || [ -z "$aiSearchIndex" ] || [ -z "$resourceGroup" ]; then
+ echo "Error: Could not retrieve all required values from azd environment."
+ return 1
+ fi
+
+ echo "Successfully retrieved values from azd environment."
+ return 0
+}
+
+get_values_from_az_deployment() {
+ echo "Getting values from Azure deployment outputs..."
+
+ directoryPath="data/agent_teams"
+
+ echo "Fetching deployment name..."
+ deploymentName=$(az group show --name "$resourceGroup" --query "tags.DeploymentName" -o tsv)
+ if [ -z "$deploymentName" ]; then
+ echo "Error: Could not find deployment name in resource group tags."
+ return 1
+ fi
+
+ echo "Fetching deployment outputs for deployment: $deploymentName"
+ deploymentOutputs=$(az deployment group show --resource-group "$resourceGroup" --name "$deploymentName" --query "properties.outputs" -o json)
+ if [ -z "$deploymentOutputs" ]; then
+ echo "Error: Could not fetch deployment outputs."
+ return 1
+ fi
+
+ # Extract specific outputs
+ storageAccount=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_STORAGE_ACCOUNT_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
+ blobContainer=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_STORAGE_CONTAINER_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
+ aiSearch=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_AI_SEARCH_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
+ aiSearchIndex=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_AI_SEARCH_INDEX_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
+ backendUrl=$(echo "$deploymentOutputs" | grep -A 3 '"backenD_URL"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
+
+ # Validate that we extracted all required values
+ if [ -z "$storageAccount" ] || [ -z "$blobContainer" ] || [ -z "$aiSearch" ] || [ -z "$aiSearchIndex" ] || [ -z "$backendUrl" ]; then
+ echo "Error: Could not extract all required values from deployment outputs."
+ return 1
+ fi
+
+ echo "Successfully retrieved values from deployment outputs."
+ return 0
+}
+
+# Authenticate with Azure
+if az account show &> /dev/null; then
+ echo "Already authenticated with Azure."
+else
+ echo "Not authenticated with Azure. Attempting to authenticate..."
+ echo "Authenticating with Azure CLI..."
+ az login
fi
-if [ -z "$aiSearchIndex" ]; then
- aiSearchIndex=$(azd env get-value AZURE_AI_SEARCH_INDEX_NAME)
+if check_azd_installed; then
+ azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID) || azSubscriptionId="$AZURE_SUBSCRIPTION_ID" || azSubscriptionId=""
fi
-if [ -z "$resourceGroup" ]; then
- resourceGroup=$(azd env get-value AZURE_RESOURCE_GROUP)
+#check if user has selected the correct subscription
+currentSubscriptionId=$(az account show --query id -o tsv)
+currentSubscriptionName=$(az account show --query name -o tsv)
+if [ "$currentSubscriptionId" != "$azSubscriptionId" ]; then
+ echo "Current selected subscription is $currentSubscriptionName ( $currentSubscriptionId )."
+ read -rp "Do you want to continue with this subscription?(y/n): " confirmation
+ if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then
+ echo "Fetching available subscriptions..."
+ availableSubscriptions=$(az account list --query "[?state=='Enabled'].[name,id]" --output tsv)
+ while true; do
+ echo ""
+ echo "Available Subscriptions:"
+ echo "========================"
+ echo "$availableSubscriptions" | awk '{printf "%d. %s ( %s )\n", NR, $1, $2}'
+ echo "========================"
+ echo ""
+ read -rp "Enter the number of the subscription (1-$(echo "$availableSubscriptions" | wc -l)) to use: " subscriptionIndex
+ if [[ "$subscriptionIndex" =~ ^[0-9]+$ ]] && [ "$subscriptionIndex" -ge 1 ] && [ "$subscriptionIndex" -le $(echo "$availableSubscriptions" | wc -l) ]; then
+ selectedSubscription=$(echo "$availableSubscriptions" | sed -n "${subscriptionIndex}p")
+ selectedSubscriptionName=$(echo "$selectedSubscription" | cut -f1)
+ selectedSubscriptionId=$(echo "$selectedSubscription" | cut -f2)
+
+ # Set the selected subscription
+ if az account set --subscription "$selectedSubscriptionId"; then
+ echo "Switched to subscription: $selectedSubscriptionName ( $selectedSubscriptionId )"
+ azSubscriptionId="$selectedSubscriptionId"
+ break
+ else
+ echo "Failed to switch to subscription: $selectedSubscriptionName ( $selectedSubscriptionId )."
+ fi
+ else
+ echo "Invalid selection. Please try again."
+ fi
+ done
+ else
+ echo "Proceeding with the current subscription: $currentSubscriptionName ( $currentSubscriptionId )"
+ az account set --subscription "$currentSubscriptionId"
+ azSubscriptionId="$currentSubscriptionId"
+ fi
+else
+ echo "Proceeding with the subscription: $currentSubscriptionName ( $currentSubscriptionId )"
+ az account set --subscription "$currentSubscriptionId"
+ azSubscriptionId="$currentSubscriptionId"
fi
-# Check if all required arguments are provided
-if [ -z "$backendUrl" ] || [ -z "$directoryPath" ] || [ -z "$storageAccount" ] || [ -z "$blobContainer" ] || [ -z "$aiSearch" ]; then
- echo "Usage: $0 [AISearchIndexName] [ResourceGroupName]"
- exit 1
+
+if [ -z "$resourceGroup" ]; then
+ # No resource group provided - use azd env
+ if ! get_values_from_azd_env; then
+ echo "Failed to get values from azd environment."
+ echo "If you want to use deployment outputs instead, please provide the resource group name as an argument."
+ echo "Usage: $0 [ResourceGroupName]"
+ exit 1
+ fi
+else
+ # Resource group provided - use deployment outputs
+ echo "Resource group provided: $resourceGroup"
+
+ # Call deployment function
+ if ! get_values_from_az_deployment; then
+ echo "Failed to get values from deployment outputs."
+ exit 1
+ fi
fi
+echo ""
+echo "==============================================="
+echo "Values to be used:"
+echo "==============================================="
+echo "Resource Group: $resourceGroup"
+echo "Backend URL: $backendUrl"
+echo "Storage Account: $storageAccount"
+echo "Blob Container: $blobContainer"
+echo "AI Search: $aiSearch"
+echo "AI Search Index: $aiSearchIndex"
+echo "Directory Path: $directoryPath"
+echo "Subscription ID: $azSubscriptionId"
+echo "==============================================="
+echo ""
isTeamConfigFailed=false
isSampleDataFailed=false
echo "Uploading team configuration..."
-bash infra/scripts/upload_team_config.sh "$backendUrl" "$directoryPath"
+bash infra/scripts/upload_team_config.sh "$backendUrl" "$directoryPath" "$azSubscriptionId"
if [ $? -ne 0 ]; then
echo "Error: Team configuration upload failed."
isTeamConfigFailed=true
@@ -61,7 +192,7 @@ echo "----------------------------------------"
echo ""
echo "Processing sample data..."
-bash infra/scripts/process_sample_data.sh "$storageAccount" "$blobContainer" "$aiSearch" "$aiSearchIndex" "$resourceGroup"
+bash infra/scripts/process_sample_data.sh "$storageAccount" "$blobContainer" "$aiSearch" "$aiSearchIndex" "$resourceGroup" "$azSubscriptionId"
if [ $? -ne 0 ]; then
echo "Error: Sample data processing failed."
isSampleDataFailed=true
diff --git a/infra/scripts/upload_team_config.sh b/infra/scripts/upload_team_config.sh
index 60875f088..5ca0d8d02 100644
--- a/infra/scripts/upload_team_config.sh
+++ b/infra/scripts/upload_team_config.sh
@@ -3,6 +3,7 @@
# Variables
backendUrl=$1
directoryPath=$2
+azSubscriptionId=$3
# get parameters from azd env, if not provided as arguments
if [ -z "$directoryPath" ]; then
@@ -13,7 +14,9 @@ if [ -z "$backendUrl" ]; then
backendUrl=$(azd env get-value BACKEND_URL)
fi
-azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID)
+if [ -z "$azSubscriptionId" ]; then
+ azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID)
+fi
if [ -z "$backendUrl" ] || [ -z "$directoryPath" ]; then
echo "Error: Missing required arguments."