lib/terraspace/all/runner.rb in terraspace-1.0.6 vs lib/terraspace/all/runner.rb in terraspace-1.1.0

- old
+ new

@@ -1,8 +1,9 @@ module Terraspace::All class Runner < Base include Terraspace::Util + extend Memoist def initialize(command, options={}) @command, @options = command, options super(options) end @@ -19,46 +20,51 @@ def preview Preview.new(@command, @batches, @options).show end def build_batches - @batches = run_builder(quiet: false) + @batches = Terraspace::Dependency::Resolver.new(@options).resolve @batches.reverse! if @command == "down" @batches end def deploy_batches truncate_logs if ENV['TS_TRUNCATE_LOGS'] + build_modules @batches.each_with_index do |batch,i| logger.info "Batch Run #{i+1}:" - run_builder unless i == 0 # already handled by build_batches the first time deploy_batch(batch) end end - # Should run after each batch run. run_builder also calls replace_outputs. - # Important: rebuild from source so placeholders are in place. - def run_builder(quiet: true) - Terraspace::Builder.new(@options.merge(mod: "placeholder", quiet: quiet)).run - end - def deploy_batch(batch) @pids = {} # stores child processes pids. map of pid to mod_name, reset this list on each batch run concurrency = Terraspace.config.all.concurrency batch.sort_by(&:name).each_slice(concurrency) do |slice| slice.each do |node| pid = fork do + build_stack(node.name) run_terraspace(node.name) end @pids[pid] = node.name # store mod_name mapping end end wait_for_child_proccess summarize # also reports lower-level error info report_errors # reports finall errors and possibly exit end + def build_modules + builder = Terraspace::Builder.new(@options.merge(mod: "placeholder", quiet: true, clean: true)) + builder.build(modules: true, stack: false) + end + + def build_stack(name) + builder = Terraspace::Builder.new(@options.merge(mod: name, quiet: true, clean: false)) + builder.build(modules: false, stack: true) + end + def wait_for_child_proccess @errors = [] # stores child processes pids that errored @pids.each do |pid, _| pid, status = Process.wait2(pid) success = status.exitstatus == 0 @@ -68,11 +74,11 @@ def report_errors @errors.each do |pid| mod_name = @pids[pid] terraspace_command = terraspace_command(mod_name) - logger.error "Error running: #{terraspace_command}. Check logs and fix the error.".color(:red) + logger.error "Error running: #{terraspace_command}. Fix the error above or check logs for the error.".color(:red) end unless @errors.empty? exit 2 if exit_on_fail? end end @@ -95,10 +101,11 @@ data = { command: @command, log_path: log_path(mod_name), terraspace_command: terraspace_command(mod_name), } - Summary.new(data).run + # Its possible for log file to not get created if RemoteState::Fetcher#validate! fails + Summary.new(data).run if File.exist?(data[:log_path]) end end def run_terraspace(mod_name) set_log_path!(mod_name)