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

Was this helpful?

Export as PDF
  1. Hooks

Sharing data between hooks

Hooks can expose values to other hooks by returning a hook output object. Takomo stores the returned value with a hook's name in a mutable variables object that it then passes to the subsequent hooks. Takomo discards the mutable variables object after the stack operation completes, which means the exposed data is not visible to hooks executed in other stacks.

Example

This example shows how you can share data between hooks.

Our file structure looks like this:

.
├─ stacks
│  └─ my-stack.yml
├─ hooks
│  ├─ first.js 
│  └─ second.js
└─ templates
   └─ my-stack.yml

There are two custom hooks located in the hooks dir.

hooks/first.js
module.exports = {
  type: "first",
  init: (props) => {
    return {
      execute: (input) => {
        return {
          message: "OK",
          success: true,
          value: "My greeting to the next hook"
        }
      }
    }
  }
}

The first hook returns a hook output object that contains a greeting to other hooks in the value property.

hooks/second.js
module.exports = {
  type: "second",
  init: (props) => {
    return {
      execute: (input) => {
        const greeting = input.variables.hooks.firstHook
        // Do something with the greeting here...
        return true
      }
    }
  }
}

The second hook reads the greeting from the input argument.

And this is how you glue everything together in a stack configuration file:

template: my-stack.yml
regions: eu-west-1
hooks:
  - name: firstHook
    type: first
  - name: secondHook
    type: second  

The hooks property defines two hooks, one of each type. Takomo executes the hooks in order they are defined.

PreviousCustom hooksNextCustom validation schemas

Last updated 3 years ago

Was this helpful?