Class: Bora::Stack
- Inherits:
-
Object
- Object
- Bora::Stack
- Defined in:
- lib/bora/stack.rb
Constant Summary collapse
- STACK_ACTION_SUCCESS_MESSAGE =
"%s stack '%s' completed successfully".freeze
- STACK_ACTION_FAILURE_MESSAGE =
"%s stack '%s' failed".freeze
- STACK_ACTION_NOT_CHANGED_MESSAGE =
"%s stack '%s' skipped as template has not changed".freeze
- STACK_DOES_NOT_EXIST_MESSAGE =
"Stack '%s' does not exist".freeze
- STACK_EVENTS_DO_NOT_EXIST_MESSAGE =
"Stack '%s' has no events".freeze
- STACK_EVENTS_MESSAGE =
"Events for stack '%s'".freeze
- STACK_OUTPUTS_DO_NOT_EXIST_MESSAGE =
"Stack '%s' has no outputs".freeze
- STACK_PARAMETERS_DO_NOT_EXIST_MESSAGE =
"Stack '%s' has no parameters".freeze
- STACK_VALIDATE_SUCCESS_MESSAGE =
"Template for stack '%s' is valid".freeze
- STACK_DIFF_TEMPLATE_UNCHANGED_MESSAGE =
'Template has not changed'.freeze
- STACK_DIFF_PARAMETERS_UNCHANGED_MESSAGE =
'Parameters have not changed'.freeze
- STACK_DIFF_NO_CHANGES_MESSAGE =
'No changes will be applied'.freeze
Instance Attribute Summary collapse
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#stack_config ⇒ Object
readonly
Returns the value of attribute stack_config.
-
#stack_name ⇒ Object
readonly
Returns the value of attribute stack_name.
-
#template_file ⇒ Object
readonly
Returns the value of attribute template_file.
Instance Method Summary collapse
- #apply(override_params = {}, pretty_json = false) ⇒ Object
- #create_change_set(change_set_name, description = nil, override_params = {}, pretty_json = false) ⇒ Object
- #delete ⇒ Object
- #delete_change_set(change_set_name) ⇒ Object
- #describe_change_set(change_set_name) ⇒ Object
- #diff(override_params = {}, context_lines = 3) ⇒ Object
- #events ⇒ Object
- #execute_change_set(change_set_name) ⇒ Object
-
#initialize(stack_name, template_file, stack_config) ⇒ Stack
constructor
A new instance of Stack.
- #list_change_sets ⇒ Object
- #outputs ⇒ Object
- #parameters ⇒ Object
- #rake_tasks ⇒ Object
- #recreate(override_params = {}) ⇒ Object
- #resolved_params(override_params = {}) ⇒ Object
- #show(override_params = {}) ⇒ Object
- #show_current ⇒ Object
- #status ⇒ Object
- #validate(override_params = {}) ⇒ Object
Constructor Details
#initialize(stack_name, template_file, stack_config) ⇒ Stack
Returns a new instance of Stack.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bora/stack.rb', line 25 def initialize(stack_name, template_file, stack_config) @stack_name = stack_name @cfn_stack_name = stack_config['cfn_stack_name'] || stack_config['stack_name'] || @stack_name if stack_config['stack_name'] puts "DEPRECATED: The 'stack_name' setting is deprecated. Please use 'cfn_stack_name' instead." end @template_file = template_file @stack_config = stack_config @region = @stack_config['default_region'] || Aws::CloudFormation::Client.new.config[:region] @cfn_stack = Cfn::Stack.new(@cfn_stack_name, @region) @resolver = ParameterResolver.new(self) end |
Instance Attribute Details
#region ⇒ Object (readonly)
Returns the value of attribute region.
38 39 40 |
# File 'lib/bora/stack.rb', line 38 def region @region end |
#stack_config ⇒ Object (readonly)
Returns the value of attribute stack_config.
38 39 40 |
# File 'lib/bora/stack.rb', line 38 def stack_config @stack_config end |
#stack_name ⇒ Object (readonly)
Returns the value of attribute stack_name.
38 39 40 |
# File 'lib/bora/stack.rb', line 38 def stack_name @stack_name end |
#template_file ⇒ Object (readonly)
Returns the value of attribute template_file.
38 39 40 |
# File 'lib/bora/stack.rb', line 38 def template_file @template_file end |
Instance Method Details
#apply(override_params = {}, pretty_json = false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bora/stack.rb', line 44 def apply(override_params = {}, pretty_json = false) = generate(override_params, pretty_json) action = @cfn_stack.exists? ? 'update' : 'create' success = invoke_action(action.capitalize, action, ) if success outputs = @cfn_stack.outputs if outputs && !outputs.empty? puts 'Stack outputs' outputs.each { |output| puts output } end end success end |
#create_change_set(change_set_name, description = nil, override_params = {}, pretty_json = false) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/bora/stack.rb', line 140 def create_change_set(change_set_name, description = nil, override_params = {}, pretty_json = false) puts "Creating change set '#{change_set_name}' for stack '#{@cfn_stack_name}' in region #{@region}" = generate(override_params, pretty_json) [:description] = description if description change_set = @cfn_stack.create_change_set(change_set_name, ) puts change_set change_set end |
#delete ⇒ Object
58 59 60 |
# File 'lib/bora/stack.rb', line 58 def delete invoke_action('Delete', 'delete') end |
#delete_change_set(change_set_name) ⇒ Object
157 158 159 160 |
# File 'lib/bora/stack.rb', line 157 def delete_change_set(change_set_name) @cfn_stack.delete_change_set(change_set_name) puts "Deleted change set '#{change_set_name}' for stack '#{@cfn_stack_name}' in region #{@region}" end |
#describe_change_set(change_set_name) ⇒ Object
153 154 155 |
# File 'lib/bora/stack.rb', line 153 def describe_change_set(change_set_name) puts @cfn_stack.describe_change_set(change_set_name) end |
#diff(override_params = {}, context_lines = 3) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/bora/stack.rb', line 62 def diff(override_params = {}, context_lines = 3) = generate(override_params) diff_parameters() diff_template(context_lines, ) diff_change_set() end |
#events ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bora/stack.rb', line 69 def events events = @cfn_stack.events if events if !events.empty? puts STACK_EVENTS_MESSAGE % @cfn_stack_name events.each { |e| puts e } else puts STACK_EVENTS_DO_NOT_EXIST_MESSAGE % @cfn_stack_name end else puts STACK_DOES_NOT_EXIST_MESSAGE % @cfn_stack_name end events end |
#execute_change_set(change_set_name) ⇒ Object
162 163 164 |
# File 'lib/bora/stack.rb', line 162 def execute_change_set(change_set_name) invoke_action("Execute change set '#{change_set_name}'", 'execute_change_set', change_set_name) end |
#list_change_sets ⇒ Object
149 150 151 |
# File 'lib/bora/stack.rb', line 149 def list_change_sets puts @cfn_stack.list_change_sets.map(&:to_s).join("\n") end |
#outputs ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bora/stack.rb', line 84 def outputs outputs = @cfn_stack.outputs if outputs if !outputs.empty? puts "Outputs for stack '#{@cfn_stack_name}'" outputs.each { |output| puts output } else puts STACK_OUTPUTS_DO_NOT_EXIST_MESSAGE % @cfn_stack_name end else puts STACK_DOES_NOT_EXIST_MESSAGE % @cfn_stack_name end outputs end |
#parameters ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bora/stack.rb', line 99 def parameters parameters = @cfn_stack.parameters if parameters if !parameters.empty? puts "Parameters for stack '#{@cfn_stack_name}'" parameters.each { |parameter| puts parameter } else puts STACK_PARAMETERS_DO_NOT_EXIST_MESSAGE % @cfn_stack_name end else puts STACK_DOES_NOT_EXIST_MESSAGE % @cfn_stack_name end parameters end |
#rake_tasks ⇒ Object
40 41 42 |
# File 'lib/bora/stack.rb', line 40 def rake_tasks StackTasks.new(self) end |
#recreate(override_params = {}) ⇒ Object
114 115 116 117 |
# File 'lib/bora/stack.rb', line 114 def recreate(override_params = {}) = generate(override_params) invoke_action('Recreate', 'recreate', ) end |
#resolved_params(override_params = {}) ⇒ Object
166 167 168 169 170 |
# File 'lib/bora/stack.rb', line 166 def resolved_params(override_params = {}) params = @stack_config['params'] || {} params.merge!(override_params) @resolver.resolve(params) end |
#show(override_params = {}) ⇒ Object
119 120 121 122 |
# File 'lib/bora/stack.rb', line 119 def show(override_params = {}) = generate(override_params) puts get_new_template() end |
#show_current ⇒ Object
124 125 126 127 |
# File 'lib/bora/stack.rb', line 124 def show_current template = current_template puts template ? template : (STACK_DOES_NOT_EXIST_MESSAGE % @cfn_stack_name) end |
#status ⇒ Object
129 130 131 |
# File 'lib/bora/stack.rb', line 129 def status puts @cfn_stack.status end |
#validate(override_params = {}) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/bora/stack.rb', line 133 def validate(override_params = {}) = generate(override_params) is_valid = @cfn_stack.validate() puts STACK_VALIDATE_SUCCESS_MESSAGE % @cfn_stack_name if is_valid is_valid end |