jinja2aws-cloudformationsceptre

How can I reference a sceptre/cloudformation parameter in a jinja2 template


I have a parameter defined in my sceptre config file that I would like to reference in a Jinja2 conditional block.

config/codepipeline.yaml

template:
  path: 'codepipeline.yaml.j2'

parameters:
  Mode: 'OnDemand'

codepipeline.yaml.j2

Parameters:

  Mode:
    Type: 'String'
    Default: 'OnDemand'
    AllowedValues: ['OnDemand', 'OnPush']

   # What I want to do

   {% if $Mode == 'OnDemand' %}
   Triggers:
     more_stuff:
   {% else %}
   Triggers:
     other_stuff:
   {% endif %}

What is the proper way to reference the parameter value?


Solution

  • I spent hours hunting for a solution to this problem.

    This issue contained the solution. The list of parameters can be made available as a dictionary block within sceptre_user_data.

    config.yaml

    sceptre_user_data:
      stack_parameters: !stack_attr parameters
    

    codepipeline.yaml.j2

       {% if sceptre_user_data.stack_parameters.Mode == 'OnDemand' %}
       Triggers:
         more_stuff:
       {% else %}
       Triggers:
         other_stuff:
       {% endif %}
    

    One caveat... sceptre_user_data.stack_parameters.Mode will only contain the Parameter values defined in config files. The default value defined in the template will not populate into the dictionary in the Parameter is not provided in the configuration file.