unbounce / iidy

iidy (Is it done yet?) -- CloudFormation with Confidence
MIT License
52 stars 7 forks source link

`render` incompatible with CloudFormation dynamic references #260

Closed rymndhng closed 2 years ago

rymndhng commented 3 years ago

The iidy preprocessor fails when using CloudFormation dynamic references, such as {{resolve:ssm:..}}. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html

Template that reproduces this error:

AWSTemplateFormatVersion: 2010-09-09
Description: Lambda function code and related resources
Parameters:
  Environment:
   Type: String

Resources:
  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Environment:
        Variables:
          MY_VAR: !Sub "{{resolve:ssm:/${Environment}/foo}}"

Command used for testing:

❯ iidy render sample.yml
error Error in string template at Root.Resources.LambdaFunction.Properties.Environment.Variables.MY_VAR:
       Parse error on line 1:
{{resolve:ssm:/${Environment}/foo}}
---------------^
Expecting 'ID', got 'INVALID'
       Template: {{resolve:ssm:/${Environment}/foo}}
rymndhng commented 3 years ago

Oops, re-opening this issue. I mis-linked the PR 🤦

tavisrudd commented 2 years ago

The trick is to escape the handlebars braces with a double backslash:

AWSTemplateFormatVersion: 2010-09-09
Description: Lambda function code and related resources
Parameters:
  Environment:
   Type: String

Resources:
  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Environment:
        Variables:
          MY_VAR: !Sub "\\{{resolve:ssm:/${Environment}/foo}}"

I've added a note about this to the docs.