ruby-terraform 0.64.0 → 0.65.0.pre.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +102 -29
  3. data/README.md +29 -9
  4. data/Rakefile +60 -42
  5. data/bin/console +3 -3
  6. data/lib/ruby-terraform.rb +1 -1
  7. data/lib/ruby_terraform.rb +20 -55
  8. data/lib/ruby_terraform/command_line/builder.rb +55 -0
  9. data/lib/ruby_terraform/command_line/option/base.rb +24 -0
  10. data/lib/ruby_terraform/command_line/option/boolean.rb +16 -0
  11. data/lib/ruby_terraform/command_line/option/boolean_value.rb +29 -0
  12. data/lib/ruby_terraform/command_line/option/flag.rb +16 -0
  13. data/lib/ruby_terraform/command_line/option/standard.rb +40 -0
  14. data/lib/ruby_terraform/command_line/option/switch.rb +43 -0
  15. data/lib/ruby_terraform/command_line/options_factory.rb +79 -0
  16. data/lib/ruby_terraform/commands/apply.rb +18 -40
  17. data/lib/ruby_terraform/commands/base.rb +56 -20
  18. data/lib/ruby_terraform/commands/clean.rb +2 -2
  19. data/lib/ruby_terraform/commands/destroy.rb +17 -38
  20. data/lib/ruby_terraform/commands/format.rb +8 -20
  21. data/lib/ruby_terraform/commands/get.rb +11 -10
  22. data/lib/ruby_terraform/commands/import.rb +17 -36
  23. data/lib/ruby_terraform/commands/init.rb +12 -28
  24. data/lib/ruby_terraform/commands/output.rb +13 -21
  25. data/lib/ruby_terraform/commands/plan.rb +13 -36
  26. data/lib/ruby_terraform/commands/refresh.rb +13 -32
  27. data/lib/ruby_terraform/commands/remote_config.rb +9 -17
  28. data/lib/ruby_terraform/commands/show.rb +9 -16
  29. data/lib/ruby_terraform/commands/validate.rb +13 -29
  30. data/lib/ruby_terraform/commands/workspace.rb +14 -14
  31. data/lib/ruby_terraform/errors/execution_error.rb +1 -1
  32. data/lib/ruby_terraform/output.rb +15 -12
  33. data/lib/ruby_terraform/version.rb +1 -1
  34. metadata +105 -13
@@ -6,7 +6,7 @@ module RubyTerraform
6
6
  attr_reader :logger
7
7
 
8
8
  def initialize(directory: nil, logger: nil)
9
- @directory = directory ? directory : '.terraform'
9
+ @directory = directory || '.terraform'
10
10
  @logger = logger || RubyTerraform.configuration.logger
11
11
  end
12
12
 
@@ -14,7 +14,7 @@ module RubyTerraform
14
14
  directory = opts[:directory] || @directory
15
15
  begin
16
16
  logger.info "Cleaning terraform directory '#{directory}'."
17
- FileUtils.rm_r(directory, :secure => true)
17
+ FileUtils.rm_r(directory, secure: true)
18
18
  rescue Errno::ENOENT => e
19
19
  logger.error "Couldn't clean '#{directory}': #{e.message}"
20
20
  end
@@ -1,47 +1,26 @@
1
- require 'lino'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Destroy < Base
7
- def configure_command(builder, opts)
8
- directory = opts[:directory]
9
- vars = opts[:vars] || {}
10
- var_file = opts[:var_file]
11
- var_files = opts[:var_files] || []
12
- target = opts[:target]
13
- targets = opts[:targets] || []
14
- state = opts[:state]
15
- force = opts[:force]
16
- no_backup = opts[:no_backup]
17
- backup = no_backup ? '-' : opts[:backup]
18
- no_color = opts[:no_color]
19
- auto_approve = opts[:auto_approve]
6
+ def switches
7
+ %w[-backup -auto-approve -force -no-color -state -target -var -var-file]
8
+ end
9
+
10
+ def sub_commands(_values)
11
+ 'destroy'
12
+ end
13
+
14
+ def arguments(values)
15
+ values[:directory]
16
+ end
17
+
18
+ def option_default_values(_opts)
19
+ { vars: {}, var_files: [], targets: [] }
20
+ end
20
21
 
