You can provide custom parameter resolvers by placing plain JavaScript files, with .js file extension, into the resolvers directory. Each file must export a parameter resolver provider object. Takomo uses the provider to initialize the actual parameter resolver.
The parameter resolver provider must implement the ResolverProvider interface which has the following properties:
name
init
schema
ctx
- CommandContext object that provides access to project configurationjoi
- Joi instance to create new validation constraintsbase
- A pre-initialized Joi object schema that you can modify to provide your resolver's validation schemaThe parameter resolver must implement the Resolver interface which consists of the following properties:
resolve
ctx
- CommandContext object that provides access to project configurationlogger
- Logger instance.stack
- The stack where the parameter whose value is being resolved belongs to.listParameterIndex
- If the parameter whose value is being resolved is of type list, this will hold the index of the value in the list. The index begins from 0. This will be 0 if the parameter being resolved os not list.parameterName
- Name of the parameter whose value is being resolved.variables
- A mutable copy of the current command variables during the stack operation.confidential
dependencies
iamRoleArns
Here's an example of a simple custom parameter resolver that converts the value given in the parameter resolver configuration to uppercase. The parameter resolver schema requires that in the stack configuration file where the resolver is used, the resolver configuration must contain a value property of type string, and that its value must not have more than 50 characters.
Our file structure looks like this:
The parameter resolver provider defined in resolvers/uppercase.js looks like this:
Our custom parameter resolver is used in the stack configuration like so:
When the stack is deployed, the value for MyParameter parameter is resolved using the uppercase custom parameter resolver. The actual value that is assigned to the parameter will be "HELLO".
You can share your custom resolvers with others by publishing them to NPM. The published NPM package must export a parameter resolver provider object.
Here's an example of how to publish a simple custom resolver that returns the current timestamp. The project file structure looks like this:
The index.js file contains the parameter resolver provider:
The package.json file contains minimum configuration that is needed to publish the resolver to NPM:
Refer to official NPM documentation for more information about publishing NPM packages.
To use custom resolvers published to NPM, you need to install the resolver's NPM package to your project and then register the resolver in your project's takomo.yml file.
Let's see how we would include the timestamp resolver from the previous example to our own project.
First of all, we need to install and save the resolver package to our project's dependencies:
Then, we need to register the resolver to our Takomo project by modifying the takomo.yml file. There are three ways to register a resolver:
When registering the resolver using option 1 or 2, Takomo registers the resolver using the name exposed by the resolver provider object - in this case that is timestamp.
It's possible that our project already has a resolver registered with the same name. Takomo requires that all resolver names are unique and will throw an error if more that one resolver has the same name. To work around this problem, you can use the third way to register a resolver, which let's you specify a new name for it. In our example, we have set the resolver name to be special-timestamp.
Once the resolver is registered, you can use it like any resolver. For more information, see the related documentation.
You can also implement custom parameter resolvers using TypeScript. Make sure you have TypeScript support enabled.
Place code for your custom parameter resolvers in src
directory under the project directory:
Register your parameter resolvers in takomo.ts
file located in the project directory like so: