Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse resource group #10927

Open
2 of 15 tasks
gavintoddchurch opened this issue Nov 8, 2024 · 3 comments
Open
2 of 15 tasks

reuse resource group #10927

gavintoddchurch opened this issue Nov 8, 2024 · 3 comments

Comments

@gavintoddchurch
Copy link

Description

When you want to reuse a resource group there is the parameter ReuseResourceGroup that is deprecated and says not to use it but if you don't pass it it prompts to delete the RG. What is the way to do this as of now?

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Ubuntu 24.04
  • macOS 12
  • macOS 13
  • macOS 13 Arm64
  • macOS 14
  • macOS 14 Arm64
  • macOS 15
  • macOS 15 Arm64
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

N/a

Is it regression?

N/a

Expected behavior

when passing nothing it reuses the group like it says in the propt

Actual behavior

prompts to choose y or n to reuse resource group

Repro steps

run image generation without -reuseresourcegroup with an existing rg in azure.

@lakshminarayana02
Copy link

Hi @gavintoddchurch

We request that you provide logs or any additional data about this issue to validate and reproduce it.

@Liabaemt
Copy link

Liabaemt commented Nov 8, 2024

Fix runerge

@gavintoddchurch
Copy link
Author

Hi @gavintoddchurch

We request that you provide logs or any additional data about this issue to validate and reproduce it.

If you run the GenerateResourcesAndImage command without -ReuseResourceGroup it will prompt you with a yes or no if you want to delete the resource group.

If you pass -ReuseResourceGroup you get this warning

WARNING: The ReuseResourceGroup and Force parameters are deprecated and will be removed in a future release. The resource group will be reused when it already exists and an error will be thrown when it doesn't. If you want to delete the resource group, please delete it manually.

The warning indicates resource group will be reused if it exists and you must delete it manually but the logic does do that. The only way to reuse the resource group is to pass the deprecated parameter

if ($ResourceGroupExists -and -not $ReuseResourceGroup) {
if ($Force) {
# Delete and recreate the resource group
Write-Host "Deleting resource group '$ResourceGroupName'..."
az group delete --name $ResourceGroupName --yes --output none
if ($LastExitCode -ne 0) {
throw "Failed to delete resource group '$ResourceGroupName'."
}
Write-Host "Resource group '$ResourceGroupName' was deleted."
$ResourceGroupExists = $false
}
else {
# 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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants