Module: CfnDsl::CloudFormation

Includes:
Functions
Defined in:
lib/cfndsl/cloudformation.rb

Overview

Syntactic Sugar for embedded ruby usage require ‘cfndsl`

class Builder

 include CfnDsl::CloudFormation

 def build_template()
    template = CloudFormation('ANewTemplate')
    a_param = template.Parameter('AParam')
    a_param.Type('String')
    return template
 end

 def map_instance_type(instance_type)
   # logic to auto convert instance types to latest available etc..
   FnFindInMap("InstanceTypeConversion",Ref('AWS::Region'),instance_type)
 end

 # templates can be passed around to other methods/classes
 def add_instance(template, instance_type)
   ec2 = template.EC2_Instance(:myInstance)
   ec2.InstanceType(map_instance_type(instance_type))
   # Alteratively with DSL block syntax
   this = self  # declare block is eval for the model instance so need to keep a reference
   template.declare do
     EC2_Instance(:myInstance) do
        InstanceType this.map_instance_type(instance_type)
     end
   end
end

def generate(template,pretty: false)
   valid = template.validate
   pretty ? valid.to_json : JSON.pretty_generate(valid)
end

end

Constant Summary

Constants included from Functions

Functions::FN_SUB_SCANNER

Instance Method Summary collapse

Methods included from Functions

#FnAnd, #FnBase64, #FnCidr, #FnEquals, #FnFindInMap, #FnGetAZs, #FnGetAtt, #FnIf, #FnImportValue, #FnJoin, #FnNot, #FnOr, #FnSelect, #FnSplit, #FnSub, #Ref

Instance Method Details

#CloudFormation(description = nil, &block) ⇒ Object



103
104
105
# File 'lib/cfndsl/cloudformation.rb', line 103

def CloudFormation(description = nil, &block)
  CloudFormationTemplate.new(description, &block)
end