Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override a parameter in the parameters.json file with PowerShell when deploying ARM template

I am using Azure PowerShell to deploy an ARM templates but want to override a parameter in the parameters.json file at runtime

Is there a way to do this?

eg I use get-azurermresource to get the virtual network name into a variable called $vnetName I then want to pass this variable $vnetName to replace the parameters for Vnet Name in the azuredeploy.parameters.json file

like image 839
itye1970 Avatar asked Mar 08 '18 10:03

itye1970


1 Answers

To overwrite the paramter at runtime you can just specify it when invoking the New-AzureRmResourceGroupDeployment cmdlet:

 New-AzureRmResourceGroupDeployment `
  -TemplateFile D:\tmp\azuredeploy.json `
  -TemplateParameterFile D:\tmp\azuredeploy.json `
  -<yourParameterNameHere> $vnetName `
  -ResourceGroupName myRg

You could also permanently overwrite the json file itself using PowerShell:

$paramFile = Get-Content d:\tmp\azuredeploy.parameters.json | ConvertFrom-Json
$paramFile.parameters.vnetName.value = $vnetName 
$paramFile | ConvertTo-Json | Set-Content d:\tmp\azuredeploy.parameters.json
like image 102
Martin Brandl Avatar answered Sep 28 '22 07:09

Martin Brandl