How to get the parameter file of Powershell Script and use the same parameter in ARM template deployment task in the same Release Pipeline

Murali R 245 Reputation points
2023-12-19T18:39:04.7966667+00:00

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.

Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,056 questions
Azure Network Watcher
Azure Network Watcher
An Azure service that is used to monitor, diagnose, and gain insights into network performance and health.
161 questions
{count} votes

Accepted answer
  1. ChaitanyaNaykodi-MSFT 24,231 Reputation points Microsoft Employee
    2023-12-28T04:28:41.3466667+00:00

    @Murali R

    Thank you for sharing the solution achieved above.

    I am just summarizing the issue and the solution above for community benefit. As current limitations in Microsoft Q&A you can only accept answers from other users. It will be helpful if you could accept the answer for community benefit.

    Solution achieved:

    You modified the code as shown below to get the storage ID.

    # Get all storage accounts in the resource group
    $storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName | Select-Object -First 1
    
    # Extract the Storage ID
    $storageId = $storageAccount.Id
    
    
    

    You also had to set the RBAC role below to be able to fetch the correct data.

    Microsoft.Storage/storageAccounts/read
    

    Thank you!

    0 comments No comments

0 additional answers

Sort by: Most helpful