Schemas
You can validate deployment targets you have defined in the deployment configuration using custom Joi validation schemas.
Take a look at custom validation schemas documentation to learn more about custom schemas.
You associate schemas with a deployment group using the targetsSchema property, which accepts a single schema or a list of schemas. Takomo uses the schemas associated with a deployment group to validate all deployment targets located under it in the deployment groups hierarchy.
You can also specify the targetsSchema property at the top-level of the deployment configuration. Top-level schemas are applied to all deployment groups.
The schemas used to validate deployment targets must be object schemas because the deployment targets to validate are given as an object whose keys are paths to deployment targets in the deployment groups hierarchy, and values are configurations of the deployment target themselves.

Example

Let's add two custom validation schemas. One to validate that if the budget variable is given, it must be a non-negative number, and another to validate that the environment variable is given and is one of the allowed values. The schemas are located in the schemas directory.
schemas/budget.js
1
module.exports = {
2
name: "budget",
3
init: ({ joi }) =>
4
joi.object().pattern(
5
/^/,
6
joi
7
.object({
8
vars: joi
9
.object({
10
budget: joi.number().min(0),
11
}),
12
})
13
.unknown(true),
14
),
15
}
Copied!
schemas/environment.js
1
module.exports = {
2
name: "environment",
3
init: ({ joi }) =>
4
joi.object().pattern(
5
/^/,
6
joi
7
.object({
8
vars: joi
9
.object({
10
environment: joi.valid("dev", "sandbox", "prod"),required(),
11
}),
12
}).required()
13
.unknown(true),
14
),
15
}
Copied!
With these schemas available, we can modify our deployment configuration and refer to the schemas with their names.
deployment/targets.yml
1
vars:
2
cost-center: 12345
3
budget: 2000
4
5
targetsSchema: budget
6
7
deploymentGroups:
8
all:
9
configSets: security
10
all/shared:
11
vars:
12
cost-center: 10000
13
budget: 500
14
targets:
15
- name: infra
16
all/application:
17
configSets: networking
18
targetsSchema: environment
19
vars:
20
cost-center: 600
21
all/application/dev:
22
targets:
23
- name: dev-environment
24
vars:
25
environment: dev
26
- name: sandbox
27
vars:
28
environment: sandbox
29
all/application/prod:
30
targets:
31
- name: prod-environment
32
vars:
33
environment: prod
34
budget: 300
Copied!
We use the budget schema for all deployment targets and the environment schema for the targets under the all/applications deployment group.
With this configuration, the object that gets passed to our custom schemas looks like this:
1
all/shared/infra:
2
deploymentGroupPath: all/shared
3
name: infra
4
configSets:
5
- security
6
vars:
7
cost-center: 10000
8
budget: 500
9
all/application/dev/dev-environment:
10
deploymentGroupPath: all/application/dev
11
name: dev-environment
12
configSets:
13
- security
14
- networking
15
vars:
16
cost-center: 12345
17
budget: 2000
18
environment: dev
19
all/application/dev/sandbox:
20
deploymentGroupPath: all/application/dev
21
name: sandbox
22
configSets:
23
- security
24
- networking
25
vars:
26
cost-center: 12345
27
budget: 2000
28
environment: sandbox
29
all/application/prod/prod-environment:
30
deploymentGroupPath: all/application/prod
31
name: prod-environment
32
configSets:
33
- security
34
- networking
35
vars:
36
cost-center: 12345
37
budget: 300
38
environment: prod
Copied!
Last modified 4mo ago
Copy link