• Infrastructure
    • terraform
    • packer
  • Networking
    • consul
  • Security
    • vault
    • boundary
  • Applications
    • nomad
    • waypoint
    • vagrant
  • HashiCorp Cloud Platform

    A fully managed platform to automate infrastructure on any cloud with HashiCorp products.

    • consul
    • terraform
    • vault
    • packerbeta
    Visit cloud.hashicorp.com
Sentinel
  • Intro
  • Docs
Download
    • v0.19.x (latest)
    • v0.18.x
    • v0.17.x
    • v0.16.x
    • v0.15.x
    • v0.14.x
    • v0.13.x
  • Release Notes
    • Overview
    • Policy as Code
    • Policy Language
    • Imports
    • Enforcement Levels
    • Overview
    • Override Files
    • Remote Sources
    • Overview
    • apply
    • fmt
    • test
    • Overview
    • Basics
    • Rules
    • Traces
    • Testing
    • Imports
    • Debugging
    • Overview
    • Modules
    • Plugins
    • Static Imports
    • Internals

    • Overview
    • Variables
    • Values
    • Lists
    • Maps
    • Rules
    • Imports
    • Parameters
    • Boolean Expressions
    • Arithmetic
    • Slices
    • Conditionals
    • Loops
    • Collection Operations
    • Functions
    • Scope
    • Undefined
    • Logging and Errors
    • Specification
    • Overview
    • append
    • delete
    • error
    • keys
    • length
    • print
    • range
    • values
    • Overview
    • base64
    • decimal
    • http
    • json
    • runtime
    • sockaddr
    • strings
    • time
    • types
    • units
    • version

  • Consul
  • Nomad
  • Terraform
  • Vault
Type '/' to Search

»Language: Variables

Variables store values that can be used later.

Most notably, a variable assignment of main is required for all Sentinel policies. This is the main rule that is executed to determine the result of a policy. The main rule may use other variables that are assigned in the policy.

Example:

a = 1
b = a + 1

In this example, two variables are assigned: a and b. a is given the value of "1" and b uses the a to calculate its own value.

»Syntax

The syntax for assigning a variable is:

IDENTIFIER = VALUE

On the left of the equal sign is an identifier. This is a name for your variable and will be how you reference it later. An identifier is any combination of letters and digits, but must start with a letter. An underscore _ is also a valid letter.

On the right is any valid Sentinel value or expression. A value is a literal value such as a number or string. An expression is some computed value such as doing math, calling a function, etc.

»Assignment and Reassignment

A variable is assigned when it is given a value. You can also reassign variables at any time by setting it to a new value. The new value takes effect for any subsequent use of that variable. A variable can be reassigned to a different type.

For example:

a = 1       // a = 1
b = a       // b = 1
a = "value" // a = "value", b = 1
c = a       // c = "value", b = 1

In the above example you can see that the variables are set and reassigned. Notice that the value of a variable is the current value, and that reassigning a variable only affects future uses of that variable. You can see this with c and b being different values.

»Unassigned Variables

Using a variable that is unassigned is an error.

In the example below, the first line would result in the policy erroring. Sentinel is executed top-down and the value of c is not available yet on the first line.

a = c // Error!
c = 1

»Type Conversion

While a topic more related to values, variables can be assigned (or-reassigned) a different value type via type conversion.

s = "1.1"
a = int(s)   // a = 1
a = float(s) // a = 1.1

a = 1
s = string(a) // s = "1"

For more details, see the type conversion sections in the values page, or the Sentinel Language Specification.

  • ProvisionMulti-Cloud Infrastructure
  • SecureMulti-Cloud Security
  • ConnectMulti-Cloud Networking
  • RunMulti-Cloud Orchestration
Products
  • Terraform
  • Vault
  • Consul
  • Nomad
  • Vagrant
  • Packer
  • Boundary NEW
  • Waypoint NEW
  • Sentinel
Resources
  • Blog
  • Tutorials
  • Community
  • Events
  • Integrations
  • Library
  • Partners
  • Podcast
  • Support
  • Training
Company
  • About Us
  • JobsWe're Hiring
  • Press Center
  • Brand
  • Contact Us
  • System Status
  • Cookie Manager
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
stdin: is not a tty