Configuration

Env Alias #

Env Alias configuration files are YAML format files that define how their alias definitions behave.

All Env Alias configurations MUST have an env-alias: top-level root.

Environment variable names are defined by the second-level key name, such as TF_PLUGIN_CACHE_DIR as shown in the short example below.

The environment value itself is then defined using 3x main components:-

  • [source|exec|value] - source content that is passed to the parser is specified using either a source, exec or value setting. Content via source may be local-file or http-remote; content via exec provides the content from STDOUT and; content can directly assigned using a value setting.
  • parser - the parser to use for the source-content can be automatically estimated based on the filename extension or the Content-Type header (if http-remote). However the parser can also be set directly which is useful when the source content does not use an indicative filename extension which is common with ini-config files. Env Alias provides 4x parsers, INI-config, YAML, JSON or simple TEXT file formats.
  • selector - the selector provides the ability to “pick” out a value from the parsed content.
    Structured content formats (ini, yaml, json) support dot-notation (eg: foo.0.bar) and brace-notation (eg: foo[0]bar) as data selectors. Text files support line-number selectors only. A special none selector exists which prevents any environment variable setting which are useful when using a shell-exec and the output is not needed.

Example #

The example below shows an Env Alias configuration for setting up a Terraform environment. Notice that all parts of the environment are easily established by calling a single alias name and that no secret values are contained within.

  • Environment variable TF_VAR_aws_access_key_id is set by reading the file ~/.aws/credentials and selecting the value from account_name.aws_access_key_id
  • Environment variable TF_VAR_aws_secret_access_key is set in a similar manner.
  • The path ~/.terraform.d/plugin-cache is created and the shell exec stdout is not assigned to anything.
  • Environment variable TF_PLUGIN_CACHE_DIR is set directly in-line to the value ~/.terraform.d/plugin-cache
env-alias:

    TF_VAR_aws_access_key_id:
        source: '~/.aws/credentials'
        parser: 'ini'
        selector: 'account_name.aws_access_key_id'

    TF_VAR_aws_secret_access_key:
        source: '~/.aws/credentials'
        parser: 'ini'
        selector: 'account_name.aws_secret_access_key'
        
    TF_PLUGIN_CACHE_DIR_CREATE:
        exec: 'mkdir -p ~/.terraform.d/plugin-cache'
        selector: null

    TF_PLUGIN_CACHE_DIR:
        value: '~/.terraform.d/plugin-cache'