{"id":18524450,"url":"https://github.com/stelligent/cfn-model","last_synced_at":"2025-07-12T19:32:19.920Z","repository":{"id":22649866,"uuid":"94480201","full_name":"stelligent/cfn-model","owner":"stelligent","description":"An object model for CloudFormation templates","archived":false,"fork":false,"pushed_at":"2024-03-25T19:38:34.000Z","size":340,"stargazers_count":6,"open_issues_count":4,"forks_count":13,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-24T13:16:25.051Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stelligent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-15T21:27:44.000Z","updated_at":"2024-06-18T22:58:21.175Z","dependencies_parsed_at":"2024-06-18T22:58:15.565Z","dependency_job_id":"3666aa5c-62b2-4edc-93b8-dc10757f4901","html_url":"https://github.com/stelligent/cfn-model","commit_stats":{"total_commits":176,"total_committers":15,"mean_commits":"11.733333333333333","dds":0.6022727272727273,"last_synced_commit":"0232e6680c62a32542f66e6055bfbde3040921fc"},"previous_names":[],"tags_count":95,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fcfn-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fcfn-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fcfn-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stelligent%2Fcfn-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stelligent","download_url":"https://codeload.github.com/stelligent/cfn-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248031651,"owners_count":21036447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-11-06T17:41:46.666Z","updated_at":"2025-04-09T11:32:04.525Z","avatar_url":"https://github.com/stelligent.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![cfn_model](https://github.com/stelligent/cfn-model/workflows/cfn_model/badge.svg)](https://github.com/stelligent/cfn-model/actions?query=workflow%3Acfn_model) [![VS Code DockerHub Build \u0026 Push](https://github.com/stelligent/cfn-model/workflows/VS%20Code%20DockerHub%20Build%20\u0026%20Push/badge.svg)](https://github.com/stelligent/cfn-model/actions?query=workflow%3A%22VS+Code+DockerHub+Build+%26+Push%22)\n\n# Overview\n\nThe cfn-model gem attempts to provide an object model to simplify doing rudimentary static analysis on CloudFormation \ntemplates.\n\nIt is \"easy\" to parse a CloudFormation template, because all (valid) templates are YAML (including the JSON templates).\nOn the other hand, there are a good number of situations where values can be lists or maps, or fields can be optional.\nIt is painful to account for some of these variations when developing static analysis code/rules.  The cyclomatic\ncomplexity can increase and the logic can be error prone and repetitive.\n\ncfn-model attempts to insulate rule developers from having to worry about some of the uninteresting nitty-gritty of the\nstructure of a CloudFormation template.  A few examples:\n \n* In the case where a value can be a Hash or an Array, an Array (of the Hash) is always returned so that a rule developer can use simple enumerators and reduce cyclomatic complexity in the rule.\n* Properties field/values are mapped to be instance variables of the resource objects - no worrying about a missing Properties\n* The basic required structure of the CloudFormation template is validated so a rule developer can presume required fields are present (i.e. it will fail before handing out a broken object model)\n\nThe cfn-model should *not* be considered a full-fledged parser for CloudFormation templates.  It tries to parse\nonly enough to enable rule developers to have an easier time.  If there are items in a template that the parser\ndoesn't recognize, the typical behavior is to ignore it.\n\nSome of this code comes from the internals of cfn-nag but more importantly the inspiration for this approach comes \nfrom difficulties in writing cfn-nag rules.\n\n# Usage\n\nThe primary interface point for this gem is the `CfnParser` which can generate a `CfnModel` object\nupon which static analysis can be conducted.\n\nThe `CfnModel` is a container for other object that have been parsed, wrapped and potentially linked to\nother wrapped objects.\n\nThe raw Hash output of `YAML.safe_load` is also available from `CfnModel`.\n\n    require 'cfn-model'\n        \n    cfn_model = CfnParser.parse IO.read('some_cloudformation_template.yml')\n    \n    cfn_model.resources_by_type('AWS::IAM::User').each do |iam_user|\n       # interrogate the iam_user\n    end\n\n## With Line Number Tracking\n\n    require 'cfn-model'\n\n    cfn_model = CfnParser.parse IO.read('some_cloudformation_template.yml'), nil, true\n\n    cfn_model.resources_by_type('AWS::IAM::User').each do |iam_user|\n       # interrogate the iam_user\n    ende\n\n## Built-in Model Elements\n    \n## Unanticipated Model Elements\n\nFor any resource type that cfn-model doesn't recognize, it will still add an object with the Properties fields flattened\ndown as instance variables on the generated object.  Given it's not recognized, there won't be any special parsing, wrapping\nor linking of the object.\n\nFor example, parsing the CloudFormation template:\n\n      ---\n      Resources:\n        newResource:\n          Type: \"AWS::TimeTravel::Machine\"\n          Properties:\n            Fuel: dilithium\n\nwould yield an object: \n\n      time_travel_machine = cfn_model.resources_by_type('AWS::TimeTravel::Machine').first\n      expect(time_travel_machine.fuel).to eq 'dilithium'\n      \n# Development\n\n## Specs\n\nTo run the specs, you need to ensure you have Docker installed and cfn-model dependencies installed via\n```\ngem install bundle\nbundle install\n```\n\nThen, to run all of the specs, just run `rake spec`.\n\n## VS Code Remote Development\nThere is a complete remote development environment created and setup with all the tools and settings pre-configured for ease in rule development and creation. You can enable this by using the VS Code Remote development functionality.\n\n- Install the VS Code [Remote Development extension pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)\n- Open the repo in VS Code\n- When prompted \"`Folder contains a dev container configuration file. Reopen folder to develop in a container`\" click the \"`Reopen in Container`\" button\n- When opening in the future use the \"`[Dev Container] cfn_nag Development`\" option\n\nMore information about the VS Code Remote Development setup can be found here, [VS Code Remote Development](vscode_remote_development.md).\n\n# Support\n\nTo report a bug or request a feature, submit an issue through the GitHub repository via: \u003chttps://github.com/stelligent/cfn-model/issues/new\u003e\n\n# Deeper Dive\n\n## Parsing\n\n## Validation\n\n## Adding a Model Element type    \n\n## Unanticipated Resource Types\n\n# Open issues\n\n* Need to ponder a more general treatment for Refs \n* Interesting to ponder doing analysis against a template combined with externally supplied Parameter values\n* Required attributes keep becoming optional... need to find way to bring validation in line with authoritative rules\n* Need to ponder best way to redesign to deal with macros and such\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstelligent%2Fcfn-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstelligent%2Fcfn-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstelligent%2Fcfn-model/lists"}