Sceptre / sceptre

Build better AWS infrastructure
https://docs.sceptre-project.org
Other
1.48k stars 313 forks source link

Fix Docs rst tags {% raw %} and {% endraw %} #785

Closed dalibor-aleksic-atomia closed 5 years ago

dalibor-aleksic-atomia commented 5 years ago

I'm struggling with templating.

Based on documentation here, I can set something like this in config.yaml file

project_code: {% raw %}{{ var.my_project_name }}{% endraw %}
region: eu-west-1

and use it like sceptre --var "my_project_name=test-project" generate dev/vpc.yaml, but I get an error

  File "/home/impress/.local/lib/python2.7/site-packages/yaml/constructor.py", line 138, in construct_mapping
    "found unacceptable key (%s)" % exc, key_node.start_mark)
yaml.constructor.ConstructorError: while constructing a mapping
  in "<unicode string>", line 1, column 15:
    project_code: {{ var.my_project_name }}
                  ^
found unacceptable key (unhashable type: 'dict')
  in "<unicode string>", line 1, column 16:
    project_code: {{ var.my_project_name }}

Also this doesn't work in stack yaml files (ex. config/dev/vpc.yaml) . It works only if I use it like

project_code: {{ var.my_project_name }}
region: eu-west-1

Example from documentation (using {% raw %} at beginning) doesn't work either

{% raw %}
profile: {{ var.profile }}
project_code: {{ var.project_code | default("prj") }}
region: {{ command_path.2 }}
template_bucket_name: {{ environment_variable.TEMPLATE_BUCKET_NAME }}
{% endraw %}

I want to achieve project_code: {{ var.project_name }}_something_{ var.another_variable}, but based on documentation and this error I'm not finding a way.


Used example:

parameters: TagExample: ThisIsTagExample

- `templates/vpc.template.yaml` content

AWSTemplateFormatVersion: "2010-09-09"

Description: >- Demo CloudFormation Template

Parameters: TagExample: Type: String

Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.10.0.0/16 EnableDnsHostnames: true EnableDnsSupport: true Tags:

Sceptre version: 2.1.5 Python: 2.7.15+

cornerman commented 5 years ago

Based on documentation here, I can set something like this in config.yaml file

project_code: {% raw %}{{ var.my_project_name }}{% endraw %}

Oh, I think the {% raw %} and {% endraw %} strings might be a formatting error in the documentation. You can safely ignore them and leave them out.

For concatenating two vars, you can do:

project_code: {{ var.project_name }}_something_{{ var.another_variable }}
ngfgrant commented 5 years ago

Hi @dalibor-aleksic-atomia

Can you try without the {% raw %} and {% endraw %} it looks like a rst added those when building the docs

dalibor-aleksic-atomia commented 5 years ago

It works :)


ngfgrant commented 5 years ago

I've updated the issue title and will see if anyone can get can this fixed shortly