Class: Bora::Stack
- Inherits:
-
Object
- Object
- Bora::Stack
- Defined in:
- lib/bora/stack.rb
Instance Attribute Summary collapse
-
#stack_name ⇒ Object
readonly
Returns the value of attribute stack_name.
Instance Method Summary collapse
- #apply(override_params = {}) ⇒ Object
- #delete ⇒ Object
- #diff(override_params = {}) ⇒ Object
- #events ⇒ Object
- #generate(override_params = {}) ⇒ Object
-
#initialize(stack_name, template_file, stack_config) ⇒ Stack
constructor
A new instance of Stack.
- #outputs ⇒ Object
- #rake_tasks ⇒ Object
- #recreate(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.
10 11 12 13 14 15 16 17 |
# File 'lib/bora/stack.rb', line 10 def initialize(stack_name, template_file, stack_config) @stack_name = stack_name @cfn_stack_name = stack_config['stack_name'] || @stack_name @template_file = template_file @stack_config = stack_config = (stack_config) @cfn_stack = Cfn::Stack.new(@cfn_stack_name) end |
Instance Attribute Details
#stack_name ⇒ Object (readonly)
Returns the value of attribute stack_name.
19 20 21 |
# File 'lib/bora/stack.rb', line 19 def stack_name @stack_name end |
Instance Method Details
#apply(override_params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bora/stack.rb', line 25 def apply(override_params = {}) generate(override_params) success = invoke_action(@cfn_stack.exists? ? "update" : "create", ) if success outputs = @cfn_stack.outputs if outputs && outputs.length > 0 puts "Stack outputs" outputs.each { |output| puts output } end end end |
#delete ⇒ Object
37 38 39 |
# File 'lib/bora/stack.rb', line 37 def delete invoke_action("delete") end |
#diff(override_params = {}) ⇒ Object
41 42 43 44 |
# File 'lib/bora/stack.rb', line 41 def diff(override_params = {}) generate(override_params) puts @cfn_stack.diff().to_s(String.disable_colorization ? :text : :color) end |
#events ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bora/stack.rb', line 46 def events events = @cfn_stack.events if events if events.length > 0 puts "Events for stack '#{@cfn_stack_name}'" @cfn_stack.events.each { |e| puts e } else puts "Stack '#{@cfn_stack_name}' has no events" end else puts "Stack '#{@cfn_stack_name}' does not exist" end end |
#generate(override_params = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bora/stack.rb', line 60 def generate(override_params = {}) params = process_params(override_params) if File.extname(@template_file) == ".rb" template_body = run_cfndsl(@template_file, params) template_json = JSON.parse(template_body) if template_json["Parameters"] cfn_param_keys = template_json["Parameters"].keys cfn_params = params.select { |k, v| cfn_param_keys.include?(k) }.map do |k, v| { parameter_key: k, parameter_value: v } end [:parameters] = cfn_params if !cfn_params.empty? end [:template_body] = template_body else [:template_url] = @template_file if !params.empty? [:parameters] = params.map do |k, v| { parameter_key: k, parameter_value: v } end end end end |
#outputs ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bora/stack.rb', line 83 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 '#{@cfn_stack_name}' has no outputs" end else puts "Stack '#{@cfn_stack_name}' does not exist" end end |
#rake_tasks ⇒ Object
21 22 23 |
# File 'lib/bora/stack.rb', line 21 def rake_tasks StackTasks.new(self) end |
#recreate(override_params = {}) ⇒ Object
97 98 99 100 |
# File 'lib/bora/stack.rb', line 97 def recreate(override_params = {}) generate(override_params) invoke_action("recreate", ) end |
#show(override_params = {}) ⇒ Object
102 103 104 105 |
# File 'lib/bora/stack.rb', line 102 def show(override_params = {}) generate(override_params) puts @cfn_stack.new_template() end |
#show_current ⇒ Object
107 108 109 110 |
# File 'lib/bora/stack.rb', line 107 def show_current template = @cfn_stack.template puts template ? template : "Stack '#{@cfn_stack_name}' does not exist" end |
#status ⇒ Object
112 113 114 |
# File 'lib/bora/stack.rb', line 112 def status puts @cfn_stack.status end |
#validate(override_params = {}) ⇒ Object
116 117 118 119 |
# File 'lib/bora/stack.rb', line 116 def validate(override_params = {}) generate(override_params) puts "Template for stack '#{@cfn_stack_name}' is valid" if @cfn_stack.validate() end |