Class: Awshark::CloudFormation::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/awshark/cloud_formation/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Manager

Returns a new instance of Manager.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/awshark/cloud_formation/manager.rb', line 12

def initialize(path, options = {})
  @path = path
  @options = options
  @stage = options[:stage]

  @capabilities = if options[:iam]
                    %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM]
                  else
                    []
                  end

  @stack = Stack.new(name: inferrer.stack_name)
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



10
11
12
# File 'lib/awshark/cloud_formation/manager.rb', line 10

def capabilities
  @capabilities
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/awshark/cloud_formation/manager.rb', line 9

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/awshark/cloud_formation/manager.rb', line 9

def path
  @path
end

#stackObject (readonly)

Returns the value of attribute stack.



10
11
12
# File 'lib/awshark/cloud_formation/manager.rb', line 10

def stack
  @stack
end

#stageObject (readonly)

Returns the value of attribute stage.



10
11
12
# File 'lib/awshark/cloud_formation/manager.rb', line 10

def stage
  @stage
end

Instance Method Details

#diff_stack_templateObject



26
27
28
29
30
31
32
33
# File 'lib/awshark/cloud_formation/manager.rb', line 26

def diff_stack_template
  new_template = template.body
  old_template = stack.template
  options = { context: 2 }

  diff = Diffy::Diff.new(old_template, new_template, options)
  diff.to_s(:color)
end

#save_stack_templateObject



49
50
51
52
53
# File 'lib/awshark/cloud_formation/manager.rb', line 49

def save_stack_template
  filename = "#{stack.name}.json"
  File.write(filename, template.body)
  filename
end

#tail_stack_eventsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/awshark/cloud_formation/manager.rb', line 55

def tail_stack_events
  stack.reload
  stack_events = StackEvents.new(stack)

  loop do
    events = stack_events.new_events
    print_stack_events(events)

    break if stack_events.done?

    sleep(event_polling)
  end
end

#update_stackObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/awshark/cloud_formation/manager.rb', line 35

def update_stack
  stack.create_or_update(
    capabilities: capabilities,
    stack_name: stack.name,
    template_url: template.url,
    parameters: parameters.stack_parameters
  )
rescue Aws::CloudFormation::Errors::ValidationError => e
  raise GracefulFail, e.message if e.message.match(/No updates are to be performed/)
  raise GracefulFail, e.message if e.message.match(/ROLLBACK_COMPLETE state and can not be updated/)

  raise e
end