Creating and Using Flow Variables

Flow Variables enable you to pass information from a Flow's configuration in Terraform, into the Sym Python SDK.


Flow Variables can be used to pass data from your Terraform configuration to your Python implementation (commonly This information can then be accessed in the and used to inform a decision via an SDK Workflow Handler.

Configuring Flow Variables

In order to illustrate how Flow Variables can be used, we can use an example that implements an auto_approve feature that depends on the user's email.

Add a variable to Terraform

First, to set up Flow Variables, add a vars block to your sym_flow resource.

resource "sym_flow" "this" {
  # ... other values omitted

  # These variables are made available in your via `event.flow.vars`
  vars = {
    # You can add more emails to this as a comma separated list, e.g. auto_approve = "[email protected],[email protected]"
    # This variable is used in the `on_request` hook in!
    auto_approve = "${var.user_email}"

  # ... other values omitted

Use the variable in Python

Now, in the, we will have access to this variable we just defined via event.flow.vars. We can then create a hook that will do something useful with this information.

Here, we are checking if the requesting user is allowed to be auto-approved. If they are, we modify the reason to display that it was an auto-approval and return an automatic approval right as they are making the request.

# Hooks let you change the control flow of your workflow.
def on_request(event):
    """Auto-approve people defined in the auto-approve list in the sym_flow vars"""

    flow_vars = event.flow.vars
    auto_approve = flow_vars["auto_approve"].split(",")

    if event.user.username in auto_approve:
        original_reason = event.payload.fields.get("reason")
        new_reason = f"Auto-approved! {original_reason}️"
        return ApprovalTemplate.approve(reason=new_reason)

Too see another example of Flow Variable usage, check out our doc about passing in a Lambda ARN from Terraform .