Class: CfnDsl::OrchestrationTemplate

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

Direct Known Subclasses

CloudFormationTemplate, HeatTemplate

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, #incorrect_capitalization?, #method_missing, #ref_children, #titleize, #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

#initializeOrchestrationTemplate

Returns a new instance of OrchestrationTemplate.



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



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

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

#isValidRef(ref, origin = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cfndsl/CloudFormationTemplate.rb', line 24

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