Skip to main content

atmos.GomplateDatasource

The atmos.GomplateDatasource template function wraps the Gomplate Datasources and caches the results, allowing executing the same data source many times without calling the external endpoint multiple times. It speeds up the data source execution and stack processing, and can eliminate other issues with calling an external endpoint, e.g. timeouts and rate limiting.

Usage

  {{ (atmos.GomplateDatasource "<alias>").<attribute> }}

Arguments

alias
The datasource alias
attribute
Attribute name (field) from the datasource

Caching the result of atmos.GomplateDatasource function

Atmos caches (in memory) the results of atmos.GomplateDatasource template function execution. If you execute the function for the same datasource alias more than once, the first execution will call the external endpoint, produce the result and cache it. All the consecutive calls will just use the cached data. This is useful when you use the atmos.GomplateDatasource function for the same datasource alias in multiple places in Atmos stack manifests. It will speed up the function execution and stack processing.

For example:

settings:
templates:
settings:
gomplate:
timeout: 5
datasources:
ip:
url: "https://api.ipify.org?format=json"
headers:
accept:
- "application/json"
components:
terraform:
test:
vars:
tags:
test1: '{{ (datasource "ip").ip }}'
test2: '{{ (atmos.GomplateDatasource "ip").ip }}'
test3: '{{ (atmos.GomplateDatasource "ip").ip }}'
test4: '{{ (atmos.GomplateDatasource "ip").ip }}'

In the example, we define a gomplate datasource ip and specify an external endpoint in the url parameter.

We use the Gomplate datasource function in the tag test1, and the atmos.GomplateDatasource wrapper for the same datasource alias ip in the other tags. The atmos.GomplateDatasource wrapper will call the same external endpoint, but will cache the result and reuse it between the datasource invocations.

When processing the component test from the above example, Atmos does the following:

  • Executes the {{ (datasource "ip").ip }} template. It calls the external endpoint using the HTTP protocol and assign the ip attribute from the result to the tag test1

  • Executes the {{ (atmos.GomplateDatasource "ip").ip }} template. It calls the external endpoint again, caches the result in memory, and assigns the ip attribute from the result to the tag test2

  • Executes the {{ (atmos.GomplateDatasource "ip").ip }} two more times for the tags test3 and test4. It detects that the result for the same datasource alias ip is already presend in the memory cache and reuses it without calling the external endpoint two more times

The datasource result caching makes the stack processing much faster and significantly reduces the load on external endpoints, preventing such issues as timeouts and rate limiting.