Class: Stackup::ChangeSet
- Inherits:
-
Object
- Object
- Stackup::ChangeSet
- Includes:
- ErrorHandling
- Defined in:
- lib/stackup/change_set.rb
Overview
An abstraction of a CloudFormation change-set.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
-
#create(options = {}) ⇒ String
Create the change-set.
-
#delete ⇒ Object
Delete a change-set.
-
#describe ⇒ Object
Describe the change-set.
-
#execute ⇒ String
Execute the change-set.
-
#initialize(name, stack) ⇒ ChangeSet
constructor
A new instance of ChangeSet.
- #status ⇒ Object
Methods included from ErrorHandling
Constructor Details
#initialize(name, stack) ⇒ ChangeSet
Returns a new instance of ChangeSet.
9 10 11 12 |
# File 'lib/stackup/change_set.rb', line 9 def initialize(name, stack) @name = name @stack = stack end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/stackup/change_set.rb', line 14 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
15 16 17 |
# File 'lib/stackup/change_set.rb', line 15 def stack @stack end |
Instance Method Details
#create(options = {}) ⇒ String
Create the change-set.
Refer Aws::CloudFormation::Client#create_change_set
(see http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#create_change_set-instance_method)
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 80 81 82 83 |
# File 'lib/stackup/change_set.rb', line 53 def create( = {}) = .dup [:stack_name] = stack.name [:change_set_name] = name [:change_set_type] = stack.exists? ? "UPDATE" : "CREATE" force = .delete(:force) [:template_body] = MultiJson.dump(.delete(:template)) if [:template] # optionally override template_body with the original template to preserve formatting (& comments in YAML) template_orig = .delete(:template_orig) [:template_body] = template_orig if .delete(:preserve) [:parameters] = Parameters.new([:parameters]).to_a if [:parameters] [:tags] = ([:tags]) if [:tags] [:capabilities] ||= ["CAPABILITY_NAMED_IAM"] delete if force handling_cf_errors do cf_client.create_change_set() loop do current = describe logger.debug("change_set_status=#{current.status}") case current.status when /COMPLETE/ return current.status when "FAILED" logger.error(current.status_reason) raise StackUpdateError, "change-set creation failed" if status == "FAILED" end sleep(wait_poll_interval) end status end end |
#delete ⇒ Object
Delete a change-set.
102 103 104 105 106 107 |
# File 'lib/stackup/change_set.rb', line 102 def delete handling_cf_errors do cf_client.delete_change_set(:stack_name => stack.name, :change_set_name => name) end nil end |
#describe ⇒ Object
Describe the change-set.
Refer Aws::CloudFormation::Client#describe_change_set
(http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#describe_change_set-instance_method)
120 121 122 123 124 |
# File 'lib/stackup/change_set.rb', line 120 def describe handling_cf_errors do cf_client.describe_change_set(:stack_name => stack.name, :change_set_name => name) end end |
#execute ⇒ String
Execute the change-set.
92 93 94 95 96 |
# File 'lib/stackup/change_set.rb', line 92 def execute modify_stack(/(CREATE|UPDATE)_COMPLETE/, "update failed") do cf_client.execute_change_set(:stack_name => stack.name, :change_set_name => name) end end |
#status ⇒ Object
109 110 111 |
# File 'lib/stackup/change_set.rb', line 109 def status describe.status end |