ruby-terraform 0.65.0.pre.4 → 0.65.0.pre.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +8 -5
  4. data/Rakefile +7 -3
  5. data/bin/console +1 -0
  6. data/lib/ruby-terraform.rb +2 -0
  7. data/lib/ruby_terraform.rb +5 -2
  8. data/lib/ruby_terraform/commands.rb +2 -0
  9. data/lib/ruby_terraform/commands/apply.rb +32 -40
  10. data/lib/ruby_terraform/commands/base.rb +59 -18
  11. data/lib/ruby_terraform/commands/clean.rb +2 -0
  12. data/lib/ruby_terraform/commands/destroy.rb +28 -38
  13. data/lib/ruby_terraform/commands/format.rb +15 -17
  14. data/lib/ruby_terraform/commands/get.rb +15 -8
  15. data/lib/ruby_terraform/commands/import.rb +25 -34
  16. data/lib/ruby_terraform/commands/init.rb +21 -34
  17. data/lib/ruby_terraform/commands/output.rb +23 -22
  18. data/lib/ruby_terraform/commands/plan.rb +24 -37
  19. data/lib/ruby_terraform/commands/refresh.rb +22 -33
  20. data/lib/ruby_terraform/commands/remote_config.rb +14 -16
  21. data/lib/ruby_terraform/commands/show.rb +13 -13
  22. data/lib/ruby_terraform/commands/validate.rb +22 -30
  23. data/lib/ruby_terraform/commands/workspace.rb +15 -10
  24. data/lib/ruby_terraform/errors.rb +2 -0
  25. data/lib/ruby_terraform/errors/execution_error.rb +2 -0
  26. data/lib/ruby_terraform/options.rb +7 -0
  27. data/lib/ruby_terraform/options/factory.rb +118 -0
  28. data/lib/ruby_terraform/options/name.rb +45 -0
  29. data/lib/ruby_terraform/options/types/base.rb +26 -0
  30. data/lib/ruby_terraform/options/types/boolean.rb +18 -0
  31. data/lib/ruby_terraform/options/types/flag.rb +18 -0
  32. data/lib/ruby_terraform/options/types/standard.rb +43 -0
  33. data/lib/ruby_terraform/options/values/boolean.rb +31 -0
  34. data/lib/ruby_terraform/output.rb +17 -11
  35. data/lib/ruby_terraform/version.rb +3 -1
  36. data/ruby_terraform.gemspec +58 -0
  37. metadata +27 -4
@@ -1,16 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module RubyTerraform
4
6
  module Commands
5
7
  class Get < Base
6
- def configure_command(builder, opts)
7
- builder
8
- .with_subcommand('get') do |sub|
9
- sub = sub.with_option('-update', true) if opts[:update]
10
- sub = sub.with_flag('-no-color') if opts[:no_color]
11
- sub
12
- end
13
- .with_argument(opts[:directory])
8
+ def options
9
+ %w[
10
+ -no-color
11
+ -update
12
+ ]
13
+ end
14
+
15
+ def subcommands(_parameters)
16
+ %w[get]
17
+ end
18
+
19
+ def arguments(parameters)
20
+ [parameters[:directory]]
14
21
  end
15
22
  end
16
23
  end
@@ -1,45 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
3
  require_relative 'base'
5
4
 
6
5
  module RubyTerraform
7
6
  module Commands
8
7
  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]
