class TerraformLandscape::Printer
def process_string(plan_output)
def process_string(plan_output) scrubbed_output = plan_output.gsub(/\e\[\d+m/, '') # Remove preface if (match = scrubbed_output.match(/^Path:[^\n]+/)) scrubbed_output = scrubbed_output[match.end(0)..-1] elsif (match = scrubbed_output.match(/^Terraform.+following\sactions:/)) scrubbed_output = scrubbed_output[match.end(0)..-1] elsif (match = scrubbed_output.match(/^\s*(~|\+|\-)/)) scrubbed_output = scrubbed_output[match.begin(0)..-1] elsif scrubbed_output =~ /^(No changes|This plan does nothing)/ @output.puts 'No changes' return else raise ParseError, 'Output does not contain proper preface' end # Remove postface if (match = scrubbed_output.match(/^Plan:[^\n]+/)) plan_summary = scrubbed_output[match.begin(0)..match.end(0)] scrubbed_output = scrubbed_output[0...match.begin(0)] end plan = TerraformPlan.from_output(scrubbed_output) plan.display(@output) @output.puts plan_summary end