Class: Terraspace::Terraform::Args::Thor
- Inherits:
-
Object
- Object
- Terraspace::Terraform::Args::Thor
- Extended by:
- Memoist
- Defined in:
- lib/terraspace/terraform/args/thor.rb
Class Method Summary collapse
-
.terraform_init_log(mod_name) ⇒ Object
Use different tmp log file in case uses run terraspace up in 2 terminals at the same time.
Instance Method Summary collapse
- #apply_args ⇒ Object
- #args ⇒ Object
- #auto_approve_arg ⇒ Object
- #destroy_args ⇒ Object
- #force_unlock_args ⇒ Object
- #import_args ⇒ Object
- #init_args ⇒ Object
-
#initialize(mod, name, options = {}) ⇒ Thor
constructor
A new instance of Thor.
- #input_option ⇒ Object
- #out_option ⇒ Object
- #output_args ⇒ Object
- #plan_args ⇒ Object
- #show_args ⇒ Object
-
#straight_delegate_args? ⇒ Boolean
delegate args straight through for special commands, currently state seems to be the only case.
- #taint_args ⇒ Object
- #untaint_args ⇒ Object
Constructor Details
#initialize(mod, name, options = {}) ⇒ Thor
Returns a new instance of Thor.
7 8 9 10 |
# File 'lib/terraspace/terraform/args/thor.rb', line 7 def initialize(mod, name, ={}) @mod, @name, @options = mod, name.underscore, @quiet = @options[:quiet].nil? ? true : @options[:quiet] end |
Class Method Details
.terraform_init_log(mod_name) ⇒ Object
Use different tmp log file in case uses run terraspace up in 2 terminals at the same time
Log for init is in /tmp because using shell >> redirection It requires full path since we’re running terraform within the .terraspace-cache folder This keeps the printed command shorter:
=> terraform init -get >> /tmp/terraspace/log/init/demo.log
147 148 149 |
# File 'lib/terraspace/terraform/args/thor.rb', line 147 def terraform_init_log(mod_name) "#{Terraspace.tmp_root}/log/init/#{mod_name}.log" end |
Instance Method Details
#apply_args ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/terraspace/terraform/args/thor.rb', line 40 def apply_args args = auto_approve_arg var_files = @options[:var_files] if var_files var_files.each do |file| copy_to_cache(file) end args << var_files.map { |f| "-var-file #{f}" }.join(' ') end args << input_option # must be at the end plan = .plan if plan copy_to_cache(plan) args << " #{plan}" end args end |
#args ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/terraspace/terraform/args/thor.rb', line 12 def args # https://terraspace.cloud/docs/ci-automation/ ENV['TF_IN_AUTOMATION'] = '1' if @options[:auto] args = [] if straight_delegate_args? args += @options[:rest] args.flatten! end args_meth = "#{@name}_args".gsub(' ', '_') # IE: apply_args, init_args if respond_to?(args_meth) args += send(args_meth) end args end |
#auto_approve_arg ⇒ Object
132 133 134 |
# File 'lib/terraspace/terraform/args/thor.rb', line 132 def auto_approve_arg @options[:yes] || @options[:auto] ? ["-auto-approve"] : [] end |
#destroy_args ⇒ Object
116 117 118 |
# File 'lib/terraspace/terraform/args/thor.rb', line 116 def destroy_args auto_approve_arg end |
#force_unlock_args ⇒ Object
36 37 38 |
# File 'lib/terraspace/terraform/args/thor.rb', line 36 def force_unlock_args [" -force #{@options[:lock_id]}"] end |
#import_args ⇒ Object
120 121 122 |
# File 'lib/terraspace/terraform/args/thor.rb', line 120 def import_args [@options[:addr], @options[:id]] end |
#init_args ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/terraspace/terraform/args/thor.rb', line 70 def init_args args = "-get" args << input_option args << " -reconfigure" if @options[:reconfigure] # must be at the end if @quiet log_path = self.class.terraform_init_log(@mod.name) FileUtils.mkdir_p(File.dirname(log_path)) args << " >> #{log_path}" end [args] end |
#input_option ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/terraspace/terraform/args/thor.rb', line 61 def input_option option = if @options[:auto] "false" else @options[:input] ? @options[:input] : "false" end " -input=#{option}" end |
#out_option ⇒ Object
100 101 102 103 104 |
# File 'lib/terraspace/terraform/args/thor.rb', line 100 def out_option out = .out FileUtils.mkdir_p(File.dirname("#{@mod.cache_dir}/#{out}")) out end |
#output_args ⇒ Object
84 85 86 87 88 |
# File 'lib/terraspace/terraform/args/thor.rb', line 84 def output_args args = [] args << "> #{out_option}" if out_option args end |
#plan_args ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/terraspace/terraform/args/thor.rb', line 90 def plan_args args = [] args << input_option args << "-destroy" if @options[:destroy] args << "-out #{out_option}" if out_option # Note: based on the expand.out will run an internal hook to copy plan # file back up to the root project folder for use. Think this is convenient and expected behavior. args end |
#show_args ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/terraspace/terraform/args/thor.rb', line 106 def show_args args = [] plan = .plan if plan copy_to_cache(.plan) args << " #{.plan}" # terraform show /path/to/plan end args end |
#straight_delegate_args? ⇒ Boolean
delegate args straight through for special commands, currently state seems to be the only case
32 33 34 |
# File 'lib/terraspace/terraform/args/thor.rb', line 32 def straight_delegate_args? @name.include?("state") # IE: "state list", "state pull", "state show" end |
#taint_args ⇒ Object
124 125 126 |
# File 'lib/terraspace/terraform/args/thor.rb', line 124 def taint_args [@options[:addr]] end |
#untaint_args ⇒ Object
128 129 130 |
# File 'lib/terraspace/terraform/args/thor.rb', line 128 def untaint_args [@options[:addr]] end |