Class: Terraspace::Terraform::Runner
- Extended by:
- Memoist
- Includes:
- Hooks::Concern, Util
- Defined in:
- lib/terraspace/terraform/runner.rb,
lib/terraspace/terraform/runner/backend.rb,
lib/terraspace/terraform/runner/retryer.rb
Defined Under Namespace
Constant Summary collapse
- @@current_dir_message_shown =
false
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#shell_exception ⇒ Object
readonly
Returns the value of attribute shell_exception.
Instance Method Summary collapse
-
#args ⇒ Object
default at end in case of redirection.
- #current_dir_message ⇒ Object
-
#custom ⇒ Object
From config/args/terraform.rb terraspace.cloud/docs/config/args/terraform/.
-
#initialize(name, options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #log(msg) ⇒ Object
-
#pass ⇒ Object
From Thor passthrough cli @options.
- #run ⇒ Object
- #terraform(name, *args) ⇒ Object
-
#thor ⇒ Object
From Thor defined/managed cli @options.
Methods included from Util::Pretty
Methods included from Util::Sure
Methods included from Util::Logging
Methods included from Hooks::Concern
Constructor Details
#initialize(name, options = {}) ⇒ Runner
Returns a new instance of Runner.
8 9 10 11 |
# File 'lib/terraspace/terraform/runner.rb', line 8 def initialize(name, ={}) @name = name super() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/terraspace/terraform/runner.rb', line 7 def name @name end |
#shell_exception ⇒ Object (readonly)
Returns the value of attribute shell_exception.
7 8 9 |
# File 'lib/terraspace/terraform/runner.rb', line 7 def shell_exception @shell_exception end |
Instance Method Details
#args ⇒ Object
default at end in case of redirection. IE: terraform output > /path
21 22 23 24 |
# File 'lib/terraspace/terraform/runner.rb', line 21 def args args = custom.args + pass.args + thor.args args.uniq end |
#current_dir_message ⇒ Object
83 84 85 86 87 |
# File 'lib/terraspace/terraform/runner.rb', line 83 def return if @@current_dir_message_shown log "Current directory: #{Terraspace::Util.pretty_path(@mod.cache_dir)}" @@current_dir_message_shown = true end |
#custom ⇒ Object
From config/args/terraform.rb terraspace.cloud/docs/config/args/terraform/
27 28 29 |
# File 'lib/terraspace/terraform/runner.rb', line 27 def custom Args::Custom.new(@mod, @name) end |
#log(msg) ⇒ Object
89 90 91 92 |
# File 'lib/terraspace/terraform/runner.rb', line 89 def log(msg) # quiet useful for RemoteState::Fetcher @options[:quiet] ? logger.debug(msg) : logger.info(msg) end |
#pass ⇒ Object
From Thor passthrough cli @options
33 34 35 |
# File 'lib/terraspace/terraform/runner.rb', line 33 def pass Args::Pass.new(@mod, @name, @options) end |
#run ⇒ Object
13 14 15 16 17 18 |
# File 'lib/terraspace/terraform/runner.rb', line 13 def run time_took do terraform(name, args) end @success end |
#terraform(name, *args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/terraspace/terraform/runner.rb', line 44 def terraform(name, *args) # only show once params = args.flatten.join(' ') command = "#{Terraspace.terraform_bin} #{name} #{params}".squish @shell_exception = nil run_hooks("terraform.rb", name) do Backend.new(@mod).create begin Terraspace::Shell.new(@mod, command, @options.merge(env: custom.env_vars)).run @success = true rescue Terraspace::ShellError => exception @shell_exception = exception @success = false end end rescue Terraspace::SharedCacheError, Terraspace::InitRequiredError @retryer ||= Retryer.new(@mod, @options, name, $!) if @retryer.retry? @retryer.run retry else exit(1) end rescue Terraspace::StateLockError => e logger.debug "ERROR: #{e.class}".color(:red) logger.info e. md = e..match(/\s+ID:\s+(.*)/) return unless md return unless lock_id = md[1] logger.info <<~EOL You can force release the lock with: terraspace force_unlock #{@mod.name} #{lock_id} EOL end |