class TerraformLandscape::TerraformPlan
def display_modified_attribute( # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def display_modified_attribute( # rubocop:disable Metrics/AbcSize, Metrics/MethodLength change_color, attribute_name, attribute_value, attribute_value_indent, attribute_value_indent_amount ) # Handle case where attribute has an annotation (e.g. "forces new resource") # appended onto the end. This is hard to parse in the Treetop grammar, so we # instead catch it here and extract if match = attribute_value.match(/\((?<reason>[^)]+)\)$/) reason = match['reason'] attribute_value = attribute_value[0...match.begin(0)] end # Since the attribute line is always of the form # "old value" => "new value", we can add curly braces and parse with # `eval` to obtain a hash with a single key/value. old, new = eval("{#{attribute_value}}").to_a.first # rubocop:disable Lint/Eval return if old == new # Don't show unchanged attributes @out.print " #{attribute_name}:".ljust(attribute_value_indent_amount, ' ') .colorize(change_color) if json?(new) # Value looks like JSON, so prettify it to make it more readable fancy_old = "#{to_pretty_json(old)}\n" fancy_new = "#{to_pretty_json(new)}\n" display_diff(fancy_old, fancy_new, attribute_value_indent) elsif old.include?("\n") || new.include?("\n") # Multiline content, so display nicer diff display_diff("#{old}\n", "#{new}\n", attribute_value_indent) else # Typical values, so just show before/after @out.print '"' + old.colorize(:red) + '"' @out.print ' => '.colorize(:light_black) @out.print '"' + new.colorize(:green) + '"' end @out.print " (#{reason})".colorize(:magenta) if reason @out.newline end