AzureFeatured

Part 9 – Arm Template – Parameter File

Add parameter files

You can use a separate JSON file to store the value for parameters being declared on base template.

In Visual Studio Code ‘VsCode’, create a new json file, name it azuredeploy.parameters.dev.json

{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
   "storagePrefix": {
     "value": "devstore"
   },
   "storageSKU": {
     "value": "Standard_LRS"
   },
   "appServicePlanName": {
     "value": "devplan"
   },
   "webAppName": {
     "value": "devapp"
   },
   "resourceTags": {
     "value": {
       "Environment": "Dev",
       "Project": "Tutorial"
     }
   }
 }
}

This file is your parameter file for the development environment. Notice that it uses Standard_LRS for the storage account, names resources with a dev prefix, and sets the Environment tag to Dev.

Again, create a new file with the following content. Save the file with the name azuredeploy.parameters.prod.json.

{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
   "storagePrefix": {
     "value": "contosodata"
   },
   "storageSKU": {
     "value": "Standard_GRS"
   },
   "appServicePlanName": {
     "value": "contosoplan"
   },
   "webAppName": {
     "value": "contosowebapp"
   },
   "resourceTags": {
     "value": {
       "Environment": "Production",
       "Project": "Tutorial"
     }
   }
 }
}

We now created Parameter file, we passed value to our storagePrefix, StorageSKU..etc in this new JSON file.

Similar to storage, we can use this file to pass all resources parameter value here.

Deploy template

$parameterFile="{path-to-azuredeploy.parameters.prod.json}"
New-AzResourceGroup `
  -Name myResourceGroupProd `
  -Location "West US"
New-AzResourceGroupDeployment `
  -Name prodenvironment `
  -ResourceGroupName myResourceGroupProd `
  -TemplateFile $templateFile `
  -TemplateParameterFile $parameterFile
Show More

Related Articles

Back to top button