Schema validation
Infrahub requires the user to define multiple YAML files. One or more files defining the schema in Infrahub and the external repository configuration file.
To help with the process of creating and maintaining these files, we publish JSON schemas that allow you to validate the schema of these files.
Language server​
To be able to validate a YAML against a schema, you need to install a language server. Which language server you can use is specific to your environment and the editor that you use. For Visual Studio Code we recommend that you install the Red Hat YAML Language server.
A language server is a software that helps an editor provide advanced language specific features like: code completion, refactoring, navigation, syntax highlighting, schema validation etc.
Schema validation for Infrahub schema files​
The schema for Infrahub schema files is published at https://schema.infrahub.app/infrahub/schema/latest.json
To use this schema for validation, you have to add a modeline near the top, or the bottom of the schema file.
A modeline is a file specific configuration parameter that configures the editor with a specific behavior. In our case it configures the editor's language server to use the schema at the URL for schema validation.
This modeline can be used for Infrahub schema files.
# yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json
An example in an Infrahub schema file.
# yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json
nodes:
- name: Test
namespace: Infra
Schema validation for Infrahub external repository configuration files​
The schema for an Infrahub external repository configuration file is published at https://schema.infrahub.app/python-sdk/repository-config/latest.json
To use this schema for validation, you have to add a modeline near the top, or the bottom of the repository configuration file.
A modeline is a file specific configuration parameter that configures the editor with a specific behavior. In our case it configures the editor's language server to use the schema at the URL for schema validation.
This modeline can be used for an Infrahub external repository configuration file.
# yaml-language-server: $schema=https://schema.infrahub.app/python-sdk/repository-config/latest.json
An example in an Infrahub schema file.
# yaml-language-server: $schema=https://schema.infrahub.app/python-sdk/repository-config/latest.json
schemas:
- ./schemas/locations.yml
The schema of the Infrahub external repository configuration file has been published on JSON Schema store. It allows an editor, like Visual Studio Code to download the correct schema validation file. Visual Studio Code will automatically validate a file named .infrahub.y(a)ml with this schema, if the Red Hat YAML Language server is installed.
Schema strict mode​
By default, Infrahub operates in schema strict mode: all schema validators run every time a schema change is made or when the CI pipeline runs schema validation checks.
New Infrahub versions occasionally introduce new validators — for new features or previously uncovered scenarios. This may require changes to existing data or schema before upgrading, which isn't always immediately possible.
For this reason, strict mode can be disabled using the INFRAHUB_SCHEMA_STRICT_MODE environment variable.
The following validators are disabled when INFRAHUB_SCHEMA_STRICT_MODE is set to false:
- relationships same parent constraint validator
min_lengthless thanmax_lengthattribute parameter validatormin_valueless thanmax_valueattribute parameter validator- HFID uses only unique attribute validator
min_value,max_value,excluded_valuesnumber attribute constraints validator
Schema strict mode should only be disabled temporarily to ease upgrades when new validations have been introduced. Re-enable it as quickly as possible.