Class: Terraspace::Cloud::Plan
Instance Method Summary
collapse
#plan_path
Methods inherited from Base
#cancelled?, #changes?, #clean_cache2_stage, #cloud_upload, #initialize, #record?, #sh, #stage_attrs, #success_status
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
Methods included from Context
#setup_context
#validate
#api, #cloud_stack_name, #expander, #region
#error_message, #errors?
#initialize
Instance Method Details
#build(success) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/terraspace/cloud/plan.rb', line 40
def build(success)
clean_cache2_stage
Dir.chdir(@mod.cache_dir) do
plan_dir = File.dirname(plan_path)
IO.write("#{plan_dir}/plan.log", Terraspace::Logger.logs)
return unless success
return if File.empty?(plan_path)
out_option_root_path = "#{Terraspace.root}/#{plan_path}"
return unless File.exist?(out_option_root_path)
FileUtils.cp(out_option_root_path, plan_path)
json = plan_path.sub('.binary','.json')
sh "#{Terraspace.terraform_bin} show -json #{plan_path} > #{json}"
end
end
|
#cani?(exit_on_error: true) ⇒ Boolean
60
61
62
63
|
# File 'lib/terraspace/cloud/plan.rb', line 60
def cani?(exit_on_error: true)
return true unless Terraspace.cloud?
api.create_plan(cani: 1, exit_on_error: exit_on_error)
end
|
#create(success, stream) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/terraspace/cloud/plan.rb', line 17
def create(success, stream)
return unless Terraspace.cloud?
return unless record?
build(success)
upload = cloud_upload.create(type: "plan", stream_id: stream['data']['id'])
api.create_plan(
upload_id: upload['data']['id'],
stack_uid: upload['data']['attributes']['stack_id'], plan: stage_attrs(success),
)
rescue Terraspace::NetworkError => e
logger.warn "WARN: #{e.class} #{e.message}"
logger.warn "WARN: Unable to save data to Terraspace cloud"
end
|
#create_stream ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/terraspace/cloud/plan.rb', line 32
def create_stream
return unless Terraspace.cloud?
api.create_stream("plan")
rescue Terraspace::NetworkError => e
logger.warn "WARN: #{e.class} #{e.message}"
logger.warn "WARN: Unable to save data to Terraspace cloud"
end
|
#setup ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/terraspace/cloud/plan.rb', line 5
def setup
return unless Terraspace.cloud?
cani?
return unless @mod.out_option
return if @mod.out_option =~ %r{^/}
name = @mod.out_option.sub("#{Terraspace.root}/",'')
dest = "#{@mod.cache_dir}/#{name}"
FileUtils.mkdir_p(File.dirname(dest))
end
|