Skip to content

Commit 5156412

Browse files
authored
Working from_resolve jinja2 function. Does not support cross account (#21)
1 parent 8597d7b commit 5156412

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/jinja2_functions_filters.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ Parameters:
3737
* ``fallback_value``: a value to use if case the property is missing.
3838

3939

40+
from_resolve
41+
--------------
42+
43+
Parameter: A string that looks like the {{resolve:}} string in AWS CloudFormation
44+
45+
For example, building the string below, we retrieve the key `SASL_JAAS_CONFIG` from the content of the secret, which we
46+
get the ARN from the `env_var` function with value `SECRET_ARN`
47+
48+
.. code-block:: yaml
49+
50+
files:
51+
/tmp/secret.test:
52+
content: |
53+
client.id=sainsburys.applications.sc-ce.cdk-gateway
54+
sasl.mechanism=PLAIN
55+
sasl.jaas.config={{ from_resolve('{{resolve:secretsmanager:' + env_var('SECRET_ARN') + ':SecretString:SASL_JAAS_CONFIG}}') | safe }}
56+
security.protocol=SASL_SSL
57+
#EOF
58+
59+
4060
4161
AWS Specific Filters
4262
=====================

ecs_files_composer/jinja2_filters/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import requests
1313
import yaml
14+
from aws_cfn_custom_resource_resolve_parser import handle
1415
from boto3.session import Session
1516
from flatdict import FlatDict, FlatterDict
1617

@@ -210,12 +211,17 @@ def hostname(alternative_value: str = None) -> str:
210211
return alternative_value
211212

212213

214+
def using_resolve(resolve_string: str) -> str:
215+
return handle(resolve_string)
216+
217+
213218
JINJA_FUNCTIONS = {
214219
"ecs_container_metadata": ecs_container_metadata,
215220
"ecs_task_metadata": ecs_task_metadata,
216221
"env_var": env_var,
217222
"from_ssm": from_ssm,
218223
"from_ssm_json": from_ssm_json,
224+
"from_resolve": using_resolve,
219225
"msk_bootstrap": msk_bootstrap,
220226
"hostname": hostname,
221227
}

0 commit comments

Comments
 (0)