Skip to content

Commit f6e345e

Browse files
committed
fix: support sp auth for requirements
1 parent 97345b6 commit f6e345e

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

src/ALZ/Private/Tools/Test-Tooling.ps1

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,56 @@ function Test-Tooling {
4141
$hasFailure = $true
4242
}
4343

44-
# Check if Azure CLI is installed
45-
Write-Verbose "Checking Azure CLI installation"
46-
$azCliPath = Get-Command az -ErrorAction SilentlyContinue
47-
if ($azCliPath) {
48-
$checkResults += @{
49-
message = "Azure CLI is installed."
50-
result = "Success"
51-
}
52-
} else {
53-
$checkResults += @{
54-
message = "Azure CLI is not installed. Follow the instructions here: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli"
55-
result = "Failure"
44+
# Check if using Service Principal Auth
45+
$nonAzCliEnvVars = @(
46+
"ARM_CLIENT_ID",
47+
"ARM_SUBSCRIPTION_ID",
48+
"ARM_TENANT_ID"
49+
)
50+
51+
$envVarsSet = $true
52+
foreach($envVar in $nonAzCliEnvVars) {
53+
$envVarValue = [System.Environment]::GetEnvironmentVariable($envVar)
54+
if($envVarValue -eq $null -or $envVarValue -eq "") {
55+
$envVarsSet = $false
56+
break
5657
}
57-
$hasFailure = $true
5858
}
5959

60-
# Check if Azure CLI is logged in
61-
Write-Verbose "Checking Azure CLI login status"
62-
$azCliAccount = $(az account show -o json) | ConvertFrom-Json
63-
if ($azCliAccount) {
64-
$checkResults += @{
65-
message = "Azure CLI is logged in. Tenant ID: $($azCliAccount.tenantId), Subscription: $($azCliAccount.name) ($($azCliAccount.id))"
66-
result = "Success"
67-
}
60+
if($envVarsSet) {
61+
Write-InformationColored "Using Service Principal Authentication, skipping Azure CLI checks" -ForegroundColor Yellow -NewLineBefore -InformationAction Continue
6862
} else {
69-
$checkResults += @{
70-
message = "Azure CLI is not logged in. Please login to Azure CLI using 'az login -t `"00000000-0000-0000-0000-000000000000}`"', replacing the empty GUID with your tenant ID."
71-
result = "Failure"
63+
# Check if Azure CLI is installed
64+
Write-Verbose "Checking Azure CLI installation"
65+
$azCliPath = Get-Command az -ErrorAction SilentlyContinue
66+
if ($azCliPath) {
67+
$checkResults += @{
68+
message = "Azure CLI is installed."
69+
result = "Success"
70+
}
71+
} else {
72+
$checkResults += @{
73+
message = "Azure CLI is not installed. Follow the instructions here: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli"
74+
result = "Failure"
75+
}
76+
$hasFailure = $true
77+
}
78+
79+
# Check if Azure CLI is logged in
80+
Write-Verbose "Checking Azure CLI login status"
81+
$azCliAccount = $(az account show -o json) | ConvertFrom-Json
82+
if ($azCliAccount) {
83+
$checkResults += @{
84+
message = "Azure CLI is logged in. Tenant ID: $($azCliAccount.tenantId), Subscription: $($azCliAccount.name) ($($azCliAccount.id))"
85+
result = "Success"
86+
}
87+
} else {
88+
$checkResults += @{
89+
message = "Azure CLI is not logged in. Please login to Azure CLI using 'az login -t `"00000000-0000-0000-0000-000000000000}`"', replacing the empty GUID with your tenant ID."
90+
result = "Failure"
91+
}
92+
$hasFailure = $true
7293
}
73-
$hasFailure = $true
7494
}
7595

7696
# Check if latest ALZ module is installed

0 commit comments

Comments
 (0)