Schemas
You can use custom Joi validation schemas to validate the following parts of stack configuration:
    stack data
    stack tags
    stack parameters
    stack name
You use the schemas property to specify which schemas Takomo should use for validation.

Example

In this example we have specified to use myDataSchema schema to validate data configuration. For tags, we have two schemas: commonTags and environmentTag.
1
schemas:
2
data: myDataSchema
3
tags:
4
- commonTags
5
- name: environmentTag
6
allowedValues:
7
- dev
8
- test
9
- prod
Copied!
The implementation of myDataSchema schema provider could look like this:
1
schemas/data.js
2
3
module.exports = {
4
name: "myDataSchema",
5
init: ({ joi }) => joi.object({
6
owner: joi.string().email(),
7
costCenter: joi.number().required()
8
})
9
}
Copied!
The file exports an object with two properties name and init. The former specifies the schema's name used to refer to it from configuration files and the latter is a function that initializes the schema object.
Read more about custom validation schemas from here.
The implementation of commonTags schema provider could look like this:
schemas/common-tags.js
1
module.exports = {
2
name: "commonTags",
3
init: ({ joi }) => joi.object({
4
project: joi.string().required()
5
})
6
}
Copied!
Finally, we have the implementation of environmentTag schema provider:
schemas/environment-tag.js
1
module.exports = {
2
name: "environmentTag",
3
init: ({ joi, props }) => {
4
return joi.object({
5
environment: joi.string().valid(...props.allowedValues)
6
})
7
}
8
}
Copied!
Unlike the other schema providers, its init function uses properties from the stack configuration file that are passed via the props argument.

Where to define

The schemas property can be defined in stack and stack group configuration files. If specified in a stack group, the stack group's children and stacks inherit the value. The schemas defined by stack groups and stacks are appended to the list of schemas they inherit from their parent.

Requirements

The schemas property must satisfy these requirements:
    Must be an object with the following optional properties: data, tags, parameters and name.
Last modified 4mo ago
Export as PDF
Copy link