21
- builder
22
- .with_subcommand('destroy') do |sub|
23
- vars.each do |key, value|
24
- var_value = value.is_a?(String) ? value : JSON.generate(value)
25
- sub = sub.with_option(
26
- '-var', "'#{key}=#{var_value}'", separator: ' ')
27
- end
28
- sub = sub.with_option('-var-file', var_file) if var_file
29
- var_files.each do |file|
30
- sub = sub.with_option('-var-file', file)
31
- end
32
- sub = sub.with_option('-target', target) if target
33
- targets.each do |target_name|
34
- sub = sub.with_option('-target', target_name)
35
- end
36
- sub = sub.with_option('-state', state) if state
37
- sub = sub.with_option('-auto-approve', auto_approve) unless
38
- auto_approve.nil?
39
- sub = sub.with_option('-backup', backup) if backup
40
- sub = sub.with_flag('-no-color') if no_color
41
- sub = sub.with_flag('-force') if force
42
- sub
43
- end
44
- .with_argument(directory)
22
+ def option_override_values(opts)
23
+ { backup: opts[:no_backup] ? '-' : opts[:backup] }
45
24
  end
46
25
  end
47
26
  end
@@ -1,30 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
- require 'lino'
4
1
  require_relative 'base'
5
2
 
6
3
  module RubyTerraform
7
4
  module Commands
8
5
  class Format < Base
9
- def configure_command(builder, opts)
10
- directory = opts[:directory]
11
- check = opts[:check]
12
- diff = opts[:diff]
13
- list = opts[:list]
14
- no_color = opts[:no_color]
15
- recursive = opts[:recursive]
16
- write = opts[:write]
6
+ def switches
7
+ %w[-list -write -diff -check -recursive -no-color]
8
+ end
17
9
 
18
- builder.with_subcommand('fmt') do |sub|
19
- sub = sub.with_option('-list', list) if list
20
- sub = sub.with_option('-write', write) if write
10
+ def sub_commands(_values)
11
+ 'fmt'
12
+ end
21
13
 
22
- sub = sub.with_flag('-check') if check
23
- sub = sub.with_flag('-diff') if diff
24
- sub = sub.with_flag('-no-color') if no_color
25
- sub = sub.with_flag('-recursive') if recursive
26
- sub
27
- end.with_argument(directory)
14
+ def arguments(values)
15
+ values[:directory]
28
16
  end
29
17
  end
30
18
  end
@@ -1,18 +1,19 @@
1
- require 'lino'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Get < Base
7
- def configure_command(builder, opts)
8
- builder
9
- .with_subcommand('get') do |sub|
10
- sub = sub.with_option('-update', true) if opts[:update]
11
- sub = sub.with_flag('-no-color') if opts[:no_color]
12
- sub
13
- end
14
- .with_argument(opts[:directory])
6
+ def switches
7
+ %w[-update -no-color]
8
+ end
9
+
10
+ def sub_commands(_values)
11
+ 'get'
12
+ end
13
+
14
+ def arguments(values)
15
+ values[:directory]
15
16
  end
16
17
  end
17
18
  end
18
- end
19
+ end
@@ -1,45 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
- require 'lino'
4
1
  require_relative 'base'
5
2
 
6
3
  module RubyTerraform
7
4
  module Commands
8
5
  class Import < Base
9
- def configure_command(builder, opts)
10
- directory = opts[:directory]
11
- vars = opts[:vars] || {}
12
- var_file = opts[:var_file]
13
- var_files = opts[:var_files] || []
14
- no_color = opts[:no_color]
15
- no_backup = opts[:no_backup]
16
- backup = no_backup ? '-' : opts[:backup]
17
- state = opts[:state]
18
- input = opts[:input]
19
- address = opts[:address]
20
- id = opts[:id]
6
+ def switches
7
+ %w[-config -backup -input -no-color -state -var -var-file]
8
+ end
9
+
10
+ def sub_commands(_values)
11
+ 'import'
12
+ end
13
+
14
+ def arguments(values)
15
+ [values[:address], values[:id]]
16
+ end
17
+
18
+ def option_default_values(_opts)
19
+ { vars: {}, var_files: [] }
20
+ end
21
21
 
