monken / cfn-include

Preprocessor for CloudFormation templates with support for loops and flexible include statements
MIT License
86 stars 10 forks source link

Fn::Join in Fn::Sub #25

Closed rschick closed 7 years ago

rschick commented 7 years ago

I've been having problems with doing this style of include for UserData:

UserData:
  Fn::Base64:
    Fn::Sub:
      !Include { type: literal, location: userdata.sh }

It fails validation with:

An error occurred (ValidationError) when calling the ValidateTemplate operation: Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to specify a mapping of values to replace in the string

It looks like an issue with CF. The output looks fine:

        "UserData": {
          "Fn::Base64": {
            "Fn::Sub": {
              "Fn::Join": [
                "",
                [
                  "#!/bin/bash -xe\n",
                 ...
                ]
              ]
            }
          }
        }

I am currently working around this by including the userdata script as a string literal in my YAML:

      UserData:
        !Base64
          Fn::Sub: |
            #!/bin/bash -xe
            ...

But I'd like to be able to !Include it instead.

I was thinking of making a PR to add another type of include that wouldn't use the Fn::Join method, and instead just join the script with newlines into a single string. I'll put something together and let you know if it works.

Thanks for the great tool!

monken commented 7 years ago

Thank you very much for reporting and fixing this issue. I have made some changes:

Let me know what you think and I will cut a release of you are happy!

monken commented 7 years ago

released