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"- STACK_ACTION_FAILURE_MESSAGE =
"%s stack '%s' failed"- STACK_ACTION_NOT_CHANGED_MESSAGE =
"%s stack '%s' skipped as template has not changed"- STACK_DOES_NOT_EXIST_MESSAGE =
"Stack '%s' does not exist"- STACK_EVENTS_DO_NOT_EXIST_MESSAGE =
"Stack '%s' has no events"- STACK_EVENTS_MESSAGE =
"Events for stack '%s'"- STACK_OUTPUTS_DO_NOT_EXIST_MESSAGE =
"Stack '%s' has no outputs"- STACK_PARAMETERS_DO_NOT_EXIST_MESSAGE =
"Stack '%s' has no parameters"- STACK_VALIDATE_SUCCESS_MESSAGE =
"Template for stack '%s' is valid"
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
- #delete ⇒ Object
- #diff(override_params = {}, context_lines = 3) ⇒ Object
- #events ⇒ Object
-
#initialize(stack_name, template_file, stack_config) ⇒ Stack
constructor
A new instance of Stack.
- #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.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bora/stack.rb', line 21 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'] @cfn_options = (stack_config) @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.
35 36 37 |
# File 'lib/bora/stack.rb', line 35 def region @region end |
#stack_config ⇒ Object (readonly)
Returns the value of attribute stack_config.
35 36 37 |
# File 'lib/bora/stack.rb', line 35 def stack_config @stack_config end |
#stack_name ⇒ Object (readonly)
Returns the value of attribute stack_name.
35 36 37 |
# File 'lib/bora/stack.rb', line 35 def stack_name @stack_name end |
#template_file ⇒ Object (readonly)
Returns the value of attribute template_file.
35 36 37 |
# File 'lib/bora/stack.rb', line 35 def template_file @template_file end |
Instance Method Details
#apply(override_params = {}, pretty_json = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bora/stack.rb', line 41 def apply(override_params = {}, pretty_json = false) generate(override_params, pretty_json) success = invoke_action(@cfn_stack.exists? ? "update" : "create", @cfn_options) if success outputs = @cfn_stack.outputs if outputs && outputs.length > 0 puts "Stack outputs" outputs.each { |output| puts output } end end success end |
#delete ⇒ Object
54 55 56 |
# File 'lib/bora/stack.rb', line 54 def delete invoke_action("delete") end |
#diff(override_params = {}, context_lines = 3) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bora/stack.rb', line 58 def diff(override_params = {}, context_lines = 3) generate(override_params) diff = Diffy::Diff.new(@cfn_stack.template, @cfn_stack.new_template(@cfn_options), context: context_lines, include_diff_info: true) diff = diff.reject { |line| line =~ /^(---|\+\+\+|\\\\)/ } diff = diff.map do |line| case line when /^\+/ line.chomp.colorize(:green) when /^-/ line.chomp.colorize(:red) when /^@@/ line.chomp.colorize(:cyan) else line.chomp end end puts diff.join("\n") end |
#events ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/bora/stack.rb', line 79 def events events = @cfn_stack.events if events if events.length > 0 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 |
#outputs ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/bora/stack.rb', line 94 def outputs outputs = @cfn_stack.outputs if outputs if outputs.length > 0 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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/bora/stack.rb', line 109 def parameters parameters = @cfn_stack.parameters if parameters if parameters.length > 0 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
37 38 39 |
# File 'lib/bora/stack.rb', line 37 def rake_tasks StackTasks.new(self) end |
#recreate(override_params = {}) ⇒ Object
124 125 126 127 |
# File 'lib/bora/stack.rb', line 124 def recreate(override_params = {}) generate(override_params) invoke_action("recreate", @cfn_options) end |
#resolved_params(override_params = {}) ⇒ Object
150 151 152 153 154 |
# File 'lib/bora/stack.rb', line 150 def resolved_params(override_params = {}) params = @stack_config['params'] || {} params.merge!(override_params) @resolver.resolve(params) end |
#show(override_params = {}) ⇒ Object
129 130 131 132 |
# File 'lib/bora/stack.rb', line 129 def show(override_params = {}) generate(override_params) puts @cfn_stack.new_template(@cfn_options) end |
#show_current ⇒ Object
134 135 136 137 |
# File 'lib/bora/stack.rb', line 134 def show_current template = @cfn_stack.template puts template ? template : (STACK_DOES_NOT_EXIST_MESSAGE % @cfn_stack_name) end |
#status ⇒ Object
139 140 141 |
# File 'lib/bora/stack.rb', line 139 def status puts @cfn_stack.status end |
#validate(override_params = {}) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/bora/stack.rb', line 143 def validate(override_params = {}) generate(override_params) is_valid = @cfn_stack.validate(@cfn_options) puts STACK_VALIDATE_SUCCESS_MESSAGE % @cfn_stack_name if is_valid is_valid end |