Skip to main content

Tests Python Support

iac-validate

A CLI tool to perform syntactic and semantic validation of YAML files.

$ iac-validate -h
Usage: iac-validate [OPTIONS] [PATHS]...

  A CLI tool to perform syntactic and semantic validation of YAML files.

Options:
  --version              Show the version and exit.
  -v, --verbosity LVL    Either CRITICAL, ERROR, WARNING, INFO or DEBUG
  -s, --schema FILE      Path to schema file. (optional, default:
                         '.schema.yaml', env: IAC_VALIDATE_SCHEMA)
  -r, --rules DIRECTORY  Path to semantic rules. (optional, default:
                         '.rules/', env: IAC_VALIDATE_RULES)
  -o, --output FILE      Write merged content from YAML files to a new YAML
                         file. (optional, env: IAC_VALIDATE_OUTPUT)
  --non-strict           Accept unexpected elements in YAML files.
  -h, --help             Show this message and exit.

Syntactic validation is done by basic YAML syntax validation (e.g., indentation) and by providing a Yamale schema and validating all YAML files against that schema. Semantic validation is done by providing a set of rules (implemented in Python) which are then validated against the YAML data. Every rule is implemented as a Python class and should be placed in a .py file located in the --rules path.

Each .py file must have a single class named Rule. This class must have the following attributes: id, description and severity. It must implement a classmethod() named match that has a single function argument data which is the data read from all YAML files. It should return a list of strings, one for each rule violation with a descriptive message. A sample rule can be found below.

class Rule:
    id = "101"
    description = "Verify child naming restrictions"
    severity = "HIGH"

    @classmethod
    def match(cls, data):
        results = []
        try:
            for child in data["root"]["children"]:
                if child["name"] == "FORBIDDEN":
                    results.append("root.children.name" + " - " + str(child["name"]))
        except KeyError:
            pass
        return results

Installation

Python 3.7+ is required to install iac-validate. Don't have Python 3.7 or later? See Python 3 Installation & Setup Guide.

iac-validate can be installed in a virtual environment using pip:

pip install iac-validate

Pre-Commit Hook

The tool can be integrated via a pre-commit hook with the following config (.pre-commit-config.yaml), assuming the default values (.schema.yaml, .rules/) are appropriate:

repos:
  - repo: https://github.com/netascode/iac-validate
    rev: v0.1.6
    hooks:
      - id: iac-validate

In case the schema or validation rules are located somewhere else the required CLI arguments can be added like this:

repos:
  - repo: https://github.com/netascode/iac-validate
    rev: v0.1.6
    hooks:
      - id: iac-validate
        args:
          - '-s'
          - 'my_schema.yaml'
          - '-r'
          - 'rules/'

Ansible Vault Support

Values can be encrypted using Ansible Vault. This requires Ansible (ansible-vault command) to be installed and the following two environment variables to be defined:

export ANSIBLE_VAULT_ID=dev
export ANSIBLE_VAULT_PASSWORD=Password123

ANSIBLE_VAULT_ID is optional, and if not defined will be omitted.

Additional Tags

Reading Environment Variables

The !env YAML tag can be used to read values from environment variables.

root:
  name: !env VAR_NAME

Metadata

Release files for iac-validate 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iac-validate 0.2.7
File Size Uploaded Provenance Actions
iac_validate-0.2.7.tar.gz 11.7 kB Without provenance Details for iac_validate-0.2.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iac-validate 0.2.7
File Interpreter ABI Platform Actions
iac_validate-0.2.7-py3-none-any.whl Python 3 none any Details for iac_validate-0.2.7-py3-none-any.whl

Total release size: 26.4 kB

Release files / iac_validate-0.2.7.tar.gz

Download URL iac_validate-0.2.7.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8172a4a633b2b65631a1e42aa354e31b8af1796ae479177d96925f2ff020eb50
BLAKE2b-256 checksum
How to use checksums
287b84fa7c06ef7ea607a9eb3ed6d1e9d02c0f7f9d1ace33110f10e533d277b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.0 CPython/3.12.3 Linux/6.8.0-1017-azure

Release files / iac_validate-0.2.7-py3-none-any.whl

Download URL iac_validate-0.2.7-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c2fd00b487d2cae3fce065aa9b51d308b0899342fffe2b92b71ebf402d8b924
BLAKE2b-256 checksum
How to use checksums
15a3b4dbe327583ad1039bde997f3bec8eed7c894082605b23bace839dd3e7b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.0 CPython/3.12.3 Linux/6.8.0-1017-azure

Security for iac-validate 0.2.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page