Skip to content

Commit

Permalink
updates to account for existing resourceGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoore-msft committed Apr 4, 2018
1 parent 8b115a6 commit 34052c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Deploy-AzureResourceGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ else {

$TemplateArgs.Add('TemplateParameterFile', $TemplateParametersFile)

# Create or update the resource group using the specified template file and template parameters file
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop
# Create the resource group only when it doesn't already exist
if ((Get-AzureRmresourcegroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction SilentlyContinue) -eq $null) {
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop
}

if ($ValidateOnly) {
$ErrorMessages = Format-ValidationOutput (Test-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
Expand Down
7 changes: 6 additions & 1 deletion az-group-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ then

fi

az group create -n "$resourceGroupName" -l "$location"
# Create the resource group only if it doesn't already exist
targetResourceGroup=$( az group list -o json | jq -r '.[] | select(.name == '\"$resourceGroupName\"')'.name )
if [[ -z $targetResourceGroup ]]
then
az group create -n "$resourceGroupName" -l "$location"
fi

# Remove line endings from parameter JSON so it can be passed in to the CLI as a single line
parameterJson=$( echo "$parameterJson" | jq -c '.' )
Expand Down

0 comments on commit 34052c6

Please sign in to comment.