Skip to content

Commit 1a29d87

Browse files
refactor: update process_data_scripts Bicep module and enhance run script for VNet and storage account handling
1 parent 1be3b12 commit 1a29d87

File tree

2 files changed

+95
-19
lines changed

2 files changed

+95
-19
lines changed

infra/process_data_scripts.bicep

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,33 @@ param solutionLocation string
22
param keyVaultName string
33
param managedIdentityResourceId string
44
param managedIdentityClientId string
5+
param storageAccount string
6+
param enablePrivateNetworking bool = false
7+
param subnetId string = ''
58

69
var baseUrl = 'https://raw.githubusercontent.com/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator/main/'
710

8-
resource process_data_scripts 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
9-
kind:'AzureCLI'
10-
name: 'process_data_scripts'
11-
location: solutionLocation // Replace with your desired location
12-
identity: {
13-
type: 'UserAssigned'
14-
userAssignedIdentities: {
15-
'${managedIdentityResourceId}' : {}
16-
}
17-
}
18-
properties: {
11+
module uploadFiles 'br/public:avm/res/resources/deployment-script:0.5.1' = {
12+
name: take('avm.res.resources.deployment-script.uploadFiles', 64)
13+
params: {
14+
kind: 'AzureCLI'
15+
name: 'process_data_scripts'
1916
azCliVersion: '2.52.0'
20-
primaryScriptUri: '${baseUrl}infra/scripts/process_data_scripts.sh'
21-
arguments: '${baseUrl} ${keyVaultName} ${managedIdentityClientId}' // Specify any arguments for the script
22-
timeout: 'PT1H' // Specify the desired timeout duration
23-
retentionInterval: 'PT1H' // Specify the desired retention interval
24-
cleanupPreference:'OnSuccess'
17+
cleanupPreference: 'Always'
18+
location: solutionLocation
19+
managedIdentities: {
20+
userAssignedResourceIds: [
21+
managedIdentityResourceId
22+
]
23+
}
24+
retentionInterval: 'P1D'
25+
runOnce: true
26+
primaryScriptUri: '${baseUrl}infra/scripts/process_data_scripts.sh'
27+
arguments: '${baseUrl} ${keyVaultName} ${managedIdentityClientId}'
28+
storageAccountResourceId: storageAccount
29+
subnetResourceIds: (enablePrivateNetworking && !empty(subnetId)) ? [
30+
subnetId
31+
] : null
32+
timeout: 'PT1H'
2533
}
2634
}

infra/scripts/run_process_data_scripts.sh

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,92 @@ sqlServerLocation=$(az sql server list --resource-group "$resourceGroupName" --q
3636
# === Retrieve the principal ID of the first user-assigned identity with name starting with 'id-' ===
3737
managedIdentityClientId=$(az identity list --resource-group "$resourceGroupName" --query "[?starts_with(name, 'id-') && !starts_with(name, 'id-sql-')].clientId | [0]" -o tsv)
3838

39+
# === Check for VNet deployment ===
40+
echo "Checking for VNet deployment in resource group: $resourceGroupName"
41+
vnetResourceId=$(az network vnet list --resource-group "$resourceGroupName" --query "[0].id" -o tsv)
42+
43+
# === Get resource group location ===
44+
rgLocation=$(az group show --name "$resourceGroupName" --query "location" -o tsv)
45+
46+
# === Find storage account (always needed) ===
47+
echo "Looking for storage account in resource group..."
48+
storageAccountResourceId=$(az storage account list --resource-group "$resourceGroupName" --query "[0].id" -o tsv)
49+
50+
if [ -z "$storageAccountResourceId" ]; then
51+
echo "ERROR: No storage account found in resource group $resourceGroupName"
52+
exit 1
53+
else
54+
echo "Using storage account: $storageAccountResourceId"
55+
fi
56+
57+
if [ -z "$vnetResourceId" ]; then
58+
echo "No VNet found in resource group. Private networking is disabled."
59+
enablePrivateNetworking="false"
60+
subnetId=""
61+
solutionLocation="$sqlServerLocation"
62+
echo "Using SQL Server location for solution: $solutionLocation"
63+
else
64+
echo "VNet found: $vnetResourceId"
65+
echo "VNet detected - enabling private networking."
66+
enablePrivateNetworking="true"
67+
solutionLocation="$rgLocation"
68+
echo "Using Resource Group location for solution: $solutionLocation"
69+
70+
# === Find the deployment script subnet ===
71+
echo "Looking for deployment-scripts subnet..."
72+
subnetId=$(az network vnet subnet list --resource-group "$resourceGroupName" --vnet-name $(basename "$vnetResourceId") --query "[?name=='deployment-scripts'].id | [0]" -o tsv)
73+
74+
if [ -z "$subnetId" ]; then
75+
echo "Warning: deployment-scripts subnet not found. Checking for alternative subnet names..."
76+
# Try alternative names
77+
subnetId=$(az network vnet subnet list --resource-group "$resourceGroupName" --vnet-name $(basename "$vnetResourceId") --query "[?contains(name, 'deployment') || contains(name, 'script')].id | [0]" -o tsv)
78+
fi
79+
80+
if [ -z "$subnetId" ]; then
81+
echo "Warning: No deployment script subnet found. Private networking will be disabled for deployment script."
82+
enablePrivateNetworking="false"
83+
subnetId=""
84+
else
85+
echo "Using deployment script subnet: $subnetId"
86+
fi
87+
fi
88+
3989
# === Validate that all required resources were found ===
40-
if [[ -z "$keyVaultName" || -z "$sqlServerLocation" || -z "$managedIdentityResourceId" || ! "$managedIdentityResourceId" =~ ^/subscriptions/ ]]; then
90+
if [[ -z "$keyVaultName" || -z "$solutionLocation" || -z "$managedIdentityResourceId" || ! "$managedIdentityResourceId" =~ ^/subscriptions/ ]]; then
4191
echo "ERROR: Could not find required resources in resource group $resourceGroupName or managedIdentityResourceId is invalid"
4292
exit 1
4393
fi
4494

45-
echo "Using SQL Server Location: $sqlServerLocation"
95+
echo "Using Solution Location: $solutionLocation"
4696
echo "Using Key Vault: $keyVaultName"
4797
echo "Using Managed Identity Resource Id: $managedIdentityResourceId"
4898
echo "Using Managed Identity ClientId Id: $managedIdentityClientId"
99+
echo "Enable Private Networking: $enablePrivateNetworking"
100+
echo "Subnet ID: $subnetId"
101+
echo "Storage Account Resource ID: $storageAccountResourceId"
49102

50103
# === Deploy resources using the specified Bicep template ===
51104
echo "Deploying Bicep template..."
52105

106+
# Build base parameters
107+
deploymentParams="solutionLocation=$solutionLocation keyVaultName=$keyVaultName managedIdentityResourceId=$managedIdentityResourceId managedIdentityClientId=$managedIdentityClientId storageAccount=$storageAccountResourceId"
108+
109+
# Add networking parameters if VNet is deployed
110+
if [ "$enablePrivateNetworking" = "true" ]; then
111+
deploymentParams="$deploymentParams enablePrivateNetworking=true"
112+
if [ -n "$subnetId" ]; then
113+
deploymentParams="$deploymentParams subnetId=$subnetId"
114+
fi
115+
else
116+
deploymentParams="$deploymentParams enablePrivateNetworking=false"
117+
fi
118+
119+
echo "Deployment parameters: $deploymentParams"
120+
53121
# MSYS_NO_PATHCONV disables path conversion in Git Bash for Windows
54122
MSYS_NO_PATHCONV=1 az deployment group create \
55123
--resource-group "$resourceGroupName" \
56124
--template-file "$bicepFile" \
57-
--parameters solutionLocation="$sqlServerLocation" keyVaultName="$keyVaultName" managedIdentityResourceId="$managedIdentityResourceId" managedIdentityClientId="$managedIdentityClientId"
125+
--parameters $deploymentParams
58126

59127
echo "Deployment completed."

0 commit comments

Comments
 (0)