Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a way to run cfn-lint on Cloudformation templates that use Handlebars templating #456

Closed
otto-liljalaakso-nt opened this issue Oct 28, 2024 · 5 comments
Labels

Comments

@otto-liljalaakso-nt
Copy link

otto-liljalaakso-nt commented Oct 28, 2024

We use Takomo and have a couple of stacks where we need to use the Handlebars templating feature. We also want to check the CloudFormation templates using cfn-lint in a CI job. We have not been able to find a good way to run the linter for the stacks where the CloudFormation templates that need Handlebars. Currently, we have resorted to writing template files that validate as both CloudFormation and Handlebars templates, so we get the linting results for parts that do not have any Handlebars templating. However, such templates are very tricky to write, restrict how we can leverage Handlebars, and are not validated for the parts that are generated with Handlebars. Could you consider adding something to make it easier to support this use case?

Some ideas:

  1. A separate command like takomo templates validate [template-path], which processes the templates and runs cfn-lint on them
  2. Or, if the cfn-lint dependency created by that approach is too hard, something like takomo templates emit [template-path], which processes the templates and emits them, so that the user (or IDE plugin, or CI) can run cfn-lint on the result.
@otto-liljalaakso-nt otto-liljalaakso-nt changed the title Add a way to run cfn-lint on Cloudoformation templates that use templating Add a way to run cfn-lint on Cloudformation templates that use Handlebars templating Oct 28, 2024
@hmeltaus
Copy link
Contributor

Thanks for your request! The implementation isn't as easy as one might expect because the stack templates can contain elements that are resolved only at the time of deployment. For example, there can be a hooks that expose some data that is used with handlebars to dynamically build the final template. Another thing is that stacks usually depend on other stacks which means the final template contents can't be known before the dependencies have been deployed.

Due to these facts, emitting the templates could sometimes lead to unexpected results. Anyway, I agree feature would be very useful, and I will try to find a way to implement it.

@hmeltaus
Copy link
Contributor

The implementation is now done. Once integration tests are ready, we can release this feature

@otto-liljalaakso-nt
Copy link
Author

That was really quick, thank you! I tested the branch version and I can now do that I wanted to do via:

tkm --out-dir /tmp/ stacks emit /path/to/my/stack.yml
cfn-lint /tmp/path-to-my-stack-region

@hmeltaus
Copy link
Contributor

Thanks for testing this feature :) . I'll try to get the release out by the end of this week.

@hmeltaus
Copy link
Contributor

🎉 This issue has been resolved in version 7.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants