{"id":18425434,"url":"https://github.com/toshke/cfhighlander-demo-inheritance","last_synced_at":"2025-04-13T17:58:54.627Z","repository":{"id":67599575,"uuid":"140157259","full_name":"toshke/cfhighlander-demo-inheritance","owner":"toshke","description":"Cfhighlander inheritance training / demo ","archived":false,"fork":false,"pushed_at":"2018-07-08T10:20:53.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T08:15:41.464Z","etag":null,"topics":["cfhighlander","cloudformation","cloudformation-templates","infrastructure-as-code","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toshke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-07-08T10:15:24.000Z","updated_at":"2018-07-08T10:39:11.000Z","dependencies_parsed_at":"2023-07-07T04:46:07.391Z","dependency_job_id":null,"html_url":"https://github.com/toshke/cfhighlander-demo-inheritance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toshke%2Fcfhighlander-demo-inheritance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toshke%2Fcfhighlander-demo-inheritance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toshke%2Fcfhighlander-demo-inheritance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toshke%2Fcfhighlander-demo-inheritance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toshke","download_url":"https://codeload.github.com/toshke/cfhighlander-demo-inheritance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758437,"owners_count":21156957,"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":["cfhighlander","cloudformation","cloudformation-templates","infrastructure-as-code","ruby"],"created_at":"2024-11-06T05:03:56.104Z","updated_at":"2025-04-13T17:58:54.602Z","avatar_url":"https://github.com/toshke.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Intro\n\nThis is training / demo repository for [cfhighlander](https://github.com/theonestack/cfhighlander)\ninheritance capabilities. Cfhighlander as infrastructure coding tool makes use of well known \ndevelopment patterns of object oriented programming, and tries to apply them to infrastructure\ncoding. Templates, as first class citizens in cfhighlander world, can inherit behaviour \nof other templates. \n\n## Try it yourself\n\n```\n## make sure to uninstall all previous versions if you have any, \n## so the proper code is returned from gem cache\n$ git clone https://github.com/toshke/cfhighlander \u0026\u0026 cd cfhighlander \u0026\u0026 git checkout feature/extend\n$ gem build cfhighlander.gemspec \u0026\u0026 gem install cfhighlander-*.gem \u0026\u0026 cd ..\n$ git clone https://github.com/toshke/cfhighlander-inheritance-demo\n$ cd cfhighlander-inheritance-demo\n$ cfhighlander cfcompile master\n```\n\n## Details\n \nEverything except for template name, version and description is being inherited from  parent\ntemplate by child template. Dsl Statement for inheritance is simple `Extends` , borrowed from\nJava. \n\n### Cfndsl templates\n\nCfndsl content of child template is appended to parent template. This way, child can shadow resources\ndefined in parent by giving them same name\n\n\n### Component configuration\n\nAny configuration key values defined by parent template can be overwritten in child template.\n\n### Highlander Statements\n\nHighlander statements (parameters, lambda functions, subcomponents) are all inherited from parent.\nIn-memory model effectively creates single instance of `CfhighlanderTemplate` object model, and applies \nall DSL statements (meaning both from parent and child templates) to this instance. \n \nFirst, parent DSL methods are applied\n \nSecondly, child DSL methods are applied. You can shadow parent definitions here, or extend capabilities\nby adding new definitions. \n\n## Example details\n\nThis repo defines 3-level hierarchy, where `master` extends `child` template, which further extends `parent`\ntemplate. `child` and `master` are defined within root directory, whereas `parent` has it's own directory. \n\n#### Example of shadowing highlander definition\n\n`child` template shadows parents definition of `parentParamToBeOverwritten` by chaging it's type from \n `String` to `AWS::EC2::Subnet::Id`.\n \n\n\n\n#### Example of extending highlander definitions\n\nIn example presented, \n\n`master`  defines `masterParameterShouldBeSiblingToParentAndChild`, \n\n`child` defines `childParamToBeUsed` and overwrites `parentParamToBeOverwritten` from `parent`, \n\n`parent` defines `parentParamToBeOverwritten` and `parentParamToBeUsed`\n\nResulting cloudformation contains all 4 stack parameters\n\n\ncontents of `out/yaml/master.compiled.yaml`\n```yaml\n parentParamToBeUsed:\n    Type: String\n    Default: ''\n    NoEcho: false\n  parentParamToBeOverwritten:\n    Type: AWS::EC2::Subnet::Id\n    Default: ''\n    NoEcho: false\n  childParamToBeUsed:\n    Type: String\n    Default: ''\n    NoEcho: false\n  masterParameterShouldBeSiblingToParentAndChild:\n    Type: String\n    Default: ''\n    NoEcho: false\n```\n\n\n\n#### Example of shadowing [cfndsl](https://github.com/cfndsl/cfndsl) resource definitions.\n\n`child` template redefines ec2 instance resource named `applicationInstance` with new Amazon Machine Image (AMI),\nand added instance type information coming from component configuration file. (This is just an example,\nalways place your instances in ASGs, even single instance, to achieve high availability in case of instance \nfailure).\n\nResulting cloudformation template uses definitions from `child` template:\n\n```yaml\n---\nAWSTemplateFormatVersion: '2010-09-09'\nResources:\n.....\n# defined in child template, shadowing parent template definition\n  applicationInstance:\n    Properties:\n      ImageId: ami-7105540e    \n      InstanceType: m5.medium\n      \n....\n```\n\n\n\n#### Example of extending [cfndsl](https://github.com/cfndsl/cfndsl) templates.\n\nEach highlander template in hierarchy defines one or more s3 buckets. If you look at \ncompiled cloudoformation template in `out/yaml/master.compiled.yaml`, there are following buckets\n\n```yaml\nAWSTemplateFormatVersion: '2010-09-09'\nResources:\n  parentDefinedBucket:\n    Type: AWS::S3::Bucket\n  iExistWithCondition2:\n    Type: AWS::S3::Bucket\n  childDefinedBucket:\n    Type: AWS::S3::Bucket\n  masterDefinedBucket:\n    Type: AWS::S3::Bucket\n```\n\n`parentDefinedBucket`, `childDefinedBucket` and `masterDefinedBucket` are all coming from different templates\nin hierarchy, but result in them being rendered within same CloudFormation template. \n\n\n\n#### Example of shadowing configuration settings\n\nParent template defines conditional buckets `iExistWithCondition` and `iExistWithCondition2`, dependant on \nconfiguration keys `conditinalbucket` (true in parent config) and `conditinalbucket2` (false in parent config).\n\nThis configuration values are changed in hierarchy, so:\n\n - Child templates disables `conditionalbucket`\n - Master template enables  `conditinalbucket2`\n \nResult - 2 levels up (or down) in hierarchy, AWS resource that will get rendered and created in parent, \nwon't exist in child, and vice versa. \n\n\n\n#### Example of extending configuration settings\n\n`child` template, extended by master, adds `child_key: child` configuration value.\nOnce component is compiled into resulting cloudformation template, intermediate configuration for master component\nin `out/config/master.config.yaml` includes this configuration key.\n\n\n```yaml\n---\n# defined in parent, overwritten in child\nparent_key: overwritten_in_child\n\n# defined in parent, and inherited in child and subsequently in master\nparent_standolone_key: this should not be overwritten\nconditionalbucket: false\nconditionalbucket2: true\ncomponent_version: latest\ncomponent_name: master\ntemplate_name: master\ntemplate_version: latest\n\n# child key, defined in child, and inherited by \nchild_key: child\napplication_instance_type: m5.medium\n\n# master template only defined configuration setting\nmaster_only: hello, world!\ndescription: master@latest - vlatest\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoshke%2Fcfhighlander-demo-inheritance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoshke%2Fcfhighlander-demo-inheritance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoshke%2Fcfhighlander-demo-inheritance/lists"}