Class: Terraspace::Terraform::Runner

Inherits:
CLI::Base
  • Object
show all
Extended by:
Memoist
Includes:
Util
Defined in:
lib/terraspace/terraform/runner.rb

Constant Summary collapse

@@current_dir_message_shown =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#pretty_path

Methods included from Util::Sure

#sure?

Methods included from Util::Sh

#sh

Methods included from Util::Logging

#logger

Constructor Details

#initialize(name, options = {}) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
# File 'lib/terraspace/terraform/runner.rb', line 7

def initialize(name, options={})
  @name = name
  super(options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/terraspace/terraform/runner.rb', line 6

def name
  @name
end

Instance Method Details

#argsObject



41
42
43
44
# File 'lib/terraspace/terraform/runner.rb', line 41

def args
  # base at end in case of redirection. IE: terraform output > /path
  custom.args + custom.var_files + default.args
end

#current_dir_messageObject



29
30
31
32
33
# File 'lib/terraspace/terraform/runner.rb', line 29

def current_dir_message
  return if @@current_dir_message_shown
  logger.info "Current directory: #{Terraspace::Util.pretty_path(@mod.cache_dir)}"
  @@current_dir_message_shown = true
end

#customObject



46
47
48
# File 'lib/terraspace/terraform/runner.rb', line 46

def custom
  Args::Custom.new(@mod, @name)
end

#defaultObject



51
52
53
# File 'lib/terraspace/terraform/runner.rb', line 51

def default
  Args::Default.new(@mod, @name, @options)
end

#runObject



12
13
14
15
16
# File 'lib/terraspace/terraform/runner.rb', line 12

def run
  time_took do
    terraform(name, args)
  end
end

#run_hooks(name, &block) ⇒ Object



35
36
37
38
39
# File 'lib/terraspace/terraform/runner.rb', line 35

def run_hooks(name, &block)
  hooks = Hooks::Builder.new(@mod, name)
  hooks.build # build hooks
  hooks.run_hooks(&block)
end

#terraform(name, *args) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/terraspace/terraform/runner.rb', line 18

def terraform(name, *args)
  current_dir_message # only show once

  params = args.flatten.join(' ')
  command = "terraform #{name} #{params}"
  run_hooks(name) do
    sh(command, env: custom.env_vars)
  end
end