Class: Rake::CloudFormation::Stack

Inherits:
Task
  • Object
show all
Includes:
Rake::CloudFormation, DSL
Defined in:
lib/rake/cloud_formation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rake::CloudFormation

#access_key_id, #cf, #credential_file_hash, #secret_access_key

Constructor Details

#initialize(*args) ⇒ Stack

Returns a new instance of Stack.



14
15
16
17
18
19
# File 'lib/rake/cloud_formation.rb', line 14

def initialize(*args)
  super
  @region = 'us-east-1'
  @parameters = {}
  @capabilities = []
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



31
32
33
# File 'lib/rake/cloud_formation.rb', line 31

def capabilities
  @capabilities
end

#parametersObject (readonly)

Returns the value of attribute parameters.



31
32
33
# File 'lib/rake/cloud_formation.rb', line 31

def parameters
  @parameters
end

#regionObject

Returns the value of attribute region.



30
31
32
# File 'lib/rake/cloud_formation.rb', line 30

def region
  @region
end

#templateObject

Returns the value of attribute template.



30
31
32
# File 'lib/rake/cloud_formation.rb', line 30

def template
  @template
end

Class Method Details

.define_task(args, &block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/rake/cloud_formation.rb', line 21

def self.define_task(args, &block)
  t = super
  if (t.is_a?(Stack))
    yield t if block_given?
    t.prepare
  end
  t
end

Instance Method Details

#execute(*args) ⇒ Object



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

def execute(*args)
  super
  options = {}
  unless parameters.empty?
    options[:parameters] = parameters.inject({}) do |hash, (key, value)|
      if value.is_a?(String)
        hash[key] = value
      elsif value.is_a?(Proc)
        hash[key] = value.call
      else
        raise "Parameter value of unknown type: key=#{key.inspect} value=#{value.inspect}"
      end
      hash
    end
  end
  options[:capabilities] = capabilities unless capabilities.empty?
  puts "Creating CloudFormation stack: #{name}"
  cf(region).stacks.create(name, IO.read(template), options)
  while cf(region).stacks[name].status === 'CREATE_IN_PROGRESS'
    sleep 20
  end
  unless cf(region).stacks[name].status === 'CREATE_COMPLETE'
    raise "Stack creation failed"
  end
end

#needed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rake/cloud_formation.rb', line 37

def needed?
  !cf(region).stacks[name].exists? or cf(region).stacks[name].status != 'CREATE_COMPLETE'
end

#prepareObject



33
34
35
# File 'lib/rake/cloud_formation.rb', line 33

def prepare
  prerequisites << file(@template)
end