Reputation: 17
I am trying to deploy azure resources [Resource Group] from Devops using ARM Template and Powershell. Below is the setup
Error
Upvotes: 0
Views: 222
Reputation: 8470
The New-AzResourceGroupDeployment is used to add a deployment to the pre-existing
resource group, if the resource group doesn't exist, it will report the error in your screenshot.
To create a resource group, you can simply use New-AzResourceGroup which doesn't require ARM template. Then you can start to deploy on this resource group.
The ARM template on my side is used to deploy storage account on the resource group, fixed the pipeline and powershell as below for example:
stages:
- stage: Partner
displayName: Dev
jobs:
- deployment: Dev_deployment
displayName: Dev deployment
pool:
vmImage: Windows-latest
environment: Dev
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: AzurePowerShell@5
displayName: Lab Dev Deployment
inputs:
azureSubscription: 'ARMConn4'
ScriptType: 'InlineScript'
Inline: |
Set-Location $(System.DefaultWorkingDirectory)
./deployment/master.ps1 -environment "dev" -rgconfig @{"dev"=@{"rgname"="rg_DevOpsCICDNew"}} # rgconfig is required as hashtable type in your powershell
azurePowerShellVersion: 'LatestVersion'
The powershell:
param
(
[Parameter(Mandatory=$true)][string] $environment,
#[Parameter(Mandatory=$true)][hashtable] $commonconfig,
[Parameter(Mandatory=$true)][hashtable] $rgconfig
)
$ARMTemplateFilePath = Resolve-Path -Path .\ARMtemplate\resourcegroup\resourcegroup.json
$ARMTemplateParamFilePath = Resolve-Path -Path .\ARMtemplate\resourcegroup\parameters.json
Write-Host $ARMTemplateFilePath
Write-Host $ARMTemplateParamFilePath
Write-Host $rgconfig[$environment].rgname
# $Deployment = @{
# ResourceGroupName = $rgconfig[$environment].rgname
# TemplateFile = $ARMTemplateFilePath
# TemplateParameterFile = $ARMTemplateParamFilePath
# }
New-AzResourceGroup -Name $rgconfig[$environment].rgname -Location "East US"
sleep 60 # add delay after resource group creation
#New-AzResourceGroupDeployment @Deployment
New-AzResourceGroupDeployment -ResourceGroupName $rgconfig[$environment].rgname -TemplateFile $ARMTemplateFilePath -TemplateParameterFile $ARMTemplateParamFilePath
Write-Host "Deployment is complted for ResourceGroup :" $rgconfig[$environment].rgname
The pipeline succeeds, and resource group created, deployment(storageaccount) completed on the resource group.
Upvotes: 0