Test cases for parameter files

This article describes the tests that are run with the template test toolkit for parameter files. For example, a file named azuredeploy.parameters.json. The examples include the test names and code samples that pass or fail the tests. For more information about how to run tests or how to run a specific test, see Test parameters.

The toolkit includes test cases for Azure Resource Manager templates (ARM templates) and the main template files named azuredeploy.json or maintemplate.json.

Use valid contentVersion

Test name: DeploymentParameters Should Have ContentVersion

The contentVersion must contain a string in the format 1.0.0.0 and only use numbers.

The following example fails because the contentVersion is missing.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

The following example fails because contentVersion isn't a string.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": {},
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

The following example passes.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

File must include parameters

Test name: DeploymentParameters Should Have Parameters

A parameter file must include the parameters section.

The following example fails.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
}

The following example passes.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

Use valid schema version

Test name: DeploymentParameters Should Have Schema

The parameter file must include a valid schema version.

There are two valid schema versions for parameter files:

  • https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#
  • https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#

The following example fails.

{
  "$schema": "https://schema.management.azure.com/schemas/2021-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

The following example passes.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

Parameters must contain values

Test name: DeploymentParameters Should Have Value

A parameter must contain a value or a reference. For secrets such as a password, a key vault uses a reference in the parameter file. For more information, see Use Azure Key Vault to pass secure parameter value during deployment.

The following example fails because stgAcctName doesn't have a value.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {}
  }
}

The following example passes.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

Next steps