Open zaro0508 opened 3 years ago
what happen with these expressions is that they do not resolve before getting added to the templating context, but they are copied over as expressions.
MyAccount: {{ MasterAccount }} will resolve to MyAccount: [object object]
MyAccount: {{ MasterAccount | object }} will resolve to to MyAccount: {Ref: MasterAccount}
there is a number of examples here.
the reason for this is that some expressions (e.g. CurrentAccount) cannot be resolved at "templating time", they need to be resolved at deployment time and might have a different value for each target.
Parameters do get evaluated before passed to the templating context. What you might be able to do to is have the expression evaluate early when assigned to a parameter, then pass the parameter to the templating context.
maybe a solution would be to add an Eval function? eagerly eval most expressions? but I would be interested to understand the usecase better before adding such function
The use case for me is when I want to pass TemplatingContext
variables to nunjuks templates and I want to use any of the !Ref, !Sub, !CopyValue, etc.. on those variables.
Examples:
Mappings:
TgwSpokesA:
VpcName:
'111111111111': 'dustbunnyvpc'
'222222222222': 'sandcastlevpc'
TestStack:
Type: update-stacks
Template: test.yaml
StackName: test
TemplatingContext:
MasterAccount: !Ref MasterAccount
VpcId: !CopyValue [!Sub '${resourcePrefix}-tgw-${vpnVpc}-VpcId']
SubnetIds:
- !CopyValue [!Join ["-", [!Ref primaryRegion, !FindInMap [TgwSpokesA, VpcName, !Ref CurrentAccount], 'PrivateSubnet']]]
- !CopyValue [!Join ["-", [!Ref primaryRegion, !FindInMap [TgwSpokesA, VpcName, !Ref CurrentAccount], 'PrivateSubnet1']]]
I think the following issue might be related to this one mainly because
OFN function references (!Ref, !Sub, !CopyValue, etc..) do no work with TemplatingContext parameters. References always resolve to object Object
Subject of the issue
OFN function references (!Ref, !Sub, !CopyValue, etc..) do no work with TemplatingContext parameters. References always resolve to
object Object
Your environment
0.9.17-beta.3
Steps to reproduce
noop.njk:
_tasks.yaml:
run
ofn print-tasks _tasks.yaml --output yaml
my out put in
.printed-stacks/noop/us-east-1-master-account.yaml
:Expected behaviour
The resource ID/name should be set to the master account ID, something like this..
Actual behaviour
The resource ID/name is set to
object Object
. Anywhere a reference (!Ref, !Sub, !CopyValue, etc..) is used it resolves toobject Object
.