using clean produces invalid template
rickalm opened this issue · 1 comments
rickalm commented
we are using new_template = to_yaml( to_json( orig_template ) )
to cleanup the yaml we are producing with jinja2
clean_up=False
we see
PublicSubnetIds:
Description: The public subnetids
Condition: HasPublicSubnet1AZ1
Value:
Fn::Join:
- ','
-
- Fn::If:
- HasPublicSubnet1AZ1
- !Ref PublicSubnet1AZ1
- !Ref AWS::NoValue
- Fn::If:
- HasPublicSubnet1AZ2
- !Ref PublicSubnet1AZ2
- !Ref AWS::NoValue
- Fn::If:
- HasPublicSubnet1AZ3
- !Ref PublicSubnet1AZ3
- !Ref AWS::NoValue
Export:
Name: !Sub vpc-${Environment}-PublicSubnetIds
but with clean_up=True
we get
PublicSubnetIds:
Description: The public subnetids
Condition: HasPublicSubnet1AZ1
Value: !Sub
- ${Param1},${Param2},${Param3}
- Param1: !If
- HasPublicSubnet1AZ1
- !Ref 'PublicSubnet1AZ1'
- !Ref 'AWS::NoValue'
Param2: !If
- HasPublicSubnet1AZ2
- !Ref 'PublicSubnet1AZ2'
- !Ref 'AWS::NoValue'
Param3: !If
- HasPublicSubnet1AZ3
- !Ref 'PublicSubnet1AZ3'
- !Ref 'AWS::NoValue'
Export:
Name: !Sub 'vpc-${Environment}-PublicSubnetIds'
Which CloudFormation complains about .. suggestions ??
stilvoid commented
Well, you've found one of the rare cases where a Join
is the correct choice over a Sub
. Unfortunately, cfn-flip doesn't (yet) have a way to detect this and so will make the opinionated decision that a Sub
is always preferable to a Join
.
It might be valid to fix this by checking if AWS::NoValue
is used anywhere in a Join
and then leave is as a Join
. I'll try this out later today.