8
+ def options
9
+ %w[
10
+ -config
11
+ -backup
12
+ -input
13
+ -no-color
14
+ -state
15
+ -var
16
+ -var-file
17
+ ]
18
+ end
19
+
20
+ def subcommands(_parameters)
21
+ %w[import]
22
+ end
23
+
24
+ def arguments(parameters)
25
+ [parameters[:address], parameters[:id]]
26
+ end
27
+
28
+ def parameter_defaults(_parameters)
29
+ { vars: {}, var_files: [] }
30
+ end
21
31
 
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)
32
+ def parameter_overrides(parameters)
33
+ { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
43
34
  end
44
35
  end
45
36
  end
@@ -1,45 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module RubyTerraform
4
6
  module Commands
5
7
  class Init < Base
6
- def configure_command(builder, opts)
7
- no_color = opts[:no_color]
8
- backend = opts[:backend]
9
- get = opts[:get]
10
- backend_config = opts[:backend_config] || {}
11
- source = opts[:from_module]
12
- path = opts[:path]
13
- plugin_dir = opts[:plugin_dir]
14
- force_copy = opts[:force_copy]
8
+ def options
9
+ %w[
10
+ -backend
11
+ -backend-config
12
+ -force-copy
13
+ -from-module
14
+ -get
15
+ -no-color
16
+ -plugin-dir
17
+ ]
18
+ end
15
19
 
16
- builder = builder
17
- .with_subcommand('init') do |sub|
18
- sub = sub.with_option('-backend', backend) unless backend.nil?
19
- unless force_copy.nil?
20
- sub = sub.with_option('-force-copy',
21
- force_copy)
22
- end
23
- sub = sub.with_option('-get', get) unless get.nil?
24
- sub = sub.with_option('-from-module', source) if source
25
- sub = sub.with_flag('-no-color') if no_color
26
- unless plugin_dir.nil?
27
- sub = sub.with_option('-plugin-dir',
28
- plugin_dir)
29
- end
30
- backend_config.each do |key, value|
31
- sub = sub.with_option(
32
- '-backend-config',
33
- "'#{key}=#{value}'",
34
- separator: ' '
35
- )
36
- end
37
- sub
38
- end
20
+ def subcommands(_parameters)
21
+ %w[init]
22
+ end
39
23
 
40
- builder = builder.with_argument(path) if path
24
+ def arguments(parameters)
25
+ [parameters[:path]]
26
+ end
41
27
 
42
- builder
28
+ def parameter_defaults(_parameters)
29
+ { backend_config: {} }
43
30
  end
44
31
  end
45
32
  end
@@ -1,37 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
  require_relative 'base'
3
5
 
4
6
  module RubyTerraform
5
7
  module Commands
6
8
  class Output < Base
7
- def initialize(**kwargs)
8
- super(**kwargs)
9
- @stdout = StringIO.new unless
10
- defined?(@stdout) && @stdout.respond_to?(:string)
9
+ def initialize_command
10
+ return if defined?(@stdout) && @stdout.respond_to?(:string)
11
+
12
+ @stdout = StringIO.new
11
13
  end
12
14
 
13
- def configure_command(builder, opts)
14
- name = opts[:name]
15
- state = opts[:state]
16
- no_color = opts[:no_color]
17
- json = opts[:json]
18
- mod = opts[:module]
15
+ def options
16
+ %w[
17
+ -json
18
+ -module
19
+ -no-color
20
+ -raw
21
+ -state
22
+ ]
23
+ end
24
+
25
+ def subcommands(_parameters)
26
+ %w[output]
27
+ end
19
28
 
20
- builder = builder
21
- .with_subcommand('output') do |sub|
22
- sub = sub.with_flag('-no-color') if no_color
23
- sub = sub.with_flag('-json') if json
24
- sub = sub.with_option('-state', state) if state
25
- sub = sub.with_option('-module', mod) if mod
26
- sub
27
- end
28
- builder = builder.with_argument(name) if name
29
- builder
29
+ def arguments(parameters)
30
+ [parameters[:name]]
30
31
  end
31
32
 
32
- def do_after(opts)
33
+ def do_after(parameters)
33
34
  result = stdout.string
34
- opts[:name] ? result.chomp : result
35
+ parameters[:name] ? result.chomp : result
35
36
  end
36
37
  end
37
38
  end
@@ -1,46 +1,33 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
2
3
  require_relative 'base'
3
4
 
4
5
  module RubyTerraform
5
6
  module Commands
6
7
  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]
8
+ def options
9
+ %w[
10
+ -destroy
11
+ -input
12
+ -no-color
13
+ -out
14
+ -state
15
+ -target
16
+ -var
17
+ -var-file
18
+ ]
19
+ end
20
+
21
+ def subcommands(_parameters)
22
+ %w[plan]
23
+ end
24
+
25
+ def arguments(parameters)
26
+ [parameters[:directory]]
27
+ end
19
28
 
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
- )
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 |file|
34
- sub = sub.with_option('-target', file)
35
- end
36
- sub = sub.with_option('-state', state) if state
37
- sub = sub.with_option('-out', plan) if plan
38
- sub = sub.with_option('-input', input) if input
39
- sub = sub.with_flag('-destroy') if destroy
40
- sub = sub.with_flag('-no-color') if no_color
41
- sub
42
- end
43
- .with_argument(directory)
29
+ def parameter_defaults(_parameters)
30
+ { vars: {}, var_files: [], targets: [] }
44
31
  end
45
32
  end
46
33
  end
@@ -1,42 +1,31 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
2
3
  require_relative 'base'
3
4
 
4
5
  module RubyTerraform
5
6
  module Commands
