Class: Lono::Cfn::Diff

Inherits:
Base
  • Object
show all
Includes:
AwsService
Defined in:
lib/lono/cfn/diff.rb

Instance Method Summary collapse

Methods included from AwsService

#cfn, #stack_exists?, #testing_update?

Methods inherited from Base

#append_suffix, #build_scripts, #capabilities, #check_files, #check_for_errors, #command_with_iam, #convention_path, #exit_unless_updatable!, #generate_all, #generate_params, #generate_templates, #get_source_path, #initialize, #prompt_for_iam, #quit, #random_suffix, #remove_suffix, #s3_folder, #set_template_body!, #show_parameters, #stack_name_suffix, #stack_status, #starting_message, #status, #switch_current, #upload_files, #upload_scripts, #upload_templates

Methods included from Util

#are_you_sure?

Constructor Details

This class inherits a constructor from Lono::Cfn::Base

Instance Method Details

#diff_viewerObject



40
41
42
43
# File 'lib/lono/cfn/diff.rb', line 40

def diff_viewer
  return ENV['LONO_DIFF'] if ENV['LONO_DIFF']
  system("type colordiff > /dev/null") ? "colordiff" : "diff"
end

#download_existing_cfn_templateObject



20
21
22
23
24
25
26
27
# File 'lib/lono/cfn/diff.rb', line 20

def download_existing_cfn_template
  resp = cfn.get_template(
    stack_name: @stack_name,
    template_stage: "Original"
  )
  resp.template_body
  IO.write(existing_template_path, resp.template_body)
end

#existing_template_pathObject



45
46
47
# File 'lib/lono/cfn/diff.rb', line 45

def existing_template_path
  "/tmp/existing_cfn_template.yml"
end

#new_cfn_templateObject

for clarity



36
37
38
# File 'lib/lono/cfn/diff.rb', line 36

def new_cfn_template
  @template_path
end

#runObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lono/cfn/diff.rb', line 4

def run
  unless stack_exists?(@stack_name)
    puts "WARN: Cannot create a diff for the stack because the #{@stack_name} does not exists.".colorize(:yellow)
    return
  end

  if @options[:noop]
    puts "NOOP Generating CloudFormation source code diff..."
  else
    generate_all # from Base superclass. Generates the output lono teplates
    puts "Generating CloudFormation source code diff..."
    download_existing_cfn_template
    show_changes
  end
end

#show_changesObject



29
30
31
32
33
# File 'lib/lono/cfn/diff.rb', line 29

def show_changes
  command = "#{diff_viewer} #{existing_template_path} #{new_cfn_template}"
  puts "Running: #{command}"
  system(command)
end