armval

A validation CLI for Azure Resource Manager (ARM) templates

Usage no npm install needed!

<script type="module">
  import armval from 'https://cdn.skypack.dev/armval';
</script>

README

ARM Validation CLI

Build Status

About

Unmaintained for reference only.

The aim is to create a simple CLI which can be run during CI to validate ARM templates and catch issues early.

Usage

To install use: (Note: Node v8 or higher is required)

    npm install -g armval

To validate ARM templates armval in a folder structure containing azuredeploy.json files.

You can specify a custom glob to match you file naming convention like this armval "**/*mytemplate.json"

If you have errors which you want to ignore add an armvalconfig.json with the following structure in the directory:

{
    "ignore": {
        "global": [ // These issues are skipped in all files
            {
                "message": "Unrecognized function name 'nonfunction'.",
                "jsonPath": "resources.1.dependsOn.1",
                "reason": "optional reason for the ignore"
            },
            {
                "message": ".*",
                "resource": { // You can match a resource by providing the values for `name`, `apiVersion` and `type`
                    "name":".*",
                    "apiVersion":".*",
                    "type":"Microsoft.Storage/storageAccounts"
                }
            }
        ],
        "test/testdata/azuredeploy.schema.1error.json": [
            {
                "message": ".*",
                "resource": {
                    "name":"[variables('storageAccountName')]",
                    "apiVersion":"2017-10-05",
                    "type":"Microsoft.Storage/storageAccounts"
                },
                "reason": "Schema is out of data for this resource type" // You can provide reasons which show in the CLI when these rules trigger
            }
        ],
        "test/testdata/azuredeploy.arm.repeatederror.json": [ // The path of the file 
            {
                "message": "Unrecognized function name 'nonfunction'.", // The message to skip. (This accepts a regex)
                "jsonPath": "resources.1.dependsOn.1" // The JSONPath to the location of the error. (This accepts a regex)
            },
            {   // Using the Regex this will skip this error  
                // in any children/properties of `resources.1`
                "message": "Unrecognized function name 'nonfunction'.",
                "jsonPath": "resources.1.*" 
            },
            {
                "message": ".*", // This would skip everthing 
                "jsonPath": ".*" // in this file
            }
        ]
    }
}

Note: Why the complicated ignore process? As JSON doesn't allow comments the standard //ignorethis style isn't doable and I didn't want to rely on linenumbers as file changes would mean edits to the ignore file.

Sample output

The tool will highlight JSON Language, ARM syntax and schema issues. The output is as follows:

Using default glob '**/*azuredeploy*.json' as none provided
-----------------------------
Files to be checked based on Glob '**/*azuredeploy*.json'
[ 'test/testdata/azuredeploy.arm.1error.json',
  'test/testdata/azuredeploy.json',
  'test/testdata/azuredeploy.json.1error.json',
  'test/testdata/azuredeploy.schema.1error.json',
  'test/testdata/azuredeploy.schema.invalid.json',
  'test/testdata/azuredeploy.schema.nonjson.json' ]
-----------------------------

 --> Checking file test/testdata/azuredeploy.arm.1error.json 

Found 1 issues 

Error: Unrecognized function name 'nonfunction'. 
 Location: { line: 60 char: 11 } 
 Type: Error 
 From: VSCodeARMValidation 
 File: test/testdata/azuredeploy.arm.1error.json 
 JsonPath: resources.1.dependsOn.1


-----------------------------

 --> Checking file test/testdata/azuredeploy.json 

Found 0 issues 

-----------------------------

 --> Checking file test/testdata/azuredeploy.json.1error.json 

Found 1 issues 

Error: Expected comma 
 Location: { line: 17 char: 5 } 
 Type: Error 
 From: VSCodeJSONLanguageServer 
 File: test/testdata/azuredeploy.json.1error.json 
 JsonPath: parameters.containerInstanceLocation


-----------------------------

 --> Checking file test/testdata/azuredeploy.schema.1error.json 

Found 1 issues 

Error: Value is not accepted. Valid values: "2017-06-01". 
 Location: { line: 45 char: 23 } 
 Type: Warning 
 From: VSCodeJSONLanguageServer 
 File: test/testdata/azuredeploy.schema.1error.json 
 JsonPath: resources.0.apiVersion


-----------------------------

 --> Checking file test/testdata/azuredeploy.schema.invalid.json 

Found 1 issues 

Error: JSON Document may not be an ARM template, it's missing the '$schema' field of the value in invalid 
 Location: { line: 1 char: 1 } 
 Type: Error 
 From: SchemaValidation 
 File: test/testdata/azuredeploy.schema.invalid.json 
 JsonPath: undefined


-----------------------------

 --> Checking file test/testdata/azuredeploy.schema.nonjson.json 

Found 1 issues 

Error: JSON Document may not be an ARM template, it's missing the '$schema' field of the value in invalid 
 Location: { line: 1 char: 1 } 
 Type: Error 
 From: SchemaValidation 
 File: test/testdata/azuredeploy.schema.nonjson.json 
 JsonPath: undefined


-----------------------------

Dev

First clone the repository using --recurse-submodules to ensure the nested repositories are restored. Then:

  1. npm install && npm build && nodejs ./index.js