Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Initial functionality to show resource replace
Browse files Browse the repository at this point in the history
Still need to add all the resource property changes that could trigger a
replacement.  For now, only does HostedZone.Name
  • Loading branch information
rdickey committed Nov 4, 2016
1 parent 9774880 commit d381448
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
25 changes: 20 additions & 5 deletions lib/convection/model/diff.rb
Expand Up @@ -12,23 +12,38 @@ class Diff
attr_reader :action
attr_reader :ours
attr_reader :theirs
colorize :action, :green => [:create], :yellow => [:update], :red => [:delete]
colorize :action, :green => [:create], :yellow => [:update], :red => [:delete, :replace]

# Properties for which a change requires a replacement
# (as opposed to an in-place update)
REPLACE_PROPERTIES = [
"AWS::Route53::HostedZone.Name",
# TODO: Add more
]

def initialize(key, ours, theirs)
@key = key
@ours = ours
@theirs = theirs

@action = if ours && theirs then :update
elsif ours then :create
else :delete
end
@action = :delete
if ours && theirs
property_name = key[/AWS::[A-Za-z0-9:]+\.[A-Za-z0-9]+/]
if REPLACE_PROPERTIES.include? property_name
@action = :replace
else
@action = :update
end
elsif ours
@action = :create
end
end

def to_thor
message = case action
when :create then "#{ key }: #{ ours }"
when :update then "#{ key }: #{ theirs } => #{ ours }"
when :replace then "#{ key }: #{ theirs } => #{ ours }"
when :delete then key
end

Expand Down
2 changes: 1 addition & 1 deletion lib/convection/model/mixin/colorize.rb
Expand Up @@ -9,7 +9,7 @@ def colorize(param, options = {})
when *options.fetch(:cyan, [:debug, :trace]) then :cyan
when *options.fetch(:green, [:info, :success, :create]) then :green
when *options.fetch(:yellow, [:warn, :update]) then :yellow
when *options.fetch(:red, [:error, :fail, :delete]) then :red
when *options.fetch(:red, [:error, :fail, :delete, :replace]) then :red
else options.fetch(:default, :green)
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/convection/model/template.rb
Expand Up @@ -184,7 +184,12 @@ def diff(other = {})
def properties(memo = {}, path = '')
keys.each do |key|
if self[key].is_a?(Hash) || self[key].is_a?(Array)
self[key].properties(memo, "#{path}.#{key}")
new_path = "#{path}#{path.empty? ? '' : '.'}#{key}"
resource_type = self["Type"]
if resource_type
new_path = "#{new_path}.#{resource_type}"
end
self[key].properties(memo, "#{new_path}")
else
memo["#{path}.#{key}"] = self[key]
end
Expand Down

0 comments on commit d381448

Please sign in to comment.