You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$subscriptionId=$(az account show --query id -o tsv)
46
+
}
47
+
35
48
if ($null-eq$subscriptionId-or$subscriptionId-eq"") {
36
-
Write-Error"Subscription ID not found. Please ensure you are logged in to Azure and have selected a subscription. Use 'az account show' to check."
49
+
Write-Error"Subscription ID not found. Please ensure you are logged in to Azure and have selected a subscription, or provide bootstrap_subscription_id. Use 'az account show' to check."
Copy file name to clipboardExpand all lines: src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1
+8-2Lines changed: 8 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -292,11 +292,17 @@ function New-Bootstrap {
292
292
# Running terraform init and apply
293
293
Write-InformationColored"Thank you for providing those inputs, we are now initializing and applying Terraform to bootstrap your environment..."-ForegroundColor Green -NewLineBefore -InformationAction Continue
294
294
295
+
# Get bootstrap_subscription_id from inputConfig if available
296
+
$bootstrapSubscriptionId=""
297
+
if ($null-ne$inputConfig.bootstrap_subscription_id-and$null-ne$inputConfig.bootstrap_subscription_id.Value) {
Write-InformationColored"Once the plan is complete you will be prompted to confirm the apply."-ForegroundColor Green -NewLineBefore -InformationAction Continue
Write-InformationColored"Bootstrap has completed successfully! Thanks for using our tool. Head over to Phase 3 in the documentation to continue..."-ForegroundColor Green -NewLineBefore -InformationAction Continue
if ($PSCmdlet.ShouldProcess("Accelerator folder structure setup","prompt and create")) {
25
20
Write-InformationColored"No input configuration files provided. Let's set up the accelerator folder structure first..."-ForegroundColor Green -NewLineBefore -InformationAction Continue
@@ -215,11 +210,14 @@ function Request-AcceleratorConfigurationInput {
215
210
# Offer to configure inputs interactively (default is Yes)
216
211
$configureNowResponse=Read-Host"`nWould you like to configure the input values interactively now? (Y/n)"
217
212
if ($configureNowResponse-ne"n"-and$configureNowResponse-ne"N") {
213
+
# Query Azure for management groups and subscriptions (for interactive selection)
214
+
$azureContext=Get-AzureContext
215
+
218
216
Request-ALZConfigurationValue`
219
217
-ConfigFolderPath $configFolderPath`
220
218
-IacType $selectedIacType`
221
219
-VersionControl $selectedVersionControl`
222
-
-AzureContext $AzureContext
220
+
-AzureContext $azureContext
223
221
}
224
222
225
223
# Check for VS Code or VS Code Insiders and offer to open the config folder
Copy file name to clipboardExpand all lines: src/ALZ/Private/Tools/Test-Tooling.ps1
+31-16Lines changed: 31 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,14 @@ function Test-Tooling {
6
6
[Parameter(Mandatory=$false)]
7
7
[switch]$checkYamlModule,
8
8
[Parameter(Mandatory=$false)]
9
-
[switch]$skipYamlModuleInstall
9
+
[switch]$skipYamlModuleInstall,
10
+
[Parameter(Mandatory=$false)]
11
+
[switch]$skipAzureLoginCheck
10
12
)
11
13
12
14
$checkResults=@()
13
15
$hasFailure=$false
16
+
$azCliInstalledButNotLoggedIn=$false
14
17
15
18
# Check if PowerShell is the correct version
16
19
Write-Verbose"Checking PowerShell version"
@@ -134,25 +137,33 @@ function Test-Tooling {
134
137
message="Azure CLI is installed."
135
138
result="Success"
136
139
}
137
-
} else {
138
-
$checkResults+=@{
139
-
message="Azure CLI is not installed. Follow the instructions here: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli"
140
-
result="Failure"
141
-
}
142
-
$hasFailure=$true
143
-
}
144
140
145
-
# Check if Azure CLI is logged in
146
-
Write-Verbose"Checking Azure CLI login status"
147
-
$azCliAccount=$(az account show -o json) |ConvertFrom-Json
148
-
if ($azCliAccount) {
149
-
$checkResults+=@{
150
-
message="Azure CLI is logged in. Tenant ID: $($azCliAccount.tenantId), Subscription: $($azCliAccount.name) ($($azCliAccount.id))"
151
-
result="Success"
141
+
# Check if Azure CLI is logged in
142
+
Write-Verbose"Checking Azure CLI login status"
143
+
$azCliAccount=$(az account show -o json 2>$null) |ConvertFrom-Json
144
+
if ($azCliAccount) {
145
+
$checkResults+=@{
146
+
message="Azure CLI is logged in. Tenant ID: $($azCliAccount.tenantId), Subscription: $($azCliAccount.name) ($($azCliAccount.id))"
147
+
result="Success"
148
+
}
149
+
} else {
150
+
$azCliInstalledButNotLoggedIn=$true
151
+
if ($skipAzureLoginCheck.IsPresent) {
152
+
$checkResults+=@{
153
+
message="Azure CLI is not logged in. Login will be prompted later."
154
+
result="Warning"
155
+
}
156
+
} else {
157
+
$checkResults+=@{
158
+
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."
159
+
result="Failure"
160
+
}
161
+
$hasFailure=$true
162
+
}
152
163
}
153
164
} else {
154
165
$checkResults+=@{
155
-
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."
166
+
message="Azure CLI is not installed. Follow the instructions here: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli"
156
167
result="Failure"
157
168
}
158
169
$hasFailure=$true
@@ -268,4 +279,8 @@ function Test-Tooling {
268
279
Write-InformationColored"Cannot continue with Deployment..."-ForegroundColor Red -InformationAction Continue
269
280
throw"Accelerator software requirements have no been met, please review and install the missing software."
# Query Azure for management groups and subscriptions (for interactive selection)
222
-
$azureContext=@{
223
-
ManagementGroups=@()
224
-
Subscriptions=@()
225
-
}
222
+
# If az cli is installed but not logged in, prompt for tenant ID and login with device code
223
+
if ($needsFolderStructureSetup-and$toolingResult-and$toolingResult.AzCliInstalledButNotLoggedIn) {
224
+
Write-InformationColored"`nAzure CLI is installed but not logged in. Let's log you in..."-ForegroundColor Yellow -InformationAction Continue
225
+
Write-InformationColored"You'll need your Azure Tenant ID. You can find this in the Azure Portal under Microsoft Entra ID > Overview."-ForegroundColor Cyan -InformationAction Continue
$tenantId=Read-Host"`nEnter your Azure Tenant ID (GUID)"
231
+
if ($tenantId-notmatch$guidRegex) {
232
+
Write-InformationColored"Invalid Tenant ID format. Please enter a valid GUID (e.g., 00000000-0000-0000-0000-000000000000)"-ForegroundColor Red -InformationAction Continue
233
+
}
234
+
} while ($tenantId-notmatch$guidRegex)
226
235
227
-
if ($needsFolderStructureSetup) {
228
-
$azureContext=Get-AzureContext
236
+
Write-InformationColored"`nLogging in to Azure using device code authentication..."-ForegroundColor Green -InformationAction Continue
237
+
Write-InformationColored"A browser window will open for you to authenticate. Follow the instructions to complete login."-ForegroundColor Cyan -InformationAction Continue
238
+
239
+
az login --use-device-code --tenant $tenantId--allow-no-subscriptions 2>&1|Out-Null
240
+
if ($LASTEXITCODE-ne0) {
241
+
Write-InformationColored"Azure login failed. Please try again or login manually using 'az login --tenant $tenantId'."-ForegroundColor Red -InformationAction Continue
242
+
throw"Azure login failed."
243
+
}
244
+
245
+
Write-InformationColored"Successfully logged in to Azure!"-ForegroundColor Green -InformationAction Continue
229
246
}
230
247
231
248
# If no inputs provided, prompt user for folder structure setup
0 commit comments