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,48 +1,27 @@
|
|
1
|
-
require 'json'
|
2
1
|
require_relative 'base'
|
3
2
|
|
4
3
|
module RubyTerraform
|
5
4
|
module Commands
|
6
5
|
class Apply < Base
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
def sub_commands(_values)
|
7
|
+
%w[apply]
|
8
|
+
end
|
9
|
+
|
10
|
+
def switches
|
11
|
+
%w[-backup -lock -lock-timeout -input -auto-approve -no-color -state
|
12
|
+
-target -var -var-file]
|
13
|
+
end
|
14
|
+
|
15
|
+
def arguments(values)
|
16
|
+
[values[:plan] || values[:directory]]
|
17
|
+
end
|
18
|
+
|
19
|
+
def option_default_values(_opts)
|
20
|
+
{ vars: {}, var_files: [], targets: [] }
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
vars.each do |key, value|
|
25
|
-
var_value = value.is_a?(String) ? value : JSON.generate(value)
|
26
|
-
sub = sub.with_option(
|
27
|
-
'-var', "'#{key}=#{var_value}'", separator: ' ')
|
28
|
-
end
|
29
|
-
sub = sub.with_option('-var-file', var_file) if var_file
|
30
|
-
var_files.each do |file|
|
31
|
-
sub = sub.with_option('-var-file', file)
|
32
|
-
end
|
33
|
-
sub = sub.with_option('-target', target) if target
|
34
|
-
targets.each do |file|
|
35
|
-
sub = sub.with_option('-target', file)
|
36
|
-
end
|
37
|
-
sub = sub.with_option('-state', state) if state
|
38
|
-
sub = sub.with_option('-input', input) if input
|
39
|
-
sub = sub.with_option('-auto-approve', auto_approve) unless
|
40
|
-
auto_approve.nil?
|
41
|
-
sub = sub.with_option('-backup', backup) if backup
|
42
|
-
sub = sub.with_flag('-no-color') if no_color
|
43
|
-
sub
|
44
|
-
end
|
45
|
-
.with_argument(plan || directory)
|
23
|
+
def option_override_values(opts)
|
24
|
+
{ backup: opts[:no_backup] ? '-' : opts[:backup] }
|
46
25
|
end
|
47
26
|
end
|
48
27
|
end
|
@@ -1,30 +1,25 @@
|
|
1
1
|
require 'lino'
|
2
|
+
|
2
3
|
require_relative '../errors'
|
4
|
+
require_relative '../options/factory'
|
3
5
|
|
4
6
|
module RubyTerraform
|
5
7
|
module Commands
|
6
8
|
class Base
|
7
9
|
def initialize(
|
8
|
-
|
10
|
+
binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil
|
11
|
+
)
|
9
12
|
@binary = binary || RubyTerraform.configuration.binary
|
10
13
|
@logger = logger || RubyTerraform.configuration.logger
|
11
14
|
@stdin = stdin || RubyTerraform.configuration.stdin
|
12
15
|
@stdout = stdout || RubyTerraform.configuration.stdout
|
13
16
|
@stderr = stderr || RubyTerraform.configuration.stderr
|
17
|
+
initialize_command
|
14
18
|
end
|
15
19
|
|
16
20
|
def execute(opts = {})
|
17
|
-
builder = instantiate_builder
|
18
|
-
|
19
21
|
do_before(opts)
|
20
|
-
|
21
|
-
logger.debug("Running '#{command.to_s}'.")
|
22
|
-
|
23
|
-
command.execute(
|
24
|
-
stdin: stdin,
|
25
|
-
stdout: stdout,
|
26
|
-
stderr: stderr
|
27
|
-
)
|
22
|
+
build_and_execute_command(opts)
|
28
23
|
do_after(opts)
|
29
24
|
rescue Open4::SpawnError
|
30
25
|
message = "Failed while running '#{command_name}'."
|
@@ -36,23 +31,69 @@ module RubyTerraform
|
|
36
31
|
|
37
32
|
attr_reader :binary, :logger, :stdin, :stdout, :stderr
|
38
33
|
|
34
|
+
def build_and_execute_command(opts)
|
35
|
+
command = build_command(opts)
|
36
|
+
logger.debug("Running '#{command}'.")
|
37
|
+
command.execute(
|
38
|
+
stdin: stdin,
|
39
|
+
stdout: stdout,
|
40
|
+
stderr: stderr
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
39
44
|
def command_name
|
40
|
-
self.class.to_s.split(
|
45
|
+
self.class.to_s.split('::')[-1].downcase
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
48
|
+
def do_before(_opts); end
|
49
|
+
|
50
|
+
def do_after(_opts); end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def initialize_command; end
|
55
|
+
|
56
|
+
def build_command(opts)
|
57
|
+
values = apply_option_defaults_and_overrides(opts)
|
58
|
+
|
44
59
|
Lino::CommandLineBuilder
|
45
|
-
|
46
|
-
|
60
|
+
.for_command(@binary)
|
61
|
+
.with_options_after_subcommands
|
62
|
+
.with_option_separator('=')
|
63
|
+
.with_appliables(options(values))
|
64
|
+
.with_subcommands(sub_commands(values))
|
65
|
+
.with_arguments(arguments(values))
|
66
|
+
.build
|
67
|
+
end
|
68
|
+
|
69
|
+
def apply_option_defaults_and_overrides(opts)
|
70
|
+
option_default_values(opts)
|
71
|
+
.merge(opts)
|
72
|
+
.merge(option_override_values(opts))
|
73
|
+
end
|
74
|
+
|
75
|
+
def option_default_values(_values)
|
76
|
+
{}
|
77
|
+
end
|
78
|
+
|
79
|
+
def option_override_values(_values)
|
80
|
+
{}
|
81
|
+
end
|
82
|
+
|
83
|
+
def sub_commands(_values)
|
84
|
+
[]
|
47
85
|
end
|
48
86
|
|
49
|
-
def
|
87
|
+
def options(values)
|
88
|
+
RubyTerraform::Options::Factory.from(values, switches)
|
50
89
|
end
|
51
90
|
|
52
|
-
def
|
91
|
+
def switches
|
92
|
+
[]
|
53
93
|
end
|
54
94
|
|
55
|
-
def
|
95
|
+
def arguments(_values)
|
96
|
+
[]
|
56
97
|
end
|
57
98
|
end
|
58
99
|
end
|
@@ -6,7 +6,7 @@ module RubyTerraform
|
|
6
6
|
attr_reader :logger
|
7
7
|
|
8
8
|
def initialize(directory: nil, logger: nil)
|
9
|
-
@directory = directory
|
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, :
|
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
|
@@ -3,44 +3,24 @@ require_relative 'base'
|
|
3
3
|
module RubyTerraform
|
4
4
|
module Commands
|
5
5
|
class Destroy < Base
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
+
%w[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
|
19
21
|
|
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 |target_name|
|
33
|
-
sub = sub.with_option('-target', target_name)
|
34
|
-
end
|
35
|
-
sub = sub.with_option('-state', state) if state
|
36
|
-
sub = sub.with_option('-auto-approve', auto_approve) unless
|
37
|
-
auto_approve.nil?
|
38
|
-
sub = sub.with_option('-backup', backup) if backup
|
39
|
-
sub = sub.with_flag('-no-color') if no_color
|
40
|
-
sub = sub.with_flag('-force') if force
|
41
|
-
sub
|
42
|
-
end
|
43
|
-
.with_argument(directory)
|
22
|
+
def option_override_values(opts)
|
23
|
+
{ backup: opts[:no_backup] ? '-' : opts[:backup] }
|
44
24
|
end
|
45
25
|
end
|
46
26
|
end
|
@@ -1,29 +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 Format < Base
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
diff = opts[:diff]
|
12
|
-
list = opts[:list]
|
13
|
-
no_color = opts[:no_color]
|
14
|
-
recursive = opts[:recursive]
|
15
|
-
write = opts[:write]
|
6
|
+
def switches
|
7
|
+
%w[-list -write -diff -check -recursive -no-color]
|
8
|
+
end
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[fmt]
|
12
|
+
end
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
sub = sub.with_flag('-no-color') if no_color
|
24
|
-
sub = sub.with_flag('-recursive') if recursive
|
25
|
-
sub
|
26
|
-
end.with_argument(directory)
|
14
|
+
def arguments(values)
|
15
|
+
[values[:directory]]
|
27
16
|
end
|
28
17
|
end
|
29
18
|
end
|
@@ -3,15 +3,17 @@ require_relative 'base'
|
|
3
3
|
module RubyTerraform
|
4
4
|
module Commands
|
5
5
|
class Get < Base
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def switches
|
7
|
+
%w[-update -no-color]
|
8
|
+
end
|
9
|
+
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[get]
|
12
|
+
end
|
13
|
+
|
14
|
+
def arguments(values)
|
15
|
+
[values[:directory]]
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
end
|
19
|
+
end
|
@@ -1,45 +1,26 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
1
|
require_relative 'base'
|
5
2
|
|
6
3
|
module RubyTerraform
|
7
4
|
module Commands
|
8
5
|
class Import < Base
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
def switches
|
7
|
+
%w[-config -backup -input -no-color -state -var -var-file]
|
8
|
+
end
|
9
|
+
|
10
|
+
def sub_commands(_values)
|
11
|
+
%w[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
|
-
|
23
|
-
|
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
|
@@ -3,36 +3,21 @@ require_relative 'base'
|
|
3
3
|
module RubyTerraform
|
4
4
|
module Commands
|
5
5
|
class Init < Base
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
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]
|
6
|
+
def switches
|
7
|
+
%w[-backend -backend-config -from-module -get -no-color -plugin-dir
|
8
|
+
-force-copy]
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
sub = sub.with_option('-force-copy', force_copy) unless force_copy.nil?
|
20
|
-
sub = sub.with_option('-get', get) unless get.nil?
|
21
|
-
sub = sub.with_option('-from-module', source) if source
|
22
|
-
sub = sub.with_flag('-no-color') if no_color
|
23
|
-
sub = sub.with_option('-plugin-dir', plugin_dir) unless plugin_dir.nil?
|
24
|
-
backend_config.each do |key, value|
|
25
|
-
sub = sub.with_option(
|
26
|
-
'-backend-config',
|
27
|
-
"'#{key}=#{value}'",
|
28
|
-
separator: ' ')
|
29
|
-
end
|
30
|
-
sub
|
31
|
-
end
|
11
|
+
def sub_commands(_values)
|
12
|
+
%w[init]
|
13
|
+
end
|
32
14
|
|
33
|
-
|
15
|
+
def arguments(values)
|
16
|
+
[values[:path]]
|
17
|
+
end
|
34
18
|
|
35
|
-
|
19
|
+
def option_default_values(_opts)
|
20
|
+
{ backend_config: {} }
|
36
21
|
end
|
37
22
|
end
|
38
23
|
end
|
@@ -4,29 +4,22 @@ require_relative 'base'
|
|
4
4
|
module RubyTerraform
|
5
5
|
module Commands
|
6
6
|
class Output < Base
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
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]
|
11
15
|
end
|
12
16
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
no_color = opts[:no_color]
|
17
|
-
json = opts[:json]
|
18
|
-
mod = opts[:module]
|
17
|
+
def sub_commands(_values)
|
18
|
+
%w[output]
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
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
|
21
|
+
def arguments(values)
|
22
|
+
[values[:name]]
|
30
23
|
end
|
31
24
|
|
32
25
|
def do_after(opts)
|