Class: Terraspace::CLI::Init
- Inherits:
-
Base
- Object
- Base
- Terraspace::CLI::Init
show all
- Defined in:
- lib/terraspace/cli/init.rb
Instance Method Summary
collapse
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
Constructor Details
#initialize(options = {}) ⇒ Init
Returns a new instance of Init.
5
6
7
8
9
|
# File 'lib/terraspace/cli/init.rb', line 5
def initialize(options={})
super(options.merge(log_to_stderr: true))
end
|
Instance Method Details
#auto? ⇒ Boolean
58
59
60
61
|
# File 'lib/terraspace/cli/init.rb', line 58
def auto?
@options[:auto] && calling_command == "up"
end
|
#build_remote_dependencies ⇒ Object
Currently only handles remote modules only one-level deep.
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/terraspace/cli/init.rb', line 39
def build_remote_dependencies
modules_json_path = "#{@mod.cache_dir}/.terraform/modules/modules.json"
return unless File.exist?(modules_json_path)
initialized_modules = JSON.load(IO.read(modules_json_path))
initialized_modules["Modules"].each do |meta|
build_remote_mod(meta)
end
end
|
#build_remote_mod(meta) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/terraspace/cli/init.rb', line 50
def build_remote_mod(meta)
return if local_source?(meta["Source"])
return if meta['Dir'] == '.'
remote_mod = Terraspace::Mod::Remote.new(meta, @mod)
Terraspace::Compiler::Perform.new(remote_mod).build
end
|
#init ⇒ Object
Note the init will always create the Terraform Cloud Workspace
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/terraspace/cli/init.rb', line 18
def init
return unless run_init? init_timeout = Integer(ENV['TS_INIT_TIMEOUT'] || 600)
Timeout::timeout(init_timeout) do
Terraspace::Terraform::Runner.new("init", @options).run if !auto? && @options[:init] != false end
rescue Timeout::Error
logger.error "ERROR: It took too long to run terraform init. Here is the output logs of terraform init:".color(:red)
logger.error IO.read(Terraspace::Terraform::Args::Default.terraform_init_log)
end
|
#run ⇒ Object
11
12
13
14
15
|
# File 'lib/terraspace/cli/init.rb', line 11
def run
init
sync_cloud
end
|
#sync_cloud? ⇒ Boolean
34
35
36
|
# File 'lib/terraspace/cli/init.rb', line 34
def sync_cloud?
%w[apply down plan up].include?(calling_command)
end
|