Class: Terraspace::Terraform::Runner
Defined Under Namespace
Classes: Retryer
Constant Summary
collapse
- @@current_dir_message_shown =
false
Instance Attribute Summary collapse
Instance Method Summary
collapse
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
#run_hooks
Constructor Details
#initialize(name, options = {}) ⇒ Runner
Returns a new instance of Runner.
8
9
10
11
|
# File 'lib/terraspace/terraform/runner.rb', line 8
def initialize(name, options={})
@name = name
super(options)
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/terraspace/terraform/runner.rb', line 7
def name
@name
end
|
Instance Method Details
#args ⇒ Object
61
62
63
64
|
# File 'lib/terraspace/terraform/runner.rb', line 61
def args
custom.args + custom.var_files + default.args
end
|
#current_dir_message ⇒ Object
50
51
52
53
54
|
# File 'lib/terraspace/terraform/runner.rb', line 50
def current_dir_message
return if @@current_dir_message_shown
log "Current directory: #{Terraspace::Util.pretty_path(@mod.cache_dir)}"
@@current_dir_message_shown = true
end
|
#custom ⇒ Object
66
67
68
|
# File 'lib/terraspace/terraform/runner.rb', line 66
def custom
Args::Custom.new(@mod, @name)
end
|
#default ⇒ Object
71
72
73
|
# File 'lib/terraspace/terraform/runner.rb', line 71
def default
Args::Default.new(@mod, @name, @options)
end
|
#log(msg) ⇒ Object
56
57
58
59
|
# File 'lib/terraspace/terraform/runner.rb', line 56
def log(msg)
@options[:quiet] ? logger.debug(msg) : logger.info(msg)
end
|
#run ⇒ Object
13
14
15
16
17
|
# File 'lib/terraspace/terraform/runner.rb', line 13
def run
time_took do
terraform(name, args)
end
end
|
#run_internal_hook(type, name) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/terraspace/terraform/runner.rb', line 39
def run_internal_hook(type, name)
begin
klass = "Terraspace::Terraform::Ihooks::#{type.to_s.classify}::#{name.classify}".constantize
rescue NameError
return
end
ihook = klass.new(name, @options)
ihook.run
end
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/terraspace/terraform/runner.rb', line 19
def terraform(name, *args)
current_dir_message
params = args.flatten.join(' ')
command = "terraform #{name} #{params}".squish
run_hooks("terraform.rb", name) do
run_internal_hook(:before, name)
Terraspace::Shell.new(@mod, command, @options.merge(env: custom.env_vars)).run
run_internal_hook(:after, name)
end
rescue Terraspace::SharedCacheError, Terraspace::InitRequiredError
@retryer ||= Retryer.new(@mod, @options, name, $!)
if @retryer.retry?
@retryer.run
retry
else
exit(1)
end
end
|