Skip to main content

Set Vars

Overview

The Set Vars action is used to define or update global variables in a Traffic Policy's runtime context. Subsequent actions or expressions can reference these variables for conditional logic through expressions or dynamic interpolation.

Configuration Reference

This is the Traffic Policy configuration reference for this action.

Supported Phases

on_http_request, on_http_response, on_tcp_connect

Type

set-vars

Configuration Fields

  • varsarray of map[string]any of size 1Required

    vars is a list of maps that have a key of string and a value of any valid CEL type

    Each map must be of exactly size 1, and represents one variable where the key is the name of the variable

Behavior

The set-vars action allows you to define your own global variables to be used in future actions or expressions. After being defined, they can be accessed using the "${vars.<name>}" syntax within CEL interpolated strings. The variables can be of any valid CEL type, including strings, booleans, doubles, null, maps, and lists.

CEL Interpolation

Strings can also support CEL interpolation, allowing for dynamic values and types. Within string values, you can use the syntax ${<expression>} to evaluate expressions and include their results in the string. CEL-interpolated strings that are exactly of the form "${vars.<name>}" will resolve to the evaluated type. Strings that contain CEL-interpolated substrings within them such as sample ${conn.tls.client.pem} here will convert all CEL-interpolated substrings to strings

Scoping

The variables defined in the set-vars action are scoped to the Traffic Policy and are not accessible outside of it. Variables defined in each of the three phases (on_http_request, on_http_response, on_tcp_connect) are scoped to that phase, and cannot be accessed in other phases.

Referencing other variables and macros

CEL-interpolated strings may reference all other variables and macros available to traffic policies. This also includes variables previously defined in the same or previous set-vars actions. This allows for powerful dynamic behavior and customization of your Traffic Policy.

Examples

Basic Example

The following Traffic Policy configuration is an example configuration of the set-vars action.

Example Traffic Policy Document

Loading…

CEL Interpolation Example

The following Traffic Policy configuration is an example of using CEL-interpolation with the set-vars action.

Example Traffic Policy Document

Loading…

Setting Vars based on Previous Vars Example

The following Traffic Policy configuration is an example of setting vars based on previous vars with the set-vars action. Variables are determined in the order in which they are listed in the configuration list.

Example Traffic Policy Document

Loading…