Module: Ruby::Terraform::ExecutionSupport

Instance Method Summary collapse

Instance Method Details

#execute(opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby/terraform/execution_support.rb', line 7

def execute(opts = {})
  working_dir = opts[:dir] || (self.dir if self.respond_to?(:dir))

  shellout_opts = {}
  shellout_opts[:cwd] = working_dir if working_dir
  if opts[:live]
    shellout_opts[:live_stdout] = STDOUT
    shellout_opts[:live_stderr] = STDERR
  end

  if opts[:show_command]
    formatter = proc do |severity, datetime, progname, msg|
      "#{msg}\n"
    end
    logger = Logger.new(STDERR, formatter: formatter)
    shellout_opts[:logger] = logger
    logger.info("Running command inside directory: #{shellout_opts[:cwd]}") if shellout_opts[:cwd]
  end

  cmd = Mixlib::ShellOut.new(command, shellout_opts)
  cmd.run_command
  cmd.error!
end

#tf_binaryObject



31
32
33
34
35
36
# File 'lib/ruby/terraform/execution_support.rb', line 31

def tf_binary
  executable = Executable.new
  executable.download
  executable.extract
  executable.binary
end