Sha256: a3cd03279c5b0c0e2952f592c76397992d0d2664f15f0fea75ddd7da8b8e44b4

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

class Lono::Cfn::Diff < Lono::Cfn::Base
  include Lono::Cfn::AwsServices

  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

  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

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

  # for clarity
  def new_cfn_template
    @template_path
  end

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

  def existing_template_path
    "/tmp/existing_cfn_template.json"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lono-3.0.1 lib/lono/cfn/diff.rb
lono-3.0.0 lib/lono/cfn/diff.rb
lono-2.1.0 lib/lono/cfn/diff.rb
lono-2.0.5 lib/lono/cfn/diff.rb
lono-2.0.4 lib/lono/cfn/diff.rb