Class: CfDeployer::Driver::CloudFormation
- Inherits:
-
Object
- Object
- CfDeployer::Driver::CloudFormation
- Defined in:
- lib/cf_deployer/driver/cloud_formation_driver.rb
Instance Method Summary collapse
- #create_stack(template, opts) ⇒ Object
- #delete_stack ⇒ Object
-
#initialize(stack_name) ⇒ CloudFormation
constructor
A new instance of CloudFormation.
- #outputs ⇒ Object
- #parameters ⇒ Object
- #query_output(key) ⇒ Object
- #resource_statuses ⇒ Object
- #stack_exists? ⇒ Boolean
- #stack_status ⇒ Object
- #template ⇒ Object
- #update_stack(template, opts) ⇒ Object
Constructor Details
#initialize(stack_name) ⇒ CloudFormation
Returns a new instance of CloudFormation.
5 6 7 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 5 def initialize stack_name @stack_name = stack_name end |
Instance Method Details
#create_stack(template, opts) ⇒ Object
13 14 15 16 17 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 13 def create_stack template, opts CfDeployer::Driver::DryRun.guard "Skipping create_stack" do cloud_formation.stacks.create @stack_name, template, opts end end |
#delete_stack ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 53 def delete_stack if stack_exists? CfDeployer::Driver::DryRun.guard "Skipping create_stack" do aws_stack.delete end else Log.info "Stack #{@stack_name} does not exist!" end end |
#outputs ⇒ Object
37 38 39 40 41 42 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 37 def outputs aws_stack.outputs.inject({}) do |memo, o| memo[o.key] = o.value memo end end |
#parameters ⇒ Object
44 45 46 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 44 def parameters aws_stack.parameters end |
#query_output(key) ⇒ Object
48 49 50 51 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 48 def query_output key output = aws_stack.outputs.find { |o| o.key == key } output && output.value end |
#resource_statuses ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 63 def resource_statuses resources = {} aws_stack.resource_summaries.each do |rs| resources[rs[:resource_type]] ||= {} resources[rs[:resource_type]][rs[:physical_resource_id]] = rs[:resource_status] end resources end |
#stack_exists? ⇒ Boolean
9 10 11 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 9 def stack_exists? aws_stack.exists? end |
#stack_status ⇒ Object
33 34 35 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 33 def stack_status aws_stack.status.downcase.to_sym end |
#template ⇒ Object
72 73 74 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 72 def template aws_stack.template end |
#update_stack(template, opts) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cf_deployer/driver/cloud_formation_driver.rb', line 19 def update_stack template, opts begin CfDeployer::Driver::DryRun.guard "Skipping update_stack" do aws_stack.update opts.merge(:template => template) end rescue AWS::CloudFormation::Errors::ValidationError => e if e. =~ /No updates are to be performed/ Log.info e. else raise end end end |