json - Trying to make if/else powershell for ARM template -
i have powershell script arm template deploy resources azure, more ase v2.
my arm template has condition in stating:
"sv-ase-version": "v2", "sv-asp-template-filenamehash": { "v1": "[concat(variables('sv-baseuri'),concat('/azuredeploy-asp.v1.json',parameters('_artifactslocationsastoken')))]", "v2": "[concat(variables('sv-baseuri'),concat('/azuredeploy-asp.json',parameters('_artifactslocationsastoken')))]" }, what have right in powershell:
param( [string] $templatefile = 'azuredeploy-dev.json', [string] $templateparametersfile = 'azuredeploy-dev.parameters.json', ) $templatefile = [system.io.path]::getfullpath([system.io.path]::combine($psscriptroot, $templatefile)) $templateparametersfile = [system.io.path]::getfullpath([system.io.path]::combine($psscriptroot, $templateparametersfile)) what wanna add in powershell is:
param( [string] $templatefile = 'azuredeploy-dev.json', [string] $templateparametersfile = 'azuredeploy-dev.parameters.json', [string] $templatefilev2 = 'azuredeploy.json', [string] $templateparametersfilev2 = 'azuredeploy.parameters.json', ) #checking if correct way if ("sv-ase-version" -eq "v1") { $templatefile = [system.io.path]::getfullpath([system.io.path]::combine($psscriptroot, $templatefile)) $templateparametersfile = [system.io.path]::getfullpath([system.io.path]::combine($psscriptroot, $templateparametersfile)) } else { $templatefilev2 = [system.io.path]::getfullpath([system.io.path]::combine($psscriptroot, $templatefilev2)) $templateparametersfilev2 = [system.io.path]::getfullpath([system.io.path]::combine($psscriptroot, $templateparametersfilev2)) } my intention: make switch in json file, without needing change things in powershell.
would work? how approach differently?
thanks.
the easiest way use parameter in template, call deploymentprefix:
"deploymentprefix": { "type": "string", "defaultvalue": "dev", "allowedvalues": [ "dev", "prod" ], "metadata": { "description": "resources created prefixed this." } }, and based on value of parameter decide deploy in template:
"variables": { "template-dev": "someurl", "template-prod": "someotherurl", "template-url": "[concat('template-', parameters('deploymentprefix))]" ... } and in powershell use new-azurermresourcegroupdeployment , pass (dev or prod) parameter , template figure out use template-url variable.
Comments
Post a Comment