Hi Team,
Iam using the below Powershell script to get the Parameter file and using the same file in ARM template deployment task in Azure Devops Release pipeline. Both the task runs in Release Pipeline.
First Task - Azure Powershell task
param (
$FilePath,
$ResourceGroupName,
$NetworkWatcherName,
$location,
$workspaceRegion,
$workspaceResourceId,
$workspaceId
)
# Get all network security groups in the resource group
$nsgs = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroupName
$nsgIds = @()
$nsgNames = @()
$nsgRgNames = @()
foreach ($nsg in $nsgs) {
$nsgIds += $nsg.Id
$nsgNames += $nsg.Name
$nsgRgNames += $nsg.ResourceGroupName
}
# Get all storage accounts in the resource group
$storageAccounts = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName
# Get the storage account
$storageAccount = $storageAccounts[0]
$data = @{
"`$schema" = "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#"
"contentVersion" = "1.0.0.0"
"parameters" = @{
"nsgIds" = @{
"value" = $nsgIds
}
"nsgNames" = @{
"value" = $nsgNames
}
"nsgRgNames" = @{
"value" = $nsgRgNames
}
"NetworkWatcherName" = @{
"value" = $NetworkWatcherName
}
"location" = @{
"value" = $location
}
"workspaceRegion" = @{
"value" = $workspaceRegion
}
"workspaceResourceId" = @{
"value" = $workspaceResourceId
}
"workspaceId" = @{
"value" = $workspaceId
}
"storageId" = @{
"value" = $storageAccount.Id
}
}
} | ConvertTo-Json -Depth 100
$data | Out-File -FilePath $FilePath
All the values has been passed in Script Argument and release pipeline variable
Script Arguments:
-FilePath $(System.DefaultWorkingDirectory)/VSS_WESTEUROPE_NSG.parameters.json -ResourceGroupName VSS_WESTEUROPE_NSG -NetworkWatcherName $(NetworkWatcherName) -location $(location) -workspaceRegion $(workspaceRegion) -workspaceResourceId $(workspaceResourceId) -workspaceId $(workspaceId)
In Arm Template deployment task, iam using the below in Template parameters
$(System.DefaultWorkingDirectory)/VSS_WESTEUROPE_NSG.parameters.json
Release pipeline gets succeeded of both the tasks, but the NSG Flow log is not created in the Azure Portal. Kindly help on this.