ruby-terraform 0.65.0.pre.1 → 0.65.0.pre.6
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +67 -33
- data/README.md +29 -9
- data/Rakefile +60 -42
- data/bin/console +3 -3
- data/lib/ruby-terraform.rb +1 -1
- data/lib/ruby_terraform.rb +20 -55
- data/lib/ruby_terraform/commands/apply.rb +18 -39
- data/lib/ruby_terraform/commands/base.rb +59 -18
- data/lib/ruby_terraform/commands/clean.rb +2 -2
- data/lib/ruby_terraform/commands/destroy.rb +17 -37
- data/lib/ruby_terraform/commands/format.rb +8 -19
- data/lib/ruby_terraform/commands/get.rb +11 -9
- data/lib/ruby_terraform/commands/import.rb +17 -36
- data/lib/ruby_terraform/commands/init.rb +12 -27
- data/lib/ruby_terraform/commands/output.rb +13 -20
- data/lib/ruby_terraform/commands/plan.rb +13 -36
- data/lib/ruby_terraform/commands/refresh.rb +13 -32
- data/lib/ruby_terraform/commands/remote_config.rb +9 -16
- data/lib/ruby_terraform/commands/show.rb +9 -15
- data/lib/ruby_terraform/commands/validate.rb +13 -29
- data/lib/ruby_terraform/commands/workspace.rb +14 -13
- data/lib/ruby_terraform/errors/execution_error.rb +1 -1
- data/lib/ruby_terraform/options/base.rb +22 -0
- data/lib/ruby_terraform/options/boolean.rb +14 -0
- data/lib/ruby_terraform/options/factory.rb +116 -0
- data/lib/ruby_terraform/options/flag.rb +14 -0
- data/lib/ruby_terraform/options/standard.rb +39 -0
- data/lib/ruby_terraform/options/switch.rb +41 -0
- data/lib/ruby_terraform/options/values/boolean.rb +29 -0
- data/lib/ruby_terraform/output.rb +15 -11
- data/lib/ruby_terraform/version.rb +1 -1
- metadata +63 -14
@@ -1,45 +1,22 @@
|
|
1
|
-
require 'json'
|
2
1
|
require_relative 'base'
|
3
2
|
|
4
3
|
module RubyTerraform
|
5
4
|
module Commands
|
6
5
|
class Plan < Base
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
+
%w[plan]
|
12
|
+
end
|
13
|
+
|
14
|
+
def arguments(values)
|
15
|
+
[values[:directory]]
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
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 option_default_values(_opts)
|
19
|
+
{ vars: {}, var_files: [], targets: [] }
|
43
20
|
end
|
44
21
|
end
|
45
22
|
end
|
@@ -1,41 +1,22 @@
|
|
1
|
-
require 'json'
|
2
1
|
require_relative 'base'
|
3
2
|
|
4
3
|
module RubyTerraform
|
5
4
|
module Commands
|
6
5
|
class Refresh < Base
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
def switches
|
7
|
+
%w[-input -no-color -state -target -var -var-file]
|
8
|
+
end
|
9
|
+
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[refresh]
|
12
|
+
end
|
13
|
+
|
14
|
+
def arguments(values)
|
15
|
+
[values[:directory]]
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
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
|
@@ -3,24 +3,17 @@ require_relative 'base'
|
|
3
3
|
module RubyTerraform
|
4
4
|
module Commands
|
5
5
|
class RemoteConfig < Base
|
6
|
-
def
|
7
|
-
backend
|
8
|
-
|
9
|
-
backend_config = opts[:backend_config] || {}
|
6
|
+
def switches
|
7
|
+
%w[-backend -backend-config -no-color]
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
end
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[remote config]
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
14
|
+
def option_default_values(_opts)
|
15
|
+
{ backend_config: {} }
|
23
16
|
end
|
24
17
|
end
|
25
18
|
end
|
26
|
-
end
|
19
|
+
end
|
@@ -1,24 +1,18 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative 'base'
|
4
2
|
|
5
3
|
module RubyTerraform
|
6
4
|
module Commands
|
7
5
|
class Show < Base
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
def switches
|
7
|
+
%w[-json -no-color -module-depth]
|
8
|
+
end
|
9
|
+
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[show]
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
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)
|
14
|
+
def arguments(values)
|
15
|
+
[values[:path] || values[:directory]]
|
22
16
|
end
|
23
17
|
end
|
24
18
|
end
|
@@ -1,38 +1,22 @@
|
|
1
|
-
require 'json'
|
2
1
|
require_relative 'base'
|
3
2
|
|
4
3
|
module RubyTerraform
|
5
4
|
module Commands
|
6
5
|
class Validate < Base
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
def switches
|
7
|
+
%w[-json -no-color -var -var-file -state -check-variables] + super
|
8
|
+
end
|
9
|
+
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[validate]
|
12
|
+
end
|
13
|
+
|
14
|
+
def arguments(values)
|
15
|
+
[values[:directory]]
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
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
|
-
end
|
24
|
-
sub = sub.with_option('-var-file', var_file) if var_file
|
25
|
-
var_files.each do |file|
|
26
|
-
sub = sub.with_option('-var-file', file)
|
27
|
-
end
|
28
|
-
sub = sub.with_option('-state', state) if state
|
29
|
-
sub = sub.with_option('-check-variables', check_variables) unless
|
30
|
-
check_variables.nil?
|
31
|
-
sub = sub.with_flag('-no-color') if no_color
|
32
|
-
sub = sub.with_flag('-json') if json_format
|
33
|
-
sub
|
34
|
-
end
|
35
|
-
.with_argument(directory)
|
18
|
+
def option_default_values(_opts)
|
19
|
+
{ vars: {}, var_files: [] }
|
36
20
|
end
|
37
21
|
end
|
38
22
|
end
|
@@ -3,21 +3,22 @@ require_relative 'base'
|
|
3
3
|
module RubyTerraform
|
4
4
|
module Commands
|
5
5
|
class Workspace < Base
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def sub_commands(values)
|
7
|
+
commands = ['workspace', values[:operation]]
|
8
|
+
if values[:workspace] && values[:operation] != 'list'
|
9
|
+
commands << values[:workspace]
|
10
|
+
else
|
11
|
+
commands
|
12
|
+
end
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def arguments(values)
|
16
|
+
[values[:directory]]
|
17
|
+
end
|
18
18
|
|
19
|
-
|
19
|
+
def option_default_values(_opts)
|
20
|
+
{ directory: nil, operation: 'list', workspace: nil }
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
23
|
-
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RubyTerraform
|
2
|
+
module Options
|
3
|
+
class Base
|
4
|
+
def initialize(switch, value)
|
5
|
+
@switch = switch
|
6
|
+
coerce_value(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply(_builder)
|
10
|
+
raise 'not implemented'
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :switch, :value
|
16
|
+
|
17
|
+
def coerce_value(value)
|
18
|
+
@value = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require_relative 'switch'
|
2
|
+
require_relative 'boolean'
|
3
|
+
require_relative 'flag'
|
4
|
+
require_relative 'standard'
|
5
|
+
|
6
|
+
module RubyTerraform
|
7
|
+
module Options
|
8
|
+
class Factory
|
9
|
+
PLURAL_SWITCHES =
|
10
|
+
Set.new(
|
11
|
+
%w[
|
12
|
+
-var
|
13
|
+
-target
|
14
|
+
-var-file
|
15
|
+
]
|
16
|
+
).freeze
|
17
|
+
|
18
|
+
BOOLEAN_SWITCHES =
|
19
|
+
Set.new(
|
20
|
+
%w[
|
21
|
+
-auto-approve
|
22
|
+
-backend
|
23
|
+
-get
|
24
|
+
-get-plugins
|
25
|
+
-input
|
26
|
+
-list
|
27
|
+
-lock
|
28
|
+
-refresh
|
29
|
+
-upgrade
|
30
|
+
-verify-plugins
|
31
|
+
-write
|
32
|
+
]
|
33
|
+
).freeze
|
34
|
+
|
35
|
+
FLAG_SWITCHES =
|
36
|
+
Set.new(
|
37
|
+
%w[
|
38
|
+
-allow-missing
|
39
|
+
-allow-missing-config
|
40
|
+
-check
|
41
|
+
-compact-warnings
|
42
|
+
-destroy
|
43
|
+
-detailed-exitcode
|
44
|
+
-diff
|
45
|
+
-draw-cycles
|
46
|
+
-force
|
47
|
+
-force-copy
|
48
|
+
-ignore-remote-version
|
49
|
+
-json
|
50
|
+
-no-color
|
51
|
+
-raw
|
52
|
+
-reconfigure
|
53
|
+
-recursive
|
54
|
+
-update
|
55
|
+
]
|
56
|
+
).freeze
|
57
|
+
|
58
|
+
OVERRIDE_SWITCHES =
|
59
|
+
{
|
60
|
+
config: :directory,
|
61
|
+
out: :plan
|
62
|
+
}.freeze
|
63
|
+
|
64
|
+
def self.from(values, switches)
|
65
|
+
new(values, switches).from
|
66
|
+
end
|
67
|
+
|
68
|
+
private_class_method :new
|
69
|
+
|
70
|
+
def initialize(values, switches)
|
71
|
+
@switches = switches.map { |switch| Switch.new(switch) }
|
72
|
+
@values = values
|
73
|
+
end
|
74
|
+
|
75
|
+
def from
|
76
|
+
switches.each_with_object([]) do |switch, options|
|
77
|
+
options.append(*options_from_switch(switch))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
attr_reader :switches, :values
|
84
|
+
|
85
|
+
def options_from_switch(switch)
|
86
|
+
return plural_options(switch) if PLURAL_SWITCHES.include?(switch)
|
87
|
+
return boolean_option(switch) if BOOLEAN_SWITCHES.include?(switch)
|
88
|
+
return flag_option(switch) if FLAG_SWITCHES.include?(switch)
|
89
|
+
return override_option(switch) if OVERRIDE_SWITCHES.key?(switch.as_key)
|
90
|
+
|
91
|
+
standard_option(switch, switch.as_key)
|
92
|
+
end
|
93
|
+
|
94
|
+
def boolean_option(switch)
|
95
|
+
[Boolean.new(switch.to_s, values[switch.as_key])]
|
96
|
+
end
|
97
|
+
|
98
|
+
def flag_option(switch)
|
99
|
+
[Flag.new(switch.to_s, values[switch.as_key])]
|
100
|
+
end
|
101
|
+
|
102
|
+
def standard_option(switch, hash_key)
|
103
|
+
[Standard.new(switch.to_s, values[hash_key])]
|
104
|
+
end
|
105
|
+
|
106
|
+
def override_option(switch)
|
107
|
+
standard_option(switch, OVERRIDE_SWITCHES[switch.as_key])
|
108
|
+
end
|
109
|
+
|
110
|
+
def plural_options(switch)
|
111
|
+
standard_option(switch.to_s, switch.as_key) +
|
112
|
+
standard_option(switch.to_s, switch.as_plural_key)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|