diff --git a/docs/jinja2_functions_filters.rst b/docs/jinja2_functions_filters.rst index ded7635..03f5edf 100644 --- a/docs/jinja2_functions_filters.rst +++ b/docs/jinja2_functions_filters.rst @@ -37,6 +37,26 @@ Parameters: * ``fallback_value``: a value to use if case the property is missing. +from_resolve +-------------- + +Parameter: A string that looks like the {{resolve:}} string in AWS CloudFormation + +For example, building the string below, we retrieve the key `SASL_JAAS_CONFIG` from the content of the secret, which we +get the ARN from the `env_var` function with value `SECRET_ARN` + +.. code-block:: yaml + + files: + /tmp/secret.test: + content: | + client.id=sainsburys.applications.sc-ce.cdk-gateway + sasl.mechanism=PLAIN + sasl.jaas.config={{ from_resolve('{{resolve:secretsmanager:' + env_var('SECRET_ARN') + ':SecretString:SASL_JAAS_CONFIG}}') | safe }} + security.protocol=SASL_SSL + #EOF + + AWS Specific Filters ===================== diff --git a/ecs_files_composer/jinja2_filters/__init__.py b/ecs_files_composer/jinja2_filters/__init__.py index 6686a69..40b3309 100644 --- a/ecs_files_composer/jinja2_filters/__init__.py +++ b/ecs_files_composer/jinja2_filters/__init__.py @@ -11,6 +11,7 @@ import requests import yaml +from aws_cfn_custom_resource_resolve_parser import handle from boto3.session import Session from flatdict import FlatDict, FlatterDict @@ -210,12 +211,17 @@ def hostname(alternative_value: str = None) -> str: return alternative_value +def using_resolve(resolve_string: str) -> str: + return handle(resolve_string) + + JINJA_FUNCTIONS = { "ecs_container_metadata": ecs_container_metadata, "ecs_task_metadata": ecs_task_metadata, "env_var": env_var, "from_ssm": from_ssm, "from_ssm_json": from_ssm_json, + "from_resolve": using_resolve, "msk_bootstrap": msk_bootstrap, "hostname": hostname, }