-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprofile.ps1
More file actions
60 lines (53 loc) · 2.38 KB
/
Copy pathprofile.ps1
File metadata and controls
60 lines (53 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Azure Functions profile.ps1
#
# This profile.ps1 will get executed every "cold start" of your Function App.
# "cold start" occurs when:
#
# * A Function App starts up for the very first time
# * A Function App starts up after being de-allocated due to inactivity
#
# You can define helper functions, run commands, or specify environment variables
# NOTE: any variables defined that are not environment variables will get reset after the first execution
# PowerShell Module Loading Strategy:
# This function uses a hybrid approach for loading PowerShell modules:
# 1. Primary: Azure Functions managed dependencies (requirements.psd1)
# 2. Fallback: Runtime loading from Azure Storage (shared/Load-Modules.ps1)
# 3. Backup: PowerShell Gallery installation
#
# For setup instructions, see: DEPLOYMENT.md (Step 2: PowerShell Module Setup)
# Initialize runtime modules from Azure Storage as fallback
. "$PSScriptRoot\shared\Load-Modules.ps1"
# Check if the primary modules are available, if not, initialize our custom loading
$criticalModules = @("Az.Accounts", "Az.KeyVault")
$needsCustomLoading = $false
foreach ($module in $criticalModules) {
if (-not (Get-Module -Name $module -ListAvailable)) {
$needsCustomLoading = $true
break
}
}
if ($needsCustomLoading) {
Write-Host "Primary modules not available through requirements.psd1, initializing custom loading..."
Initialize-RuntimeModules -StorageAccountName $env:STORAGE_ACCOUNT_NAME -ContainerName "modules"
} else {
Write-Host "Modules available through requirements.psd1, skipping custom loading"
}
# Authenticate with Azure PowerShell using MSI.
# Remove this if you are not planning on using MSI or Azure PowerShell.
if ($env:MSI_SECRET) {
try {
# Import Az.Accounts if available
if (Get-Module -Name Az.Accounts -ListAvailable) {
Import-Module Az.Accounts -Force -ErrorAction SilentlyContinue
Disable-AzContextAutosave -Scope Process | Out-Null
Connect-AzAccount -Identity
} else {
Write-Warning "Az.Accounts module not available for Azure authentication"
}
} catch {
Write-Warning "Failed to authenticate with Azure: $_"
}
}
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
# Enable-AzureRmAlias
# You can also define functions or aliases that can be referenced in any of your PowerShell functions.