Class: Formatron::AWS::CloudFormationStack
- Inherits:
-
Object
- Object
- Formatron::AWS::CloudFormationStack
- Defined in:
- lib/formatron/aws/cloud_formation_stack.rb
Overview
utilities for monitoring CloudFormation stack activities rubocop:disable Metrics/ClassLength
Constant Summary collapse
- CAPABILITIES =
%w(CAPABILITY_IAM)
- CREATE_COMPLETE_STATUS =
'CREATE_COMPLETE'
- CREATE_FINAL_STATUSES =
%W( #{CREATE_COMPLETE_STATUS} CREATE_FAILED ROLLBACK_COMPLETE ROLLBACK_FAILED )
- UPDATE_COMPLETE_STATUS =
'UPDATE_COMPLETE'
- UPDATE_FINAL_STATUSES =
%W( #{UPDATE_COMPLETE_STATUS} UPDATE_ROLLBACK_COMPLETE UPDATE_ROLLBACK_FAILED )
- DELETE_COMPLETE_STATUS =
'DELETE_COMPLETE'
- DELETE_FINAL_STATUSES =
%W( #{DELETE_COMPLETE_STATUS} DELETE_FAILED )
Instance Method Summary collapse
- #create(template_url:, parameters:) ⇒ Object
-
#delete ⇒ Object
rubocop:enable Metrics/MethodLength.
- #exists? ⇒ Boolean
-
#initialize(stack_name:, client:) ⇒ CloudFormationStack
constructor
A new instance of CloudFormationStack.
- #update(template_url:, parameters:) ⇒ Object
Constructor Details
#initialize(stack_name:, client:) ⇒ CloudFormationStack
Returns a new instance of CloudFormationStack.
31 32 33 34 35 36 37 38 |
# File 'lib/formatron/aws/cloud_formation_stack.rb', line 31 def initialize(stack_name:, client:) @stack_name = stack_name @client = client @stack = Aws::CloudFormation::Stack.new( stack_name, client: @client ) end |
Instance Method Details
#create(template_url:, parameters:) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/formatron/aws/cloud_formation_stack.rb', line 44 def create(template_url:, parameters:) @client.create_stack( stack_name: @stack_name, template_url: template_url, capabilities: CAPABILITIES, on_failure: 'DO_NOTHING', parameters: parameters ) @stack.wait_until_exists status = _wait_for_status statuses: CREATE_FINAL_STATUSES fail status unless status.eql? CREATE_COMPLETE_STATUS end |
#delete ⇒ Object
rubocop:enable Metrics/MethodLength
89 90 91 92 93 94 95 96 97 |
# File 'lib/formatron/aws/cloud_formation_stack.rb', line 89 def delete last_event_id = _last_event_id @stack.delete status = _wait_for_status( statuses: DELETE_FINAL_STATUSES, last_event_id: last_event_id ) fail status unless status.eql? DELETE_COMPLETE_STATUS end |
#exists? ⇒ Boolean
40 41 42 |
# File 'lib/formatron/aws/cloud_formation_stack.rb', line 40 def exists? @stack.exists? end |
#update(template_url:, parameters:) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/formatron/aws/cloud_formation_stack.rb', line 57 def update(template_url:, parameters:) last_event_id = _last_event_id return unless _update_unless_no_changes( template_url: template_url, parameters: parameters ) status = _wait_for_status( statuses: UPDATE_FINAL_STATUSES, last_event_id: last_event_id ) fail status unless status.eql? UPDATE_COMPLETE_STATUS end |