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.
14 15 16 17 18 19 20 |
# File 'lib/rake/cloud_formation.rb', line 14 def initialize(*args) super @region = 'us-east-1' @parameters = {} @capabilities = [] @notification_arns = [] end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
32 33 34 |
# File 'lib/rake/cloud_formation.rb', line 32 def capabilities @capabilities end |
#notification_arns ⇒ Object (readonly)
Returns the value of attribute notification_arns.
32 33 34 |
# File 'lib/rake/cloud_formation.rb', line 32 def notification_arns @notification_arns end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
32 33 34 |
# File 'lib/rake/cloud_formation.rb', line 32 def parameters @parameters end |
#region ⇒ Object
Returns the value of attribute region.
31 32 33 |
# File 'lib/rake/cloud_formation.rb', line 31 def region @region end |
#template ⇒ Object
Returns the value of attribute template.
31 32 33 |
# File 'lib/rake/cloud_formation.rb', line 31 def template @template end |
Class Method Details
.define_task(args, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rake/cloud_formation.rb', line 22 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
46 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 |
# File 'lib/rake/cloud_formation.rb', line 46 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 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
38 39 40 41 42 43 44 |
# File 'lib/rake/cloud_formation.rb', line 38 def needed? begin cf(region).describe_stacks({stack_name: name}).stacks.first.stack_status != 'CREATE_COMPLETE' rescue true end end |
#prepare ⇒ Object
34 35 36 |
# File 'lib/rake/cloud_formation.rb', line 34 def prepare prerequisites << file(@template) end |