Introduction
When using static imports with HashiCorp Sentinel, you can include the same static data in your tests without duplicating the data. This allows you to validate your policies against consistent, predefined datasets.
Prerequisites
- Sentinel
v0.19or newer
Procedure
To use static data in your Sentinel tests, you must specify the path to the data file within each test case.
- In your test file, define a
staticimport block. - Set the
sourceattribute to the relative path of your static data file. This method is distinct from mocking data, as outlined in the documentation.
The following example shows an excerpt from a test file that imports a static JSON file.
# In your test file (e.g., test/my-policy/pass.hcl)
import "static" "example" {
source = "../../data/my-static-import.json"
format = "json"
}