Class: Terraspace::CLI::Plan
Instance Method Summary
collapse
Methods included from TfcConcern
#backend, #tfc?
#able_to_comment?, #cloud_comment, #finalize_vars, #kind, #pr_comment, #vcs, #vcs_vars
#cloud_stream
#plan_path
Methods inherited from Base
#initialize
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
Instance Method Details
#cloud_cost ⇒ Object
72
73
74
|
# File 'lib/terraspace/cli/plan.rb', line 72
def cloud_cost
Terraspace::Cloud::Cost.new(@options.merge(stack: @mod.name, kind: kind, vcs_vars: vcs_vars))
end
|
#cloud_plan ⇒ Object
67
68
69
|
# File 'lib/terraspace/cli/plan.rb', line 67
def cloud_plan
Terraspace::Cloud::Plan.new(@options.merge(stack: @mod.name, kind: kind, vcs_vars: vcs_vars))
end
|
#commander ⇒ Object
48
49
50
|
# File 'lib/terraspace/cli/plan.rb', line 48
def commander
Commander.new("plan", @options)
end
|
#copy_out_file_to_root ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/terraspace/cli/plan.rb', line 53
def copy_out_file_to_root
file = @mod.out_option
return if !file || @options[:copy_to_root] == false
return if file =~ %r{^/}
name = file.sub("#{Terraspace.root}/",'')
src = "#{@mod.cache_dir}/#{name}"
dest = name
return unless File.exist?(src) FileUtils.mkdir_p(File.dirname(dest))
FileUtils.cp(src, dest)
!!dest
end
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/terraspace/cli/plan.rb', line 16
def perform
success = plan_only
plan = cloud_plan.create(success, @stream)
if success && plan resp = cloud_cost.cani?(exit_on_error: false)
if resp['errors'] logger.info "WARN: Not creating a cost estimate."
logger.info resp['errors'][0]['detail']
else
cost = cloud_cost.create(uid: plan['data']['id'], stream: @stream)
(plan, cost)
end
logger.info "Terraspace Cloud #{plan['data']['attributes']['url']}"
end
success
rescue Exception => e
@exception = true
logger.info "Exception #{e.class}: #{e.message}".color(:red)
logger.info e.backtrace.join("\n")
false
end
|
#plan_only ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/terraspace/cli/plan.rb', line 38
def plan_only
if Terraspace.cloud? && !@options[:out]
@options[:out] = plan_path
end
cloud_plan.setup
success = commander.run
copy_out_file_to_root
success
end
|
#run ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/terraspace/cli/plan.rb', line 8
def run
cloud_plan.cani?
@stream = cloud_stream.open("plan")
success = perform
cloud_stream.close(success, @exception)
exit 1 unless success
end
|