Functions Reference
Functions Reference
Section titled “Functions Reference”varlock provides several powerful functions that allow for dynamic and composable environment variable values. This reference covers all available functions, their arguments, and usage examples.
varlock()
Section titled “varlock()”The varlock() function is used to handle encrypted values. It decrypts the provided encrypted string at runtime.
# @sensitiveAPI_KEY=varlock("encrypted_string_here")Arguments
Section titled “Arguments”encrypted_string(string, required): The encrypted value to be decrypted
Example
Section titled “Example”# @sensitiveDATABASE_PASSWORD=varlock("oipjfdopiajpfoidjpaoijpofdjpoa...")fallback()
Section titled “fallback()”The fallback() function provides a way to specify multiple possible values, using the first non-empty value in the list.
VALUE=fallback("", undefined, "default-value")Arguments
Section titled “Arguments”- Multiple values (any type): The function will use the first non-empty value in the list
Example
Section titled “Example”# TODO: add examplesconcat()
Section titled “concat()”The concat() function combines multiple strings into a single string.
PATH=concat("base/", ref("ENV"), "/config.json")Arguments
Section titled “Arguments”- Multiple strings (string): The strings to be concatenated
Example
Section titled “Example”# Simple concatenationAPI_URL=concat("https://", ref("DOMAIN"), "/api")
# Complex path constructionCONFIG_PATH=concat("config/", ref("ENV"), "/", ref("REGION"), ".json")eval()
Section titled “eval()”The eval() function executes a command and uses its output as the value. This is useful for integrating with external tools and services.
SECRET=eval(`op read "op://vault/item/credential"`)Arguments
Section titled “Arguments”command(string, required): The command to execute
Example
Section titled “Example”# Using 1Password CLIAPI_KEY=eval(`op read "op://dev test/${OP_VAULT}/credential"`)
# Using AWS CLIAWS_CREDENTIALS=eval(`aws sts get-session-token --profile prod`)The ref() function references the value of another environment variable. This is equivalent to using ${VARIABLE} syntax.
NEW_VAR=ref("EXISTING_VAR")Arguments
Section titled “Arguments”variable_name(string, required): The name of the variable to reference
Example
Section titled “Example”# Simple referenceAPI_URL=concat("https://", ref("DOMAIN"), "/api")
# Nested referencesCONFIG_PATH=concat("config/", ref("ENV"), "/", ref("REGION"), ".json")Function Composition
Section titled “Function Composition”Functions can be composed together to create complex value resolution logic. Here are some examples:
# Using multiple functions togetherAPI_URL=concat("https://", ref("DOMAIN"), "/", ref("API_VERSION"))
# Dynamic configuration with evalCONFIG=eval(`aws ssm get-parameter --name "/config/${ENV}" --with-decryption`)