From f89cfcb64a6f9e793463f800ab62cdd0010d13a5 Mon Sep 17 00:00:00 2001 From: Andrew Wasilczuk Date: Thu, 13 Apr 2023 18:31:55 +0100 Subject: [PATCH 1/4] feat: added a flag to configure parallelism --- CHANGELOG.adoc | 4 ++++ bin/tfctl | 8 ++++++-- lib/tfctl/version.rb | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 48ff116..c340344 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -1,5 +1,9 @@ = Changelog +== 1.7.0 + + * feat: added a `-p` flag to configure parallelism + == 1.6.1 * fix: pagination problem when listing accounts in an OU. diff --git a/bin/tfctl b/bin/tfctl index e14103b..63eb9f8 100755 --- a/bin/tfctl +++ b/bin/tfctl @@ -26,6 +26,7 @@ options = { unbuffered: false, debug: false, use_cache: false, + parallelism: 8, } optparse = OptionParser.new do |opts| @@ -56,6 +57,9 @@ optparse = OptionParser.new do |opts| opts.on('-d', '--debug', 'Turn on debug messages') do options[:debug] = true end + opts.on('-p', '--parallelism', 'How many terraform processes to execute in parallel') do + options[:debug] = true + end opts.on('-v', '--version', 'Show version') do puts Tfctl::VERSION exit @@ -93,7 +97,7 @@ begin raise OptionParser::InvalidOption, 'Please specify target' end rescue OptionParser::InvalidOption, OptionParser::MissingArgument - warn $ERROR_INFO.to_s + warn $ERROR_INFO warn optparse exit 2 end @@ -202,7 +206,7 @@ begin # Execute Terraform in target accounts - Parallel.each(accounts, in_processes: 8) do |ac| + Parallel.each(accounts, in_processes: options[:parallelism]) do |ac| run_account(config, ac, options, ARGV, log) end diff --git a/lib/tfctl/version.rb b/lib/tfctl/version.rb index 5187e6f..a6c8ee2 100644 --- a/lib/tfctl/version.rb +++ b/lib/tfctl/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Tfctl - VERSION = '1.6.1' + VERSION = '1.7.0' end From 05ac13e0d76ab4ffb06f42cc4e6670b24ecf63a2 Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Fri, 14 Apr 2023 11:43:43 +0100 Subject: [PATCH 2/4] Fix parallelism setting in tfctl --- bin/tfctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/tfctl b/bin/tfctl index 63eb9f8..9dd1879 100755 --- a/bin/tfctl +++ b/bin/tfctl @@ -57,8 +57,8 @@ optparse = OptionParser.new do |opts| opts.on('-d', '--debug', 'Turn on debug messages') do options[:debug] = true end - opts.on('-p', '--parallelism', 'How many terraform processes to execute in parallel') do - options[:debug] = true + opts.on('-p', '--parallelism=num', 'How many terraform processes to execute in parallel') do |o| + options[:parallelism] = o.to_i end opts.on('-v', '--version', 'Show version') do puts Tfctl::VERSION From 27e2c1f76009be2c1a921a5c3e64b46be632464c Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Fri, 14 Apr 2023 11:45:09 +0100 Subject: [PATCH 3/4] Enhance the error message when Terraform execution fails We now include the account_name and the actual runcmd in the raised error. This should make it much easier to pinpoint which part of the logs you may be interested in. --- lib/tfctl/executor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tfctl/executor.rb b/lib/tfctl/executor.rb index df71319..b199e4f 100644 --- a/lib/tfctl/executor.rb +++ b/lib/tfctl/executor.rb @@ -88,7 +88,7 @@ def run(account_name:, config_name:, log:, cmd: nil, argv: [], unbuffered: true) FileUtils.rm_f plan_file if args[0] == 'apply' # tidy up the plan file unless status.exitstatus.zero? - raise Tfctl::Error, "#{cmd} failed with exit code: #{status.exitstatus}" + raise Tfctl::Error, "#{account_name}: #{runcmd} failed with exit code: #{status.exitstatus}" end end end From d8c41d79d3cb6a0c3595de92a091d7839d53b7f8 Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Fri, 14 Apr 2023 11:46:44 +0100 Subject: [PATCH 4/4] Update CHANGELOG with executor enhancement --- CHANGELOG.adoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c340344..6247662 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -3,6 +3,9 @@ == 1.7.0 * feat: added a `-p` flag to configure parallelism + * feat: enhanced the executor output when raising `Tfctl::Error`, it will now + report the `account_name` that raised the error along with the full command + that was being run == 1.6.1