CLI for rendering configuration templates with SSM Parameter Store as a data source
Project description
SSM Parameter Store Template
Command line application to render templates with data from SSM Parameter Store
Installation
The ssm-ps-template
application is available via the Python Package Index and can be installed with pip:
pip install ssm-ps-template
Templating
The application uses Jinja2 for the templating engine.
Configuration
The configuration file provides the ability to specify multiple templates, override AWS configuration, and change logging levels:
Top-Level Configuration Directives
Directive | Description |
---|---|
templates |
An array of template directives as detailed in the next table. |
endpoint_url |
Specify an endpoint URL to use to override the default URL used to contact SSM Parameter Store |
profile |
Specify the AWS profile to use. If unspecified will default to the AWS_DEFAULT_PROFILE environment variable or is unspecified |
region |
Specify the AWS region to use. If unspecified it will default to the AWS_DEFAULT_REGION environment variable or is unspecified |
verbose |
Turn debug logging on. Possible values are true and false |
Template Configuration Directives
The templates
directive in the configuration is an array of objects, defined by a source
and destination
.
Directive | Description |
---|---|
source |
The source file of the template |
destination |
The destination path to write the rendered template to |
prefix |
The prefix to prepend variables with if they do not start with a forward-slash (/ ) |
Extended Templating Functionality
In addition to the base functionality exposed by Jinja2, the following Python functions have been added:
Function | Definition |
---|---|
urlparse |
The urllib.parse.urlparse function from the Python standard library. |
parse_qs |
The urllib.parse.parse_qs function from the Python standard library. |
unquote |
The urllib.parse.unquote function from the Python standard library. |
The following filters are added:
Filter | Description |
---|---|
toyaml |
Converts a dictionary value to YAML |
The following variables are exposed:
Variable | Definition |
---|---|
environ |
The os.environ dictionary for accessing environment variables |
Configuration File Format
The application supports JSON, TOML, or YAML for configuration. The following example is in YAML:
Example Configuration File
templates:
- source: /etc/ssm-templates/nginx-example
destination: /etc/nginx/sites-available/example
prefix: /namespaced/application/nginx/
- source: /etc/ssm-templates/postgres-example
destination: /etc/postgresql/14/main/postgresql.conf
prefix: /namespaced/application/postgres/
profile: default
region: us-east-1
verbose: false
Path Based Dictionaries
In more complex templates it's possible to need a dictionary of values from SSM instead of straight key/value usage.
This is achieved by setting a variable to a key with a trailing slash (/
).
The following pattern will retrieve all keys under a path and return them as a nested dictionary with a /
delimiter,
and then iterate over the key/value pairs:
{% set values = settings/ %}
{% for key, value in settings.items() %}
{{ key }}: {{ value }}
{% endfor %}
Or to convert them to YAML:
settings: {% set values = settings/ %}
{{ values | toyaml | indent(2, first=True) }}
Command Line Usage
usage: ssm-ps-template [-h] [--aws-profile AWS_PROFILE] [--aws-region AWS_REGION] [--prefix PREFIX] [--verbose] config
Templating for SSM Parameter Store
positional arguments:
config
optional arguments:
-h, --help show this help message and exit
--aws-profile AWS_PROFILE
AWS Profile
--aws-region AWS_REGION
AWS Region
--endpoint-url ENDPOINT_URL
Specify an endpoint URL to use when contacting SSM Parameter Store.
--prefix PREFIX Default SSM Key Prefix
--replace-underscores
Replace underscores in variable names to dashes when looking for values in SSM
--verbose
Note that the default SSM prefix can also be set with the PARAMS_PREFIX
environment variable and
the endpoint URL setting cn be set with the ENDPOINT_URL
environment variable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ssm-ps-template-1.1.0.tar.gz
.
File metadata
- Download URL: ssm-ps-template-1.1.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eab6f97f9972dbf1a7e768f16deab4154b552de91975608d4ea7fc5c059ca9f7 |
|
MD5 | c53d2e33977b120f32c7145ec2e83d7b |
|
BLAKE2b-256 | 22310c9b7eadd9e75a6e005bbe7bc8a195941896533963e742b4cfa9af8b66d9 |
File details
Details for the file ssm_ps_template-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: ssm_ps_template-1.1.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0cd08149694309eb6d841b2da7ddb95bffa2dc611d679ef6f3bc6fd99579090 |
|
MD5 | f510a9478592d15119ae0ead4c8ef72a |
|
BLAKE2b-256 | c310496393bb61af239183dbf3fee40e3c2345a722cc865f3f477549c1a97981 |