6
7
  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]
8
+ def options
9
+ %w[
10
+ -input
11
+ -no-color
12
+ -state
13
+ -target
14
+ -var
15
+ -var-file
16
+ ]
17
+ end
18
+
19
+ def subcommands(_parameters)
20
+ %w[refresh]
21
+ end
22
+
23
+ def arguments(parameters)
24
+ [parameters[:directory]]
25
+ end
17
26
 
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
- )
25
- end
26
- sub = sub.with_option('-var-file', var_file) if var_file
27
- var_files.each do |file|
28
- sub = sub.with_option('-var-file', file)
29
- end
30
- sub = sub.with_option('-state', state) if state
31
- sub = sub.with_option('-input', input) if input
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_flag('-no-color') if no_color
37
- sub
38
- end
39
- .with_argument(directory)
27
+ def parameter_defaults(_parameters)
28
+ { vars: {}, var_files: [], targets: [] }
40
29
  end
41
30
  end
42
31
  end
@@ -1,26 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module RubyTerraform
4
6
  module Commands
5
7
  class RemoteConfig < Base
6
- def configure_command(builder, opts)
7
- backend = opts[:backend]
8
- no_color = opts[:no_color]
9
- backend_config = opts[:backend_config] || {}
8
+ def options
9
+ %w[
10
+ -backend
11
+ -backend-config
12
+ -no-color
13
+ ]
14
+ end
10
15
 
11
- builder
12
- .with_subcommand('remote')
13
- .with_subcommand('config') do |sub|
14
- sub = sub.with_option('-backend', backend) if backend
15
- backend_config.each do |key, value|
16
- sub = sub.with_option(
17
- '-backend-config', "'#{key}=#{value}'", separator: ' '
18
- )
19
- end
16
+ def subcommands(_parameters)
17
+ %w[remote config]
18
+ end
20
19
 
21
- sub = sub.with_flag('-no-color') if no_color
22
- sub
23
- end
20
+ def parameter_defaults(_parameters)
21
+ { backend_config: {} }
24
22
  end
25
23
  end
26
24
  end
@@ -5,20 +5,20 @@ require_relative 'base'
5
5
  module RubyTerraform
6
6
  module Commands
7
7
  class Show < Base
8
- def configure_command(builder, opts)
9
- path = opts[:path] || opts[:directory]
10
- json_format = opts[:json]
11
- no_color = opts[:no_color]
12
- module_depth = opts[:module_depth]
8
+ def options
9
+ %w[
10
+ -json
11
+ -module-depth
12
+ -no-color
13
+ ]
14
+ end
15
+
16
+ def subcommands(_parameters)
17
+ %w[show]
18
+ end
13
19
 
14
- builder
15
- .with_subcommand('show') do |sub|
16
- sub = sub.with_option('-module-depth', module_depth) if module_depth
17
- sub = sub.with_flag('-no-color') if no_color
18
- sub = sub.with_flag('-json') if json_format
19
- sub
20
- end
21
- .with_argument(path)
20
+ def arguments(parameters)
21
+ [parameters[:path] || parameters[:directory]]
22
22
  end
23
23
  end
24
24
  end
@@ -1,39 +1,31 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
2
3
  require_relative 'base'
3
4
 
4
5
  module RubyTerraform
5
6
  module Commands
6
7
  class Validate < 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
- check_variables = opts[:check_variables]
14
- no_color = opts[:no_color]
15
- json_format = opts[:json]
8
+ def options
9
+ %w[
10
+ -check-variables
11
+ -json
12
+ -no-color
13
+ -state
14
+ -var
15
+ -var-file
16
+ ]
17
+ end
18
+
19
+ def subcommands(_parameters)
20
+ %w[validate]
21
+ end
22
+
23
+ def arguments(parameters)
24
+ [parameters[:directory]]
25
+ end
16
26
 
17
- builder
18
- .with_subcommand('validate') do |sub|
19
- vars.each do |key, value|
20
- var_value = value.is_a?(String) ? value : JSON.generate(value)
21
- sub = sub.with_option(
22
- '-var', "'#{key}=#{var_value}'", separator: ' '
23
- )
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('-check-variables', check_variables) unless
31
- check_variables.nil?
32
- sub = sub.with_flag('-no-color') if no_color
33
- sub = sub.with_flag('-json') if json_format
34
- sub
35
- end
36
- .with_argument(directory)
27
+ def parameter_defaults(_parameters)
28
+ { vars: {}, var_files: [] }
37
29
  end
38
30
  end
39
31
  end