Pass Variables
Variables are module-level objects that allow you to pass values to your module at runtime. When running Flowpipe, you can pass values on the command line or from a .fpvars file, and you will be prompted for any variables that have no values.
Locals are internal, private variables used only within your mod - you cannot pass values in at runtime.
Input Variables
Defining Input Variables
Flowpipe mods support input variables that are similar to Terraform input variables. You declare them with a variable block:
The type is optional, though it is generally recommended that you provide the type explicitly to provide clarity to the user and to avoid unexpected run time errors due to unforeseen type coercions.
You can optionally define a default value and description for the variable.
If a variable does not define a default, the user will be prompted for its value when Flowpipe starts. If a variable defines a default, the user is not prompted and the default value is used if the variable is not explicitly set.
You may also provide a description of the variable. The description helps to provide information about the intent and format of the variable to the user of the mod. The description is included when the user is prompted for a variable's value.
Types
Flowpipe supports the standard HCL string, number, and bool type primitives.
The keyword any may be used to indicate that any type is acceptable. If no type is defined, it is assumed to be any:
Collection types (list, map, set, object) may also be used:
You can even create deeply nested types:
In addition to the standard string, number, and bool primitives, Flowpipe connection and notifier config primitives may be specified.
You can even specify a variable as a specific type of connection:
As with any type, collections may also be defined:
Enum
Flowpipe supports an enum argument to provide a set of allowed values; no other values are allowed.
Using Input Variables
Variables may be referenced as var.<NAME>. Variables are often used as defaults for pipeline parameters:
Passing Input Variables
When running Flowpipe, you can pass variables in several ways. You can pass individual variable values on the command line with one or more --var arguments:
For connection or notifier variables, pass them by name:
When passing list variables, they must be enclosed in single quotes:
You can specify variable values in a .fpvars file, using HCL syntax:
Flowpipe automatically reads in the file named flowpipe.fpvars as well as any file ending in .auto.fpvars from the working directory if they exist. You can also specify a variable file by name on the command line:
You may also set variable values via environment variables. Simply prefix the Flowpipe variable name with FP_VAR_:
If you run Flowpipe from a mod that defines input variables, and they are not set anywhere (no default, not set in a .fpvars file, not set with --var argument, not set via an environment variable) then Flowpipe will prompt you for them before running the pipeline.
Flowpipe loads variables in the following order, with later sources taking precedence over earlier ones:
- Environment variables
- The flowpipe.fpvars file, if present.
- Any *.auto.fpvars files, in alphabetical order by filename.
- Any --var and --var-file options on the command line, in the order they are provided.
Passing Variables for Dependency Mods
A Flowpipe mod can depend on other mods, and those dependency mods may include variables that you would like to pass. To set them, prefix the variable names with the mod name and then set them like any other variable.
You can set them in a .fpvars file:
Or pass them to the command with the --var argument
Local Variables
Flowpipe supports using local variables in a manner similar to Terraform local values. Unlike variables, locals cannot be passed in at runtime, but are useful as internal private variables.
The locals block defines and sets one or more local variables, using standard HCL assignment syntax. The locals are scoped to the mod, and a mod may contain multiple locals blocks. Locals may reference other values in the mod, including other local values.
A set of one or more local values can be declared in one or more locals blocks:
Once a local value is declared, you can reference it in expressions as local.<NAME>.