22
- builder
23
- .with_subcommand('import') do |sub|
24
- sub = sub.with_option('-config', directory)
25
- vars.each do |key, value|
26
- var_value = value.is_a?(String) ? value : JSON.generate(value)
27
- sub = sub.with_option(
28
- '-var', "'#{key}=#{var_value}'", separator: ' '
29
- )
30
- end
31
- sub = sub.with_option('-var-file', var_file) if var_file
32
- var_files.each do |file|
33
- sub = sub.with_option('-var-file', file)
34
- end
35
- sub = sub.with_option('-state', state) if state
36
- sub = sub.with_option('-input', input) if input
37
- sub = sub.with_option('-backup', backup) if backup
38
- sub = sub.with_flag('-no-color') if no_color
39
- sub
40
- end
41
- .with_argument(address)
42
- .with_argument(id)
22
+ def option_override_values(opts)
23
+ { backup: opts[:no_backup] ? '-' : opts[:backup] }
43
24
  end
44
25
  end
45
26
  end
@@ -1,39 +1,23 @@
1
- require 'lino'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Init < Base
7
- def configure_command(builder, opts)
8
- no_color = opts[:no_color]
9
- backend = opts[:backend]
10
- get = opts[:get]
11
- backend_config = opts[:backend_config] || {}
12
- source = opts[:from_module]
13
- path = opts[:path]
14
- plugin_dir = opts[:plugin_dir]
15
- force_copy = opts[:force_copy]
6
+ def switches
7
+ %w[-backend -backend-config -from-module -get -no-color -plugin-dir
8
+ -force-copy]
9
+ end
16
10
 
17
- builder = builder
18
- .with_subcommand('init') do |sub|
19
- sub = sub.with_option('-backend', backend) unless backend.nil?
20
- sub = sub.with_option('-force-copy', force_copy) unless force_copy.nil?
21
- sub = sub.with_option('-get', get) unless get.nil?
22
- sub = sub.with_option('-from-module', source) if source
23
- sub = sub.with_flag('-no-color') if no_color
24
- sub = sub.with_option('-plugin-dir', plugin_dir) unless plugin_dir.nil?
25
- backend_config.each do |key, value|
26
- sub = sub.with_option(
27
- '-backend-config',
28
- "'#{key}=#{value}'",
29
- separator: ' ')
30
- end
31
- sub
32
- end
11
+ def sub_commands(_values)
12
+ 'init'
13
+ end
33
14
 
34
- builder = builder.with_argument(path) if path
15
+ def arguments(values)
16
+ values[:path]
17
+ end
35
18
 
36
- builder
19
+ def option_default_values(_opts)
20
+ { backend_config: {} }
37
21
  end
38
22
  end
39
23
  end
@@ -1,33 +1,25 @@
1
- require 'lino'
2
1
  require 'stringio'
3
2
  require_relative 'base'
4
3
 
5
4
  module RubyTerraform
6
5
  module Commands
7
6
  class Output < Base
8
- def initialize(**kwargs)
9
- super(**kwargs)
10
- @stdout = StringIO.new unless
11
- defined?(@stdout) && @stdout.respond_to?(:string)
7
+ def initialize_command
8
+ return if defined?(@stdout) && @stdout.respond_to?(:string)
9
+
10
+ @stdout = StringIO.new
11
+ end
12
+
13
+ def switches
14
+ %w[-json -raw -no-color -state -module]
12
15
  end
13
16
 
14
- def configure_command(builder, opts)
15
- name = opts[:name]
16
- state = opts[:state]
17
- no_color = opts[:no_color]
18
- json = opts[:json]
19
- mod = opts[:module]
17
+ def sub_commands(_values)
18
+ 'output'
19
+ end
20
20
 
21
- builder = builder
22
- .with_subcommand('output') do |sub|
23
- sub = sub.with_flag('-no-color') if no_color
24
- sub = sub.with_flag('-json') if json
25
- sub = sub.with_option('-state', state) if state
26
- sub = sub.with_option('-module', mod) if mod
27
- sub
28
- end
29
- builder = builder.with_argument(name) if name
30
- builder
21
+ def arguments(values)
22
+ values[:name]
31
23
  end
32
24
 
33
25
  def do_after(opts)
