Class: CfnDsl::CloudFormationTemplate

Inherits:
JSONable
  • Object
show all
Defined in:
lib/cfndsl/CloudFormationTemplate.rb

Constant Summary collapse

@@globalRefs =
{
   "AWS::NotificationARNs" => 1,
   "AWS::Region" => 1,
   "AWS::StackId" => 1,
   "AWS::StackName" => 1,
   "AWS::AccountId" => 1,
   "AWS::NoValue" => 1
}

Instance Method Summary collapse

Methods inherited from JSONable

#declare, #method_missing, #ref_children, #to_json

Methods included from Functions

#FnAnd, #FnBase64, #FnEquals, #FnFindInMap, #FnFormat, #FnGetAZs, #FnGetAtt, #FnIf, #FnJoin, #FnNot, #FnOr, #FnSelect, #Ref

Methods included from RefCheck

#ref_children, #references

Constructor Details

#initializeCloudFormationTemplate

Returns a new instance of CloudFormationTemplate.



11
12
13
# File 'lib/cfndsl/CloudFormationTemplate.rb', line 11

def initialize
  @AWSTemplateFormatVersion = "2010-09-09"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CfnDsl::JSONable

Instance Method Details

#checkRefsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cfndsl/CloudFormationTemplate.rb', line 43

def checkRefs()
  invalids = []
  @_ResourceRefs = {}
  if(@Resources)  then
    @Resources.keys.each do |resource|
      @_ResourceRefs[resource.to_s] = @Resources[resource].references({})
    end
    @_ResourceRefs.keys.each do |origin|
      @_ResourceRefs[origin].keys.each do |ref|
        invalids.push "Invalid Reference: Resource #{origin} refers to #{ref}" unless isValidRef(ref,origin)
      end
    end
  end
  outputRefs = {}
  if(@Outputs) then
    @Outputs.keys.each do |resource|
      outputRefs[resource.to_s] = @Outputs[resource].references({})
    end
    outputRefs.keys.each do |origin|
      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
end

#generateOutputObject



15
16
17
# File 'lib/cfndsl/CloudFormationTemplate.rb', line 15

def generateOutput()
  puts self.to_json  # uncomment for pretty printing # {:space => ' ', :indent => '  ', :object_nl => "\n", :array_nl => "\n" }
end

#isValidRef(ref, origin = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cfndsl/CloudFormationTemplate.rb', line 28

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)
  end

  return false
end