Class: OpenStax::Aws::ChangeSet
- Inherits:
-
Object
- Object
- OpenStax::Aws::ChangeSet
- Defined in:
- lib/openstax/aws/change_set.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #create(options:) ⇒ Object
- #created? ⇒ Boolean
- #delete ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
- #has_change_caused_by?(entity_name) ⇒ Boolean
- #id ⇒ Object
-
#initialize(client:) ⇒ ChangeSet
constructor
A new instance of ChangeSet.
- #parameter_value(parameter_name) ⇒ Object
- #resource_change_summaries ⇒ Object
Constructor Details
#initialize(client:) ⇒ ChangeSet
Returns a new instance of ChangeSet.
6 7 8 |
# File 'lib/openstax/aws/change_set.rb', line 6 def initialize(client:) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/openstax/aws/change_set.rb', line 4 def client @client end |
Instance Method Details
#create(options:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/openstax/aws/change_set.rb', line 10 def create(options:) create_change_set_output = client.create_change_set() @id = create_change_set_output.id = OpenStax::Aws::WaitMessage.new( message: "Waiting for change set #{id} to be ready" ) begin client.wait_until(:change_set_create_complete, change_set_name: id) do |w| w.delay = OpenStax::Aws.configuration.stack_waiter_delay w.before_attempt do |attempts, response| .say_it end end rescue Aws::Waiters::Errors::FailureStateError => ee if ee.response&.status_reason =~ /didn't contain changes/ logger.info("No changes detected, deleting change set") delete return self else logger.error(ee.response.status_reason) raise end rescue Aws::Waiters::Errors::WaiterFailed => ee logger.error("An error occurred: #{ee.}") raise end @description = client.describe_change_set(change_set_name: id) self end |
#created? ⇒ Boolean
44 45 46 |
# File 'lib/openstax/aws/change_set.rb', line 44 def created? @description.present? end |
#delete ⇒ Object
48 49 50 |
# File 'lib/openstax/aws/change_set.rb', line 48 def delete client.delete_change_set(change_set_name: id) end |
#description ⇒ Object
60 61 62 |
# File 'lib/openstax/aws/change_set.rb', line 60 def description @description || raise("Description not set; create failed?") end |
#execute ⇒ Object
52 53 54 |
# File 'lib/openstax/aws/change_set.rb', line 52 def execute client.execute_change_set(change_set_name: id) end |
#has_change_caused_by?(entity_name) ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'lib/openstax/aws/change_set.rb', line 64 def has_change_caused_by?(entity_name) description.changes.any? do |change| change.resource_change.details.any? do |detail| detail.causing_entity == entity_name end end end |
#id ⇒ Object
56 57 58 |
# File 'lib/openstax/aws/change_set.rb', line 56 def id @id || raise("ID isn't yet known!") end |
#parameter_value(parameter_name) ⇒ Object
72 73 74 75 76 |
# File 'lib/openstax/aws/change_set.rb', line 72 def parameter_value(parameter_name) description.parameters.select do |parameter| parameter.parameter_key == parameter_name end.first.parameter_value end |
#resource_change_summaries ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/openstax/aws/change_set.rb', line 78 def resource_change_summaries summaries = description.changes.flat_map(&:resource_change).map do |change| summary = "#{change.action} '#{change.logical_resource_id}' (#{change.resource_type})" case change.action when "Modify" causes = change.details.map{|detail| [detail.change_source, detail.causing_entity].compact.join(":")}.join(", ") summary = "#{summary}: Replacement=#{change.replacement}; Due to change in #{change.scope}; Causes: #{causes}" end summary end end |