@@ -1,45 +1,22 @@
1
- require 'lino'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Plan < Base
7
- def configure_command(builder, opts)
8
- directory = opts[:directory]
9
- vars = opts[:vars] || {}
10
- var_file = opts[:var_file]
11
- var_files = opts[:var_files] || []
12
- target = opts[:target]
13
- targets = opts[:targets] || []
14
- state = opts[:state]
15
- plan = opts[:plan]
16
- input = opts[:input]
17
- destroy = opts[:destroy]
18
- no_color = opts[:no_color]
6
+ def switches
7
+ %w[-destroy -input -no-color -out -state -target -var -var-file]
8
+ end
9
+
10
+ def sub_commands(_values)
11
+ 'plan'
12
+ end
13
+
14
+ def option_default_values(_opts)
15
+ { vars: {}, var_files: [], targets: [] }
16
+ end
19
17
 
20
- builder
21
- .with_subcommand('plan') do |sub|
22
- vars.each do |key, value|
23
- var_value = value.is_a?(String) ? value : JSON.generate(value)
24
- sub = sub.with_option(
25
- '-var', "'#{key}=#{var_value}'", separator: ' ')
26
- end
27
- sub = sub.with_option('-var-file', var_file) if var_file
28
- var_files.each do |file|
29
- sub = sub.with_option('-var-file', file)
30
- end
31
- sub = sub.with_option('-target', target) if target
32
- targets.each do |file|
33
- sub = sub.with_option('-target', file)
34
- end
35
- sub = sub.with_option('-state', state) if state
36
- sub = sub.with_option('-out', plan) if plan
37
- sub = sub.with_option('-input', input) if input
38
- sub = sub.with_flag('-destroy') if destroy
39
- sub = sub.with_flag('-no-color') if no_color
40
- sub
41
- end
42
- .with_argument(directory)
18
+ def arguments(values)
19
+ values[:directory]
43
20
  end
44
21
  end
45
22
  end
@@ -1,41 +1,22 @@
1
- require 'lino'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Refresh < Base
7
- def configure_command(builder, opts)
8
- directory = opts[:directory]
9
- vars = opts[:vars] || {}
10
- var_file = opts[:var_file]
11
- var_files = opts[:var_files] || []
12
- state = opts[:state]
13
- input = opts[:input]
14
- target = opts[:target]
15
- targets = opts[:targets] || []
16
- no_color = opts[:no_color]
6
+ def switches
7
+ %w[-input -no-color -state -target -var -var-file] + super
8
+ end
9
+
10
+ def sub_commands(_values)
11
+ 'refresh'
12
+ end
13
+
14
+ def arguments(values)
15
+ values[:directory]
16
+ end
17
17
 
18
- builder
19
- .with_subcommand('refresh') do |sub|
20
- vars.each do |key, value|
21
- var_value = value.is_a?(String) ? value : JSON.generate(value)
22
- sub = sub.with_option(
23
- '-var', "'#{key}=#{var_value}'", separator: ' ')
24
- end
25
- sub = sub.with_option('-var-file', var_file) if var_file
26
- var_files.each do |file|
27
- sub = sub.with_option('-var-file', file)
28
- end
29
- sub = sub.with_option('-state', state) if state
30
- sub = sub.with_option('-input', input) if input
31
- sub = sub.with_option('-target', target) if target
32
- targets.each do |target_name|
33
- sub = sub.with_option('-target', target_name)
34
- end
35
- sub = sub.with_flag('-no-color') if no_color
36
- sub
37
- end
38
- .with_argument(directory)
18
+ def option_default_values(_opts)
19
+ { vars: {}, var_files: [], targets: [] }
39
20
  end
40
21
  end
41
22
  end
@@ -1,27 +1,19 @@
1
- require 'lino'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class RemoteConfig < Base
7
- def configure_command(builder, opts)
8
- backend = opts[:backend]
9
- no_color = opts[:no_color]
10
- backend_config = opts[:backend_config] || {}
6
+ def switches
7
+ %w[-backend -backend-config -no-color]
8
+ end
11
9
 
12
- builder
13
- .with_subcommand('remote')
14
- .with_subcommand('config') do |sub|
15
- sub = sub.with_option('-backend', backend) if backend
16
- backend_config.each do |key, value|
17
- sub = sub.with_option(
18
- '-backend-config', "'#{key}=#{value}'", separator: ' ')
19
- end
10
+ def sub_commands(_values)
11
+ %w[remote config]
12
+ end
20
13
 
21
- sub = sub.with_flag('-no-color') if no_color
22
- sub
23
- end
14
+ def option_default_values(_opts)
15
+ { backend_config: {} }
24
16
  end
25
17
  end
26
18
  end
27
- end
19
+ end