Skip to content

Commit

Permalink
helpers/GenerateResourcesAndImage.ps1: check for interactive mode (ac…
Browse files Browse the repository at this point in the history
…tions#8326)

* helpers/GenerateResourcesAndImage.ps1: check for interactive mode

when RG already exists, we asked user whether to delete it, however it
is only possible in interactive mode

* mention -ReuseResourceGroup as an option, add back new line
  • Loading branch information
ilia-shipitsin authored Sep 22, 2023
1 parent e1ac652 commit 73b4a8a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions helpers/GenerateResourcesAndImage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,23 @@ Function GenerateResourcesAndImage {
$ResourceGroupExists = $false
}
else {
# Resource group already exists, ask the user what to do
$title = "Resource group '$ResourceGroupName' already exists"
$message = "Do you want to delete the resource group and all resources in it?"
# are we running in a non-interactive session?
# https://stackoverflow.com/questions/9738535/powershell-test-for-noninteractive-mode
if ([System.Console]::IsOutputRedirected -or ![Environment]::UserInteractive -or !!([Environment]::GetCommandLineArgs() | Where-Object { $_ -ilike '-noni*' })) {
throw "Non-interactive mode, resource group '$ResourceGroupName' already exists, either specify -Force to delete it, or -ReuseResourceGroup to reuse."
}
else {
# Resource group already exists, ask the user what to do
$title = "Resource group '$ResourceGroupName' already exists"
$message = "Do you want to delete the resource group and all resources in it?"

$options = @(
[System.Management.Automation.Host.ChoiceDescription]::new("&Yes", "Delete the resource group and all resources in it."),
[System.Management.Automation.Host.ChoiceDescription]::new("&No", "Keep the resource group and continue."),
[System.Management.Automation.Host.ChoiceDescription]::new("&Abort", "Abort execution.")
)
$result = $Host.UI.PromptForChoice($title, $message, $options, 0)
$options = @(
[System.Management.Automation.Host.ChoiceDescription]::new("&Yes", "Delete the resource group and all resources in it."),
[System.Management.Automation.Host.ChoiceDescription]::new("&No", "Keep the resource group and continue."),
[System.Management.Automation.Host.ChoiceDescription]::new("&Abort", "Abort execution.")
)
$result = $Host.UI.PromptForChoice($title, $message, $options, 0)
}

switch ($result) {
0 {
Expand Down

0 comments on commit 73b4a8a

Please sign in to comment.