by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Behrang
    @behrangsa

    Hi all,

    In order to keep cfndsl template files small:

    1- Can we declare helper methods? For example:

    def to_tag(key, val, propagate = false)
        tag = {
            Key: key,
            Val: val
        }
    
        if (propagate) {
            tag[:PropagateAtLaunch] = true
        }
    
        tag
    end

    This is a simple use case. Some other use cases require access to external_parameters too,
    for example when generating user data scripts:

    def user_data(details)
        return FnBase64(FnJoin('', [
            "#!/bin/bash -ex\n",
            "aws s3 cp #{details[:package_url]} /tmp/#{details[:package_filename]}",
            "..."
        ]))
    end

    2- Can we declare resources (and helper methods) outside the main CloudFormation block, in a separate file?

    For example, I want to have a file named sg.rb that contains my security groups:

    # sg.rb
    EC2_SecurityGroup(:MySecurityGroup) do
        GroupDescription '...'
        VpcId Ref(:VpcId)
        SecurityGroupIngress [
            // a few hundred lines of ingress rules
        ]
        SecurityGroupEngress [
            // a few hundred lines of egress rules
        ]
    end

    And then in my main CloudFormation, I want to use the security group in a way similar to this:

    # stack.rb
    AutoScaling_LaunchConfiguration(:LaunchConfiguration) do    
        SecurityGroups [ Ref(:MySecurityGroup) ]
    end

    or even:

    # sg.rb
    def mysg(vpcid)
        return EC2_SecurityGroup(:MySecurityGroup) do
            GroupDescription '...'
            VpcId Ref(vpcid)
            SecurityGroupIngress [
                // a few hundred lines of ingress rules
            ]
            SecurityGroupEngress [
                // a few hundred lines of egress rules
            ]
        end
    end
    
    # stack.rb
    AutoScaling_LaunchConfiguration(:LaunchConfiguration) do    
        SecurityGroups [ mysg(:VpcId) ]
    end
    • Does cfndsl allow us to do these at the moment? While cfndsl is significantly more readable and powerful than raw JSON/YAML templates, when stacks become large even cfndsl templates become difficult to maintain and comprehend.
    • Any plans to support these features?