class Stacker::Stack::Template

Constants

FORMAT_VERSION

Public Instance Methods

diff(*args) click to toggle source
# File lib/stacker/stack/template.rb, line 44
def diff *args
  Differ.json_diff local, remote, *args
end
dump() click to toggle source
# File lib/stacker/stack/template.rb, line 53
def dump
  write remote
end
exists?() click to toggle source
# File lib/stacker/stack/template.rb, line 16
def exists?
  File.exists? path
end
local() click to toggle source
# File lib/stacker/stack/template.rb, line 20
def local
  @local ||= begin
    if exists?
      template = JSON.parse File.read path
      template['AWSTemplateFormatVersion'] ||= FORMAT_VERSION
      template
    else
      {}
    end
  end
rescue JSON::ParserError
  raise TemplateSyntaxError.new path
end
remote() click to toggle source
# File lib/stacker/stack/template.rb, line 34
def remote
  @remote ||= JSON.parse client.template
rescue AWS::CloudFormation::Errors::ValidationError => err
  if err.message =~ /does not exist/
    raise DoesNotExistError.new err.message
  else
    raise Error.new err.message
  end
end
write(value = local) click to toggle source
# File lib/stacker/stack/template.rb, line 49
def write value = local
  File.write path, JSONFormatter.format(value)
end

Private Instance Methods

path() click to toggle source
# File lib/stacker/stack/template.rb, line 59
def path
  @path ||= File.join(
    stack.region.templates_path,
    "#{stack.options.fetch('template_name', stack.name)}.json"
  )
end