lib/cfndsl/CloudFormationTemplate.rb in cfndsl-0.0.16 vs lib/cfndsl/CloudFormationTemplate.rb in cfndsl-0.1.0
- old
+ new
@@ -1,46 +1,48 @@
require 'cfndsl/JSONable'
require 'cfndsl/names'
-module CfnDsl
- class CloudFormationTemplate < JSONable
+module CfnDsl
+ class CloudFormationTemplate < JSONable
##
# Handles the overall template object
dsl_attr_setter :AWSTemplateFormatVersion, :Description
- dsl_content_object :Parameter, :Output, :Resource, :Mapping
-
+ dsl_content_object :Condition, :Parameter, :Output, :Resource, :Mapping
+
def initialize
@AWSTemplateFormatVersion = "2010-09-09"
end
-
- def generateOutput()
+
+ def generateOutput()
puts self.to_json # uncomment for pretty printing # {:space => ' ', :indent => ' ', :object_nl => "\n", :array_nl => "\n" }
end
- @@globalRefs = {
- "AWS::NotificationARNs" => 1,
+ @@globalRefs = {
+ "AWS::NotificationARNs" => 1,
"AWS::Region" => 1,
"AWS::StackId" => 1,
- "AWS::StackName" => 1
+ "AWS::StackName" => 1,
+ "AWS::AccountId" => 1,
+ "AWS::NoValue" => 1
}
def isValidRef( ref, origin=nil)
ref = ref.to_s
origin = origin.to_s if origin
return true if @@globalRefs.has_key?( ref )
return true if @Parameters && @Parameters.has_key?( ref )
-
+
if( @Resources.has_key?( ref ) ) then
- return !origin || !@_ResourceRefs || !@_ResourceRefs[ref] || !@_ResourceRefs[ref].has_key?(origin)
+ return !origin || !@_ResourceRefs || !@_ResourceRefs[ref] || !@_ResourceRefs[ref].has_key?(origin)
end
return false
end
- def checkRefs()
+ def checkRefs()
invalids = []
@_ResourceRefs = {}
if(@Resources) then
@Resources.keys.each do |resource|
@_ResourceRefs[resource.to_s] = @Resources[resource].references({})
@@ -60,14 +62,14 @@
outputRefs[origin].keys.each do |ref|
invalids.push "Invalid Reference: Output #{origin} refers to #{ref}" unless isValidRef(ref,nil)
end
end
end
- return invalids.length>0 ? invalids : nil
+ return invalids.length>0 ? invalids : nil
end
-
+
names = {}
nametypes = {}
CfnDsl::Types::AWS_Types["Resources"].each_pair do |name, type|
# Subclass ResourceDefintion and generate property methods
klass = Class.new(CfnDsl::ResourceDefinition)
@@ -75,15 +77,15 @@
CfnDsl::Types.const_set( klassname, klass )
type["Properties"].each_pair do |pname, ptype|
if( ptype.instance_of? String )
create_klass = CfnDsl::Types.const_get( ptype );
- klass.class_eval do
+ klass.class_eval do
CfnDsl::methodNames(pname) do |method|
define_method(method) do |*values, &block|
if( values.length <1 ) then
- values.push create_klass.new
+ values.push create_klass.new
end
@Properties ||= {}
@Properties[pname] ||= CfnDsl::PropertyDefinition.new( *values )
@Properties[pname].value.instance_eval &block if block
@Properties[pname].value
@@ -122,11 +124,11 @@
end
end
end
parts = name.split "::"
- while( parts.length > 0)
+ while( parts.length > 0)
abreve_name = parts.join "_"
if( names.has_key? abreve_name ) then
# this only happens if there is an ambiguity
names[abreve_name] = nil
else
@@ -136,10 +138,10 @@
parts.shift
end
end
-
+
#Define property setter methods for each of the unambiguous type names
names.each_pair do |typename,type|
if(type) then
class_eval do
CfnDsl::methodNames(typename) do |method|