class Stacker::Stack::Template
Constants
- FORMAT_VERSION
Public Instance Methods
diff(*args)
click to toggle source
# File lib/stacker/stack/template.rb, line 58 def diff *args if json? Differ.json_diff local, remote, *args else Differ.diff local_raw, remote_raw, *args end end
dump()
click to toggle source
# File lib/stacker/stack/template.rb, line 71 def dump write remote end
exists?()
click to toggle source
# File lib/stacker/stack/template.rb, line 17 def exists? File.exists? path end
local()
click to toggle source
# File lib/stacker/stack/template.rb, line 26 def local raise TemplateDoesNotExistError.new name unless exists? @local ||= begin template = if json? JSON.parse local_raw else YAML.load local_raw end template['AWSTemplateFormatVersion'] ||= FORMAT_VERSION template end rescue JSON::ParserError, Psych::SyntaxError raise TemplateSyntaxError.new path end
local_raw()
click to toggle source
# File lib/stacker/stack/template.rb, line 21 def local_raw File.read path end
remote()
click to toggle source
# File lib/stacker/stack/template.rb, line 48 def remote @remote ||= json? ? JSON.parse(remote_raw) : YAML.parse(remote_raw) 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
remote_raw()
click to toggle source
# File lib/stacker/stack/template.rb, line 41 def remote_raw stack.region.client.get_template( stack_name: stack.name ).template_body end
write(value = local)
click to toggle source
# File lib/stacker/stack/template.rb, line 67 def write value = local File.write path, JSONFormatter.format(value) end
Private Instance Methods
json?()
click to toggle source
# File lib/stacker/stack/template.rb, line 95 def json? path.end_with? '.json' end
name()
click to toggle source
# File lib/stacker/stack/template.rb, line 77 def name stack.options.fetch('template_name', stack.name) end
path()
click to toggle source
# File lib/stacker/stack/template.rb, line 88 def path json = path_with_ext 'json' yaml = path_with_ext 'yml' File.exists?(json) ? json : yaml end
path_with_ext(ext)
click to toggle source
# File lib/stacker/stack/template.rb, line 81 def path_with_ext ext File.join( stack.region.templates_path, "#{name}.#{ext}" ) end
yaml?()
click to toggle source
# File lib/stacker/stack/template.rb, line 99 def yaml? path.end_with? '.yml' end