lookup (Function)¶
Fetch a key from a map. Provide a default as the third argument to avoid errors when the key is missing.
Example Usage¶
locals {
lookup_settings = {
database_host = "db.example.com"
database_port = 5432
}
lookup_db_host = provider::pyvider::lookup(local.lookup_settings, "database_host", "localhost")
lookup_missing = provider::pyvider::lookup(local.lookup_settings, "missing_key", "default")
}
output "lookup_results" {
value = {
found = local.lookup_db_host
notfound = local.lookup_missing
}
}
Signature¶
lookup(map_to_search: map[string, any], key: string, options: variadic) -> any
Parameters¶
map_to_search(map[string, any], required) — Map to read. Returnsnullwhen this isnull.key(string, required) — Key to retrieve.options(variadic, optional) — First value acts as the default result.
Returns¶
The matching value, the provided default, or null when the map itself is null.
Notes¶
- Without a default, a missing key raises a
FunctionError.