Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Identify CloudFormation templates #281

Closed
iainelder opened this issue Feb 5, 2022 · 4 comments
Closed

Identify CloudFormation templates #281

iainelder opened this issue Feb 5, 2022 · 4 comments

Comments

@iainelder
Copy link

Would identify be able to tag CloudFormation templates with a cloudformation tag?

A CloudFormation template uses one of two syntaxes (YAML or JSON) and has no standard extension ("you can use any extension", according to the docs).

Although there is no extension, there are a couple of a magic strings. All CloudFormation files contain Resources as a top-level key. If that's too general, there's also AWSTemplateFormatVersion, although that's not strictly required (I'd consider it poor form to omit it, though.)

I ask for this because I lint my CloudFormation templates in pre-commit using cfn-lint.

I use cfn-lint to lint my CloudFormation templates. As my project grows and I change the organization of my CloudFormation templates, I need to keep the pre-commit configuration synchronized with the project structure to keep everything linted.

All my CloudFormation templates are written with YAML syntax. They are named *.yaml because there's no better extension to use.

I have other YAML files in my project (for example to configure pre-commit). So I can't just run the linter on all files tagged as yaml because it would correctly fail on non-CloudFormation files.

Early in the project I just chucked all the CloudFormation templates into a templates directory and use the files filter to run cfn-lint only on files in that folder.

So my pre-commit configuration looked like this (following Kenneth J Pronovici's example of using Poetry to control the linter version):

      - id: cfn-lint
        name: cfn-lint
        entry: poetry run cfn-lint
        files: ^templates/
        types: [yaml]
        language: system

As my project grows I move functionality into submodules each containing CloudFormation templates in different subfolders. The problem this causes is that the pre-commit configuration no longer passes all the CloudFormation templates to the linter.

I'm dealing with it by updating the pre-commit configuration each time I identify a new folder to store CloudFormation templates.

files: ^(templates/client|templates/server|iam-config|testing)/

I don't like having to maintain that list. It would be great to be able to just let the type tagging take care of it.

I see a similar issue affecting SaltStack files (#61). It seems that part of the problem is that identify is not designed to read the file contents to determine the file type. Does that mean this is a no-go?

@asottile
Copy link
Member

asottile commented Feb 5, 2022

A CloudFormation template uses one of two syntaxes (YAML or JSON) and has no standard extension ("you can use any extension", according to the docs).

nope, this is unfortunately why the official cfn-lint requires you to set your own files / etc. filtering: https://github.com/aws-cloudformation/cfn-lint/blob/1cb1d1b23c440463526f65295cfc5e22a47f8e54/.pre-commit-hooks.yaml#L5

@iainelder
Copy link
Author

Thanks for confirming.

I've proposed a standard file extension here: aws-cloudformation/cfn-language-discussion#45

@iainelder
Copy link
Author

Thanks @PatMyron for the links to help further the discussion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants