Custom components

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

Custom components

Custom components are a way to create new components from a pipeline of built-in and other custom components.

A custom component includes:

  • Arguments: Settings that configure the custom component.
  • Exports: Values the custom component exposes to its consumers.
  • Components: Built-in and custom components that run as part of the custom component.

Create custom components

Use the declare configuration block to create a new custom component. The block’s label specifies the custom component’s name.

You can use the following configuration blocks inside a declare block:

  • argument: Define a named argument whose current value you can reference using the expression argument.NAME.value. The user of the custom component determines argument values.
  • export: Define a named value to expose to custom component users.

Custom components are helpful for reusing a common pipeline multiple times. To learn how to share custom components across files, refer to Modules.

Example

This example creates a custom component called add, which exports the sum of two arguments:

alloy
declare "add" {
    argument "a" { }
    argument "b" { }

    export "sum" {
        value = argument.a.value + argument.b.value
    }
}

add "example" {
    a = 15
    b = 17
}

// add.example.sum == 32