Class: Ruby::Terraform::Executable

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/terraform/executable.rb

Defined Under Namespace

Classes: PlatformUnsupported

Instance Method Summary collapse

Constructor Details

#initialize(config = Ruby::Terraform.config) ⇒ Executable

Returns a new instance of Executable.



17
18
19
20
21
22
23
24
25
# File 'lib/ruby/terraform/executable.rb', line 17

def initialize(config = Ruby::Terraform.config)
  @terraform_version = config.terraform_version
  @download_path = config.download_path
  @binary = config.binary
  @download_filename = "#{@terraform_version}-terraform.zip"
  FileUtils.mkdir_p(@download_path)

  raise PlatformUnsupported unless supported?
end

Instance Method Details

#binaryObject



27
28
29
# File 'lib/ruby/terraform/executable.rb', line 27

def binary
  @binary
end

#download(opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby/terraform/executable.rb', line 31

def download(opts = {})
  return if binary_exist?
  opts[:uri] ||= ENV['TERRAFORM_DOWNLOAD_URL'] || "https://releases.hashicorp.com/#{download_uri}"

  $stderr.puts("Downloading terraform binary from #{opts[:uri]}") if opts[:verbose]

  open("#{@download_path}/#{@download_filename}", 'wb') do |saved_file|
    open(opts[:uri], 'rb') do |read_file|
      saved_file.write(read_file.read)
    end
  end
end

#extract(opts = {}) ⇒ Object



44
45
46
47
48
49
# File 'lib/ruby/terraform/executable.rb', line 44

def extract(opts={})
  return if binary_exist?

  Decompressor.extract("#{@download_path}/#{@download_filename}", @download_path, opts[:verbose] || false)
  make_exe
end