Takomo
  • What is Takomo?
  • Getting started
    • Installation
    • Quick start
    • Tutorial
  • Configuration
    • AWS credentials
    • Directory structure
    • Stacks and stack groups
    • Project configuration
  • Stack properties
    • Name
    • Regions
    • Template
    • Template bucket
    • Command role
    • Account ids
    • Depends
    • Parameters
    • Tags
    • Inherit tags
    • Termination protection
    • Timeout
    • Capabilities
    • Stack policy
    • Ignore
    • Obsolete
    • Hooks
    • Data
    • Schemas
  • Variables and templating
    • Introduction
    • Handlebars syntax
    • Environment variables
    • Command-line variables
    • Partials
    • Helpers
    • Available variables
  • Parameter resolvers
    • Built-in parameter resolvers
      • Stack output resolver
      • External stack output resolver
      • Command resolver
      • File contents resolver
      • Hook output resolver
      • SSM parameter resolver
      • Secret resolver
    • Custom parameter resolvers
  • Hooks
    • Built-in hooks
    • Custom hooks
    • Sharing data between hooks
  • Validation schemas
    • Custom validation schemas
  • Command-line usage
    • Common options
    • Deploy stacks
    • Undeploy stacks
    • Prune stacks
    • List stacks
    • Detect drift
    • Generate IAM policies
    • Inspect stack configuration
    • Inspect stack dependencies
  • Support
    • Getting help
    • Troubleshooting
  • Development
    • Change log
Powered by GitBook
On this page
  • Schema provider
  • Examples
  • Validation schema for stack tags

Was this helpful?

Export as PDF
  1. Validation schemas

Custom validation schemas

PreviousSharing data between hooksNextCommon options

Last updated 3 years ago

Was this helpful?

You can use custom Joi validation schemas to validate your configuration.

Please read more about Joi from its .

You provide custom validation schemas by placing plain JavaScript files, with .js file extension, into the schemas directory or its subdirectories. Each file must export a . Takomo uses the provider to initialize the actual schema.

You can use all language features available in Node 14.4.0.

Schema provider

Schema provider initializes a Joi validation schema. It has the following properties:

  • name

    • Name of the resolver used to refer to the schema from configuration files. It can be either a string or a function that returns a string. The function must not be asynchronous.

    • Required.

  • init

    • A function that initializes the Joi schema object with properties given in a configuration file that uses to the schema.

    • The function can be either synchronous or asynchronous, and must return an instantiated Joi schema.

    • It takes one argument that is an object with the following properties:

      • ctx - object that provides access to project configuration

      • joi - Joi instance to create new validation constraints

      • props - Properties from the configuration file

    • Required.

  • schema

    • A function that return a Joi schema object used to validate the properties given to the init function.

    • It takes one argument that is an object with the following properties:

      • ctx - object that provides access to project configuration

      • joi - Joi instance to create new validation constraints

      • base - A pre-initialized that you can modify to provide your resolver's validation schema

    • You can return the pre-initialized schema from the schema function or use the Joi instance to create an entirely new schema. In most cases you should modify the base schema object as needed and then return it.

    • Optional.

Examples

Here are a few examples of custom schemas.

Validation schema for stack tags

First, you need to implement a schema provider. We name our tag schema as my-tags and specify two required properties: environment and costCenter. In other words, we require that every stack must always have these two tags.

schemas/my-tags.js
module.exports = {
  name: "my-tags",
  init: ({ joi }) => joi.object({
    environment: joi.string().valid("dev", "test", "prod").required(),
    costCenter: joi.number().required()
  }).unknown(false)
} 

In stack configuration we specify that we want to validate stack tags using our custom schema like so:

schemas:
  tags: my-tags
  
tags:
  environment: dev
  costCenter: 1234  

You can find more information from the .

You can use the property to specify validation schemas for stack tag configuration. Tag configuration is an object whose keys are tag keys and values are value for the corresponding tags. Therefore you need to use Joi's object schema to validate your tag configurations.

API documentation
schemas
official documentation
CommandContext
CommandContext
Joi object schema
schema provider object