Reputation: 529
I have Cloudformation template in yaml format. The template is rendered by Ansible Jinja2.
I need to find a way to add validation of some elements inside the template. Something like this ("if" statement is a pseudo code of what I want to get):
Parameters:
EnvironmentType:
Default: {{profile}}
Mappings:
Environments:
dev:
DbSnapshotArn: ""
test:
DbSnapshotArn: "AAA"
Type: AWS::RDS::DBInstance
Properties:
{% if Mappings.Environments.{{profile}}.DbInstanceClass %}
DBSnapshotIdentifier: !FindInMap [Environments, !Ref 'EnvironmentType', DbSnapshotArn]
{% endif %}
Is it possible?
Upvotes: 0
Views: 708
Reputation: 47913
Not if Mappings.Environments.{{profile}}.DbInstanceClass
references something inside the template.
But if you define a variable like this:
Mappings:
Environments:
Dev:
DbInstanceClass: "..."
And another variable that contains the value of profile
, then inside your template you can create an if
statement like this:
{% if Mappings.Environments[profile].DbInstanceClass is defined %}
...
{% endif %}
See also:
Upvotes: 1