Class: RubyTerraform::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_terraform/commands/base.rb

Direct Known Subclasses

Apply, Destroy, Get, Init, Output, Plan, Refresh, RemoteConfig, Show, Validate, Workspace

Instance Method Summary collapse

Constructor Details

#initialize(binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
# File 'lib/ruby_terraform/commands/base.rb', line 7

def initialize(
    binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil)
  @binary = binary || RubyTerraform.configuration.binary
  @logger = logger || RubyTerraform.configuration.logger
  @stdin = stdin || RubyTerraform.configuration.stdin
  @stdout = stdout || RubyTerraform.configuration.stdout
  @stderr = stderr || RubyTerraform.configuration.stderr
end

Instance Method Details

#execute(opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_terraform/commands/base.rb', line 16

def execute(opts = {})
  builder = instantiate_builder

  do_before(opts)
  command = configure_command(builder, opts).build
  logger.debug("Running '#{command.to_s}'.")

  command.execute(
      stdin: stdin,
      stdout: stdout,
      stderr: stderr
  )
  do_after(opts)
rescue Open4::SpawnError
  message = "Failed while running '#{command_name}'."
  logger.error(message)
  raise Errors::ExecutionError, message
end