Class: Terraspace::Terraform::Args::Default
- Inherits:
-
Object
- Object
- Terraspace::Terraform::Args::Default
- Defined in:
- lib/terraspace/terraform/args/default.rb
Constant Summary collapse
- @@terraform_init_log =
Use different tmp log file in case uses run terraspace up in 2 terminals at the same time
nil
Class Method Summary collapse
Instance Method Summary collapse
- #apply_args ⇒ Object
- #args ⇒ Object
- #auto_approve_arg ⇒ Object
- #destroy_args ⇒ Object
- #expanded_out ⇒ Object
- #init_args ⇒ Object
-
#initialize(mod, name, options = {}) ⇒ Default
constructor
A new instance of Default.
- #output_args ⇒ Object
- #plan_args ⇒ Object
Constructor Details
#initialize(mod, name, options = {}) ⇒ Default
Returns a new instance of Default.
5 6 7 8 |
# File 'lib/terraspace/terraform/args/default.rb', line 5 def initialize(mod, name, ={}) @mod, @name, @options = mod, name, @quiet = @options[:quiet].nil? ? true : @options[:quiet] end |
Class Method Details
.terraform_init_log ⇒ Object
103 104 105 106 107 |
# File 'lib/terraspace/terraform/args/default.rb', line 103 def terraform_init_log return @@terraform_init_log if @@terraform_init_log basename = File.basename(Tempfile.new('terraform-init').path) @@terraform_init_log = "#{Terraspace.tmp_root}/out/#{basename}.out" end |
Instance Method Details
#apply_args ⇒ Object
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 |
# File 'lib/terraspace/terraform/args/default.rb', line 22 def apply_args args = auto_approve_arg var_files = @options[:var_files] if var_files args << var_files.map { |f| "-var-file #{Dir.pwd}/#{f}" }.join(' ') end if @options[:auto] && @options[:input].nil? args << " -input=false" end unless @options[:input].nil? input = @options[:input] ? "true" : "false" args << " -input=#{input}" # = sign required for apply when there's a plan at the end. so input=false works input false doesnt end # must be at the end plan = @options[:plan] if plan if plan.starts_with?('/') src = plan dest = src else src = "#{Dir.pwd}/#{plan}" dest = "#{@mod.cache_dir}/#{File.basename(src)}" end FileUtils.cp(src, dest) args << " #{dest}" end args end |
#args ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/terraspace/terraform/args/default.rb', line 10 def args # https://terraspace.cloud/docs/ci-automation/ ENV['TF_IN_AUTOMATION'] = '1' if @options[:auto] if %w[apply destroy init output plan].include?(@name) meth = "#{@name}_args" send(meth) else [] end end |
#auto_approve_arg ⇒ Object
96 97 98 |
# File 'lib/terraspace/terraform/args/default.rb', line 96 def auto_approve_arg @options[:yes] || @options[:auto] ? ["-auto-approve"] : [] end |
#destroy_args ⇒ Object
92 93 94 |
# File 'lib/terraspace/terraform/args/default.rb', line 92 def destroy_args auto_approve_arg end |
#expanded_out ⇒ Object
87 88 89 90 |
# File 'lib/terraspace/terraform/args/default.rb', line 87 def out = @options[:out] out.starts_with?('/') ? out : "#{Dir.pwd}/#{out}" end |
#init_args ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/terraspace/terraform/args/default.rb', line 53 def init_args args = "-get" if @options[:auto] && @options[:input].nil? args << " -input=false" end unless @options[:input].nil? input = @options[:input] ? "true" : "false" args << " -input=#{input}" end args << " -reconfigure" if @options[:reconfigure] # must be at the end if @quiet && !ENV['TS_INIT_LOUD'] out_path = self.class.terraform_init_log FileUtils.mkdir_p(File.dirname(out_path)) args << " > #{out_path}" end [args] end |
#output_args ⇒ Object
80 81 82 83 84 85 |
# File 'lib/terraspace/terraform/args/default.rb', line 80 def output_args args = [] args << "-json" if @options[:format] == "json" args << "> #{}" if @options[:out] args end |
#plan_args ⇒ Object
74 75 76 77 78 |
# File 'lib/terraspace/terraform/args/default.rb', line 74 def plan_args args = [] args << "-out #{}" if @options[:out] args end |