Class: Rake::CloudFormation::Stack
- Inherits:
-
Task
- Object
- Task
- Rake::CloudFormation::Stack
- Includes:
- Rake::CloudFormation, DSL
- Defined in:
- lib/rake/cloud_formation.rb
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#notification_arns ⇒ Object
readonly
Returns the value of attribute notification_arns.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#region ⇒ Object
Returns the value of attribute region.
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(*args) ⇒ Object
-
#initialize(*args) ⇒ Stack
constructor
A new instance of Stack.
- #needed? ⇒ Boolean
- #prepare ⇒ Object
Methods included from Rake::CloudFormation
Constructor Details
#initialize(*args) ⇒ Stack
Returns a new instance of Stack.
15 16 17 18 19 20 21 |
# File 'lib/rake/cloud_formation.rb', line 15 def initialize(*args) super @region = 'us-east-1' @parameters = {} @capabilities = Set.new @notification_arns = Set.new end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
33 34 35 |
# File 'lib/rake/cloud_formation.rb', line 33 def capabilities @capabilities end |
#notification_arns ⇒ Object (readonly)
Returns the value of attribute notification_arns.
33 34 35 |
# File 'lib/rake/cloud_formation.rb', line 33 def notification_arns @notification_arns end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
33 34 35 |
# File 'lib/rake/cloud_formation.rb', line 33 def parameters @parameters end |
#region ⇒ Object
Returns the value of attribute region.
32 33 34 |
# File 'lib/rake/cloud_formation.rb', line 32 def region @region end |
#template ⇒ Object
Returns the value of attribute template.
32 33 34 |
# File 'lib/rake/cloud_formation.rb', line 32 def template @template end |
Class Method Details
.define_task(args, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/rake/cloud_formation.rb', line 23 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rake/cloud_formation.rb', line 47 def execute(*args) super = { stack_name: name, template_body: IO.read(template), } unless parameters.empty? [:parameters] = parameters.inject([]) do |params, (key, value)| param = { :parameter_key => key } if value.is_a?(String) param[:parameter_value] = value elsif value.is_a?(Proc) param[:parameter_value] = value.call else raise "Parameter value of unknown type: key=#{key.inspect} value=#{value.inspect}" end params << param params end end [:capabilities] = capabilities.to_a unless capabilities.empty? [:notification_arns] = notification_arns.to_a unless notification_arns.empty? puts "Creating CloudFormation stack: #{name}" cf(region).create_stack() while cf(region).describe_stacks({stack_name: name}).stacks.first.stack_status === 'CREATE_IN_PROGRESS' sleep 20 end unless cf(region).describe_stacks({stack_name: name}).stacks.first.stack_status === 'CREATE_COMPLETE' raise "Stack creation failed" end end |
#needed? ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'lib/rake/cloud_formation.rb', line 39 def needed? begin cf(region).describe_stacks({stack_name: name}).stacks.first.stack_status != 'CREATE_COMPLETE' rescue true end end |
#prepare ⇒ Object
35 36 37 |
# File 'lib/rake/cloud_formation.rb', line 35 def prepare prerequisites << file(@template) end |