Skip to main content

A Jinja filter for allowing Sceptre resolvers in var files

Project description

README

Overview

A custom Jinja filter for Sceptre for unquoting resolvers appearing in var files.

Motivation

In Sceptre, resolvers are an essential feature for simplifying complex configurations by enabling dynamic data retrieval. Resolvers such as !stack_output_external and !stack_output are particularly useful for referencing output values from other stacks or external sources, among many others.

When using resolvers in var files, however, they must be protected from being interpreted as YAML tags by the YAML loader.

This plugin addresses this challenge by allowing you to safely include resolvers in your var files. It ensures that resolvers are not processed as YAML tags by the loader, and then turned back into YAML tags after Jinja interpolation in the generated config.

Installation

Installation instructions

To install directly from PyPI

pip install jinja-unquote-resolvers-filter

To install from the git repo

pip install git+https://github.com/Sceptre/jinja-unquote-resolvers-filter.git

Usage/Examples

In your var file:

Subnets:
  - '!stack_output_external mystack::subnet_a'  # Quotes needed to protect a YAML tag.
  - '!stack_output_external mystack::subnet_b'

VPC: '!stack_output_external mystack::vpc_id'

In your config:

j2_environment:
  extensions:
    - jinja_unquote_resolvers_filter.UnquoteResolversFilterExtension

sceptre_user_data:
  subnets:
    {{ var.Subnets | unquote_resolvers(output_indent=4, trim=True) }}
  vpc: {{ var.VPC }}  # This filter is not needed if the quoted resolvers are passed in as scalars.

Arguments

  • indent (optional, default=2): The number of spaces to use for indentation of nested structures in the output YAML.
  • output_indent (optional, default=0): The number of spaces to use for indentation of the entire output YAML.
  • trim (optional, default=False): Whether to trim leading and trailing spaces in the output YAML.

Limitations

At this time, resolver expressions must be wrapped in a single line of text. That is, instead of:

my_multiline_resolver: |
  !from_json
    - !request http://www.whatever.com

Instead write:

my_multiline_resolver: '!from_json [!request http://www.whatever.com]'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja_unquote_resolvers_filter-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file jinja_unquote_resolvers_filter-0.0.1.tar.gz.

File metadata

File hashes

Hashes for jinja_unquote_resolvers_filter-0.0.1.tar.gz
Algorithm Hash digest
SHA256 646602e67f6e42b5b5c4d172c3b33a5e5b6bfff281f1f54649e1b4bcf27ec20c
MD5 eef3dafce5083a8f5dfcd4af443bab94
BLAKE2b-256 2780c4089be7b202d30978c8a7cc861d504d7d1363823c7a3c2b0f08132e71b0

See more details on using hashes here.

File details

Details for the file jinja_unquote_resolvers_filter-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jinja_unquote_resolvers_filter-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c70b7c0ab6cddd8ac2b72ba1a09d8e8481cfbb9f1479b2af6c3cc1f600e3b38
MD5 a888ca2cff0d0583e94cd61d2c15f8ae
BLAKE2b-256 da1cd97af94676903f6291843e8f32d3c3fec49aab3429ce1f9ceb8b071ac201

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page