Question:
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
Answer:
To overwrite the paramter at runtime you can just specify it when invoking the New-AzureRmResourceGroupDeployment
cmdlet:
1 2 3 4 5 6 |
New-AzureRmResourceGroupDeployment ` -TemplateFile D:\tmp\azuredeploy.json ` -TemplateParameterFile D:\tmp\azuredeploy.json ` - -ResourceGroupName myRg |
You could also permanently overwrite the json file itself using PowerShell:
1 2 3 4 |
$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 |