4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/proteus/commands/plan.rb', line 4
def self.included(thor_class)
thor_class.class_eval do
desc "plan", "Runs terraform plan"
long_desc <<-LONGDESC
Runs terraform plan.
With --limit option, the plan run will be limited to the specified targets
LONGDESC
option :limit, type: :array, aliases: "-l", default: []
option :destroy, type: :boolean, default: false
option :parallelism, type: :numeric, aliases: "-p", default: 10
def plan
module_manager = Proteus::Modules::Manager.new(context: context, environment: environment)
module_manager.clean
module_manager.render_modules
fmt_cmd = <<~FMT_CMD
cd #{context_path(context)} && \
terraform fmt -list=true .
FMT_CMD
fmt_output = syscall(
fmt_cmd.squeeze(' '),
capture: true,
suppress: true
)
say "Formatted files:", :green
say fmt_output, :green
init(verbose: parent_options[:verbose]) if not dryrun
terraform_command = <<~TERRAFORM_COMMAND
cd #{context_path(context)} && \
terraform plan \
#{"-destroy" if options[:destroy]} \
-parallelism=#{options[:parallelism]} \
-input=false \
-refresh=true \
-var-file=#{var_file(context, environment)} \
-out=#{plan_file(context, environment)} \
#{aws_profile} #{limit(options[:limit])} \
#{context_path(context)}
TERRAFORM_COMMAND
syscall terraform_command.squeeze(' '), dryrun: dryrun
end
end
end
|