Sha256: 468d45875e7a5d7db12491b02601787171ae744010db8b82887c5bd6c20a0454

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'mixlib/shellout'
require 'logger'

module Ruby
  module Terraform
    module ExecutionSupport
      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
          loger.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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake-terraform-wrapper-0.2.0 lib/ruby/terraform/execution_support.rb