{"id":18284471,"url":"https://github.com/pplu/cloudformation-dsl","last_synced_at":"2025-04-09T05:46:43.830Z","repository":{"id":66753256,"uuid":"170857681","full_name":"pplu/cloudformation-dsl","owner":"pplu","description":null,"archived":false,"fork":false,"pushed_at":"2020-04-27T09:40:18.000Z","size":186,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-15T00:25:49.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pplu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-02-15T11:54:13.000Z","updated_at":"2020-04-27T09:40:21.000Z","dependencies_parsed_at":"2023-02-22T19:15:20.014Z","dependency_job_id":null,"html_url":"https://github.com/pplu/cloudformation-dsl","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/pplu%2Fcloudformation-dsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fcloudformation-dsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fcloudformation-dsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fcloudformation-dsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pplu","download_url":"https://codeload.github.com/pplu/cloudformation-dsl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987107,"owners_count":21028891,"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":[],"created_at":"2024-11-05T13:13:39.935Z","updated_at":"2025-04-09T05:46:43.808Z","avatar_url":"https://github.com/pplu.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nCloudFormation::DSL - A Domain Specific Language for creating CloudFormation templates\n\n# SYNOPSIS\n\n    package MyStack {\n      use CloudFormation::DSL;\n\n      resource Instance1 =\u003e 'AWS::EC2::Instance', {\n        ImageId =\u003e 'ami-12345',\n      };\n\n      output IP =\u003e GetAtt('Instance1', 'PublicIp');\n    }\n\n    my $s1 = MyStack-\u003enew;\n    say \"Resource Count: \" . $s1-\u003eResourceCount;\n    print $s1-\u003eas_hashref;\n\n# DESCRIPTION\n\nCloudFormation is a great AWS service for automating infrastructure creation. You can get a better\ngrasp of what CloudFormation does and tries to solve here: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)\n\nCloudFormation::DSL is a \"framework\" for writing CloudFormation and addressing some of its shortcomings.\nIt lets you express CloudFormation templates in an easier fashion, with a more forgiving syntax \nthan the standard JSON or YAML syntaxes that CloudFormation supports. It also eases authoring some \ncomplex CloudFormation patterns.\n\nYou can think of it as a preprocessor that generates CloudFormation documents.\n\nCloudFormation::DSL builds on the idea that the information in a CloudFormation template can be\nexpressed as a class. After all, a class is a template for an object! Since we represent templates \nas classes, we can instance those classes, manipulate and query them. An instance of a class has\nan `as_json` method that once called generates the CloudFormation document that can be sent to\nthe CloudFormation service.\n\nCloudFormation::DSL builds upon existing layers:\n\n[Cfn](https://metacpan.org/pod/Cfn): Each `CloudDeploy::DSL` class is a Cfn subclass. This means that the object model that \nCfn provides is accessible from `CloudDeploy::DSL`.\n\n[Moose](https://metacpan.org/pod/Moose) and [Perl](https://metacpan.org/pod/Perl): `CloudDeploy::DSL` builds upon Moose's (An Object Orientation framework for Perl)\nand Perl's ability to add syntax to the language. This let's us declare keywords like `resource` \nor `paramter` so you can write your CloudFormation templates in a faster way. This is just an implementation\ndetail: you don't need to know Moose or Perl to use `CloudFormation::DSL`.\n\nCloudFormation::DSL brings you full object orientation to your CloudFormation template authoring: you\ncan create base classes, inherit, override and specialize.\n\nEnough chit-chat: let's see the action:\n\n# Writing a class\n\nStart a file named \\`MyCfn.pm\\`\n\n    package MyCfn {\n      use CloudFormation::DSL;\n    }\n    1;\n\nYou now have a class that represents a template without resources. Now we'll add stuff with\nthe following keywords:\n\n## resource Name =\u003e 'TYPE', { ... Properties ... };\n\n    package MyCfn {\n      use CloudFormation::DSL;\n\n      resource User1 =\u003e 'AWS::IAM::User', {\n        Path =\u003e \"/\",\n      };\n    }\n\nThe resource keyword declares a CloudFormation resource of type `TYPE`. The supported types\nare available in the `Cfn::Resource` namespace. This piece of code generates the following\nCloudFormation:\n\n    {\n      \"Resources\": {\n        \"User1\": {\n          \"Type\": \"AWS::IAM::User\",\n          \"Properties\": {\n            \"Path\": \"/\"\n          }\n        }\n      }\n    }\n\nNote a couple of things that the DSL is doing for us:\n\n`User1` doesn't have to be quoted. Perls \"fat comma\" automatically quotes it for us!\n\nYou could write:\n\n    resource 'User1' =\u003e 'AWS::IAM::User', { ... };\n\nif you wanted. You could also use double quotes:\n\n    resource \"User1\" =\u003e 'AWS::IAM::User', { ... };\n\nYou actually need to do this if the resource name has special characters. \n\nNote that we specify the properties just after the object in a Key / Value fashion.\nWe use Perls Hashrefs to represent these Key/Value structures. The Keys are the same\nkeys that we would use in the `\"Properties\"` object in a CloudFormation template. The\nvalues can be Perl strings `\"myvalue\"`, Perl numbers `42`, bareword booleans `true` \nor `false` and also CloudFormation functions like `{ Ref =` 'LogicalId' }\u003e and \n`{ 'Fn::GetAtt' =`  \\[ 'LogicalId', 'AttributeName' \\] }\u003e as Perl HashRefs. If you think \nthis is typing too much, please read the \"shortcuts\" section. You don't have to type\n`\"Properties\"`, and these go first, since 99% of the time we write resources, we\nwrite their properties.\n\nNote that in HashRefs we can leave trailing commas:\n\n    { Path =\u003e '/', }\n\nis valid, while in JSON\n\n    { \"Path\": \"/\", }\n\nisn't valid.\n\nThe DSL is also helping us assuring that AWS::IAM::User is a valid resource type. If we\ndon't use a supported resource type, we will get an error. This is also true for its\nproperties. The `AWS::IAM::User` object has a property called `Path`. If we had a\ntypo in the `Path` property, we would get an error. If we didn't define a required property\nwe get an error. If we used a wrong value: we get an error.\n\n## resource Name =\u003e 'TYPE', { ... Properties ... }, { ... Resource Attributes ... }\n\nIf we want to configure resource properties like `DependsOn` or `DeletionPolicy`\nwe can do so passing a fourth element to our `resource` statement:\n\n    resource \"User1\" =\u003e 'AWS::IAM::User', { ... }, { DeletionPolicy =\u003e 'Retain' };\n\nThe DSL will verify that the DeletionPolicy is a permitted value in CloudFormation.\n\n## output Name =\u003e ...;\n\nThis will declare an output in our CloudFormation template.\n\n    package MyCfn {\n      use CloudFormation::DSL;\n\n      resource User1 =\u003e 'AWS::IAM::User', {\n        Path =\u003e \"/\"\n      };\n\n      output IAMUser =\u003e Ref('User1');\n    }\n\nNote that the name of the output doesn't need to be quoted (just like in with the\n`resource` keyword. The value for an output is the same ones that CloudFormation supports.\nIn the example we're using a shortcut to specify a CloudFormation Ref function. We could\nhave wrote:\n\n    output IAMUser =\u003e { Ref =\u003e 'User1' };\n\nThe two are equivalent to the following CloudFormation JSON:\n\n    {\n      \"Outputs\": {\n        \"IAMUser\": {\n          \"Value\": { \"Ref\": \"User1\" }\n        }\n      }\n    }\n\n## output Name =\u003e ..., { ... Output properties ... };\n\nWe can also specify extra properties for the output `Description`,\n\n    output IAMUser =\u003e { Ref =\u003e 'User1' }, {\n      Description =\u003e 'The name of the IAM user',\n    };\n\nWill generate:\n\n    {\n      \"Outputs\": {\n        \"IAMUser\": {\n          \"Value\": { \"Ref\": \"User1\" },\n          \"Description\": \"The name of the IAM user\"\n        }\n      }\n    }\n\n## parameter Name =\u003e 'TYPE', { ... Properties ... }\n\nThe `parameter` keyword adds a CloudFormation parameter to the template.\n\n    parameter IAMPath =\u003e 'String',\n\nGenerates:\n\n    {\n      \"Parameters\": {\n        \"IAMPath\": {\n          \"Type\": \"String\"\n        }\n      }\n    }\n\n## parameter Name =\u003e 'TYPE', { ... Properties ... }\n\nWe can also specify parameter properties like `Default`,\n`NoEcho`, `MaxLength`, etc.\n\n    parameter IAMPath =\u003e 'String', {\n      Default =\u003e '/',\n      MazLength =\u003e 32,\n    };\n\nGenerates:\n\n    {\n      \"Parameters\": {\n        \"IAMPath\": {\n          \"Type\": \"String\",\n          \"Default\": \"/\",\n          \"MaxLength\": 32\n        }\n      }\n    }\n\n## condition Name =\u003e ...;\n\nAdds a condition to the template\n\n## mapping Name =\u003e { }\n\nAdds a CloudFormation mapping with a specific name\n\n## metadata\n\nAdds a metadata key to the template\n\n## transform\n\nAdds a transform to the template\n\n## stack\\_version\n\n# Shortcuts\n\n## Ref('LogicalId')\n\nis a shorthand way to write `{ Ref =` 'LogicalId' }\u003e\n\nIt writes `{\"Ref\":\"LogicalId\"}` in the CloudFormation template.\n\n## GetAtt('LogicalId', 'AttributeName')\n\nis a shorthand way to write\n\n## Parameter('ParameterName')\n\nis a shorthand way of referencing a parameter that doesn't get passed to CloudFormation. \n\n## Tag($key, $value)\n\nis a shorhand way of writing the values that most `Tag` attributes of resources expect:\n\n    Tag('Owner', 'me')\n\ngets converted to\n\n    { \"Key\": \"Owner\", \"Value\": \"me\" }\n\nin CloudFormation\n\nAn example of usage would be:\n\n    resource Subnet1 =\u003e 'AWS::EC2::Subnet', {\n      VpcId =\u003e Ref('Vpc'),\n      CidrBlock =\u003e '10.0.0.0/24',\n      Tags =\u003e [ Tag('Owner', 'me'), Tag('BU', 'sales') ],\n    };\n\n## Attribute('AttributeName')\n\nis a shorthand way of referencing an instance attribute. This is for advanced use. See\nthe \"Instance Attributes\" section.\n\n## UserData($string)\n\nis a shorthand way to import the contents of a file in \"UserData\" format:\n\n### TieFighters\n\nTiefighters are sequences of `#-#...#-#` that can be found inside the files\nthat the UserData keyword converts to the\n\n#### #-#LogicalId#-#\n\nInserts a Ref('LogicalId')\n\n#### #-#LogicalId-\u003eAttribute#-#\n\nInserts a GetAtt('LogicalId', 'Attribute') \n\n#### #-#Parameter(ParamName)#-#\n\nInserts a Parameter\n\n#### #-#Attribute(ParamName)#-#\n\nInserts an Attribute value\n\n## CfString($string)\n\nis a shorthand way to write a string that has gets tiefighters interpreted\n\n## Json($json\\_string)\n\nwill convert a JSON string into a HashRef\n\n# Networking shortcuts\n\n## ELBListener($lbport, $lbprotocol\\[, $instance\\_port\\[, $instance\\_protocol\\]\\])\n\nis a shorthand way of writing an ELB Listener. It can be used in many ways:\n\n`ELBListener(80, 'HTTP')` will forward traffic from port 80 of the ELB to port 80 on the backends\n\n`ELBListener(80, 'HTTP', 3000)` will forward traffic from port 80 of the ELB to port 3000 on the \nbackends\n\n`ELBListener(443, 'HTTPS', 5000, 'HTTP')` will do SSL offloading on the ELB, forwarding to port \n5000 HTTP on the backends\n\n## TCPELBListener($lbport\\[, $instance\\_port\\])\n\n## SGRule($port, $to, $desc)\n\n## SGRule($port, $to, $proto, $desc)\n\n## SGEgressRule\n\n# Getting the most out of the DSL\n\n# Inheritance\n\nYou can use inheritance primitives to structure your infrastructure into reusable modules\n\n    package MyBaseClass {\n      use CloudFormation::DSL;\n\n      resource I1 =\u003e 'AWS::EC2::Instance', {\n        ImageId =\u003e SpecifyInSubClass,\n        SecurityGroups =\u003e [ Ref('SG' ],\n      };\n      resource SG =\u003e 'AWS::EC2::SecurityGroup, {\n        ...\n      };\n    }\n    package SubClass1 {\n      use CloudFormation::DSL;\n      extends 'MyBaseClass';\n      resource I1 =\u003e 'AWS::IAM::User', {\n        ImageId =\u003e 'ami-XXXX',\n      };\n    }\n\n## SpecifyInSubClass\n\nUse `SpecifyInSubClass` to force the user to overwrite this value in a subclass:\n\n    package MyBase {\n      use CloudFormation::DSL;\n\n      resource User1 =\u003e 'AWS::IAM::User', {\n        Path =\u003e SpecifyInSubclass,\n      };\n    }\n\nIf MyBase is instanced, an error will be thrown. The value can be overwritten in \nsubclasses:\n\n    package MySubClass {\n      use CloudFormation::DSL;\n      extends 'MyBase';\n\n      resource '+User1' =\u003e 'AWS::IAM::User', {\n        Path =\u003e '/',\n      };\n    }\n\n# Attachments\n\n## attachment \n\nAdds an attachment to the template\n\n# Extending the DSL\n\n# Instance Attributes\n\n# SEE ALSO\n\n[Cfn](https://metacpan.org/pod/Cfn)\n\n[https://docs.aws.amazon.com/es\\_es/AWSCloudFormation/latest/UserGuide/Welcome.html](https://docs.aws.amazon.com/es_es/AWSCloudFormation/latest/UserGuide/Welcome.html)\n\n# AUTHOR\n\n    Jose Luis Martinez\n    CAPSiDE\n    jlmartinez@capside.com\n\n# Contributions\n\nThanks to Sergi Pruneda, Miquel Ruiz, Luis Alberto Gimenez, Eleatzar Colomer, Oriol Soriano, \nRoi Vazquez for years of work on this module.\n\n# BUGS and SOURCE\n\nThe source code is located here: [https://github.com/pplu/cloudformation-dsl](https://github.com/pplu/cloudformation-dsl)\n\nPlease report bugs to: [https://github.com/pplu/cfn-perl/cloudformation-dsl](https://github.com/pplu/cfn-perl/cloudformation-dsl)\n\n# COPYRIGHT and LICENSE\n\nCopyright (c) 2013 by CAPSiDE\nThis code is distributed under the Apache 2 License. The full text of the \nlicense can be found in the LICENSE file included with this module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpplu%2Fcloudformation-dsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpplu%2Fcloudformation-dsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpplu%2Fcloudformation-dsl/lists"}