ruby-terraform 0.65.0.pre.3 → 0.65.0.pre.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/lib/ruby_terraform.rb +20 -54
- data/lib/ruby_terraform/commands/apply.rb +30 -40
- data/lib/ruby_terraform/commands/base.rb +58 -15
- data/lib/ruby_terraform/commands/destroy.rb +26 -38
- data/lib/ruby_terraform/commands/format.rb +15 -19
- data/lib/ruby_terraform/commands/get.rb +13 -8
- data/lib/ruby_terraform/commands/import.rb +25 -36
- data/lib/ruby_terraform/commands/init.rb +19 -34
- data/lib/ruby_terraform/commands/output.rb +19 -20
- data/lib/ruby_terraform/commands/plan.rb +22 -37
- data/lib/ruby_terraform/commands/refresh.rb +20 -33
- data/lib/ruby_terraform/commands/remote_config.rb +12 -16
- data/lib/ruby_terraform/commands/show.rb +13 -15
- data/lib/ruby_terraform/commands/validate.rb +20 -30
- data/lib/ruby_terraform/commands/workspace.rb +13 -10
- data/lib/ruby_terraform/options.rb +5 -0
- data/lib/ruby_terraform/options/factory.rb +116 -0
- data/lib/ruby_terraform/options/name.rb +43 -0
- data/lib/ruby_terraform/options/types/base.rb +24 -0
- data/lib/ruby_terraform/options/types/boolean.rb +16 -0
- data/lib/ruby_terraform/options/types/flag.rb +16 -0
- data/lib/ruby_terraform/options/types/standard.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 +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bf0ddc673685c898ae6d2eada53730debf6f88b641fa14a6c9607ba7fecdb30
|
4
|
+
data.tar.gz: f8514023bc5442bfa6d9c5148030dcba0bf6d926c3af2031b439bb179df1b15c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7db215e6820ddfde9c5362a27063413469a8d62ca57be6d2f68c0f6e47b9b02c8a32ce5f8e9471de41d8baca7dbf07c46d62e284d750e1da76584786f56ce65
|
7
|
+
data.tar.gz: b5d3bbe7617c24bdf233c81a298d3a78df93e30f7d9a61145e05afe009e3fad49b840e4fcdbf082dbc9afd92be11147401cc691fab5a376c93a009fd9f34bf67
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-terraform (0.65.0.pre.
|
5
|
-
lino (>=
|
4
|
+
ruby-terraform (0.65.0.pre.8)
|
5
|
+
lino (>= 2.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
concurrent-ruby (~> 1.0)
|
51
51
|
i18n (1.8.10)
|
52
52
|
concurrent-ruby (~> 1.0)
|
53
|
-
lino (
|
53
|
+
lino (2.3.0)
|
54
54
|
hamster (~> 3.0)
|
55
55
|
open4 (~> 1.3)
|
56
56
|
listen (3.5.1)
|
@@ -101,7 +101,7 @@ GEM
|
|
101
101
|
rb-inotify (0.10.1)
|
102
102
|
ffi (~> 1.0)
|
103
103
|
regexp_parser (2.1.1)
|
104
|
-
rexml (3.2.
|
104
|
+
rexml (3.2.5)
|
105
105
|
rspec (3.10.0)
|
106
106
|
rspec-core (~> 3.10.0)
|
107
107
|
rspec-expectations (~> 3.10.0)
|
@@ -115,7 +115,7 @@ GEM
|
|
115
115
|
diff-lcs (>= 1.2.0, < 2.0)
|
116
116
|
rspec-support (~> 3.10.0)
|
117
117
|
rspec-support (3.10.2)
|
118
|
-
rubocop (1.12.
|
118
|
+
rubocop (1.12.1)
|
119
119
|
parallel (~> 1.10)
|
120
120
|
parser (>= 3.0.0.0)
|
121
121
|
rainbow (>= 2.2.2, < 4.0)
|
data/lib/ruby_terraform.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'ruby_terraform/version'
|
2
2
|
require 'ruby_terraform/errors'
|
3
|
+
require 'ruby_terraform/options'
|
3
4
|
require 'ruby_terraform/commands'
|
4
5
|
require 'logger'
|
5
6
|
|
@@ -21,60 +22,25 @@ module RubyTerraform
|
|
21
22
|
end
|
22
23
|
|
23
24
|
module ClassMethods
|
24
|
-
|
25
|
-
Commands::
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Commands::
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
Commands::
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Commands::Validate
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def apply(opts = {})
|
45
|
-
Commands::Apply.new.execute(opts)
|
46
|
-
end
|
47
|
-
|
48
|
-
def destroy(opts = {})
|
49
|
-
Commands::Destroy.new.execute(opts)
|
50
|
-
end
|
51
|
-
|
52
|
-
def remote_config(opts = {})
|
53
|
-
Commands::RemoteConfig.new.execute(opts)
|
54
|
-
end
|
55
|
-
|
56
|
-
def refresh(opts = {})
|
57
|
-
Commands::Refresh.new.execute(opts)
|
58
|
-
end
|
59
|
-
|
60
|
-
def output(opts = {})
|
61
|
-
Commands::Output.new.execute(opts)
|
62
|
-
end
|
63
|
-
|
64
|
-
def show(opts = {})
|
65
|
-
Commands::Show.new.execute(opts)
|
66
|
-
end
|
67
|
-
|
68
|
-
def workspace(opts = {})
|
69
|
-
Commands::Workspace.new.execute(opts)
|
70
|
-
end
|
71
|
-
|
72
|
-
def import(opts = {})
|
73
|
-
Commands::Import.new.execute(opts)
|
74
|
-
end
|
75
|
-
|
76
|
-
def format(opts = {})
|
77
|
-
Commands::Format.new.execute(opts)
|
25
|
+
{
|
26
|
+
apply: RubyTerraform::Commands::Apply,
|
27
|
+
clean: RubyTerraform::Commands::Clean,
|
28
|
+
destroy: RubyTerraform::Commands::Destroy,
|
29
|
+
format: RubyTerraform::Commands::Format,
|
30
|
+
get: RubyTerraform::Commands::Get,
|
31
|
+
import: RubyTerraform::Commands::Import,
|
32
|
+
init: RubyTerraform::Commands::Init,
|
33
|
+
output: RubyTerraform::Commands::Output,
|
34
|
+
plan: RubyTerraform::Commands::Plan,
|
35
|
+
refresh: RubyTerraform::Commands::Refresh,
|
36
|
+
remote_config: RubyTerraform::Commands::RemoteConfig,
|
37
|
+
show: RubyTerraform::Commands::Show,
|
38
|
+
validate: RubyTerraform::Commands::Validate,
|
39
|
+
workspace: RubyTerraform::Commands::Workspace
|
40
|
+
}.each do |method, command_class|
|
41
|
+
define_method(method) do |opts = {}|
|
42
|
+
command_class.new.execute(opts)
|
43
|
+
end
|
78
44
|
end
|
79
45
|
end
|
80
46
|
extend ClassMethods
|
@@ -1,49 +1,39 @@
|
|
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 subcommands(_values)
|
7
|
+
%w[apply]
|
8
|
+
end
|
9
|
+
|
10
|
+
# rubocop:disable Metrics/MethodLength
|
11
|
+
def switches
|
12
|
+
%w[
|
13
|
+
-auto-approve
|
14
|
+
-backup
|
15
|
+
-input
|
16
|
+
-lock
|
17
|
+
-lock-timeout
|
18
|
+
-no-color
|
19
|
+
-state
|
20
|
+
-target
|
21
|
+
-var
|
22
|
+
-var-file
|
23
|
+
]
|
24
|
+
end
|
25
|
+
# rubocop:enable Metrics/MethodLength
|
26
|
+
|
27
|
+
def arguments(values)
|
28
|
+
[values[:plan] || values[:directory]]
|
29
|
+
end
|
30
|
+
|
31
|
+
def option_default_values(_opts)
|
32
|
+
{ vars: {}, var_files: [], targets: [] }
|
33
|
+
end
|
21
34
|
|
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
|
-
)
|
29
|
-
end
|
30
|
-
sub = sub.with_option('-var-file', var_file) if var_file
|
31
|
-
var_files.each do |file|
|
32
|
-
sub = sub.with_option('-var-file', file)
|
33
|
-
end
|
34
|
-
sub = sub.with_option('-target', target) if target
|
35
|
-
targets.each do |file|
|
36
|
-
sub = sub.with_option('-target', file)
|
37
|
-
end
|
38
|
-
sub = sub.with_option('-state', state) if state
|
39
|
-
sub = sub.with_option('-input', input) if input
|
40
|
-
sub = sub.with_option('-auto-approve', auto_approve) unless
|
41
|
-
auto_approve.nil?
|
42
|
-
sub = sub.with_option('-backup', backup) if backup
|
43
|
-
sub = sub.with_flag('-no-color') if no_color
|
44
|
-
sub
|
45
|
-
end
|
46
|
-
.with_argument(plan || directory)
|
35
|
+
def option_override_values(opts)
|
36
|
+
{ backup: opts[:no_backup] ? '-' : opts[:backup] }
|
47
37
|
end
|
48
38
|
end
|
49
39
|
end
|
@@ -1,5 +1,7 @@
|
|
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
|
@@ -12,20 +14,12 @@ module RubyTerraform
|
|
12
14
|
@stdin = stdin || RubyTerraform.configuration.stdin
|
13
15
|
@stdout = stdout || RubyTerraform.configuration.stdout
|
14
16
|
@stderr = stderr || RubyTerraform.configuration.stderr
|
17
|
+
initialize_command
|
15
18
|
end
|
16
19
|
|
17
20
|
def execute(opts = {})
|
18
|
-
builder = instantiate_builder
|
19
|
-
|
20
21
|
do_before(opts)
|
21
|
-
|
22
|
-
logger.debug("Running '#{command}'.")
|
23
|
-
|
24
|
-
command.execute(
|
25
|
-
stdin: stdin,
|
26
|
-
stdout: stdout,
|
27
|
-
stderr: stderr
|
28
|
-
)
|
22
|
+
build_and_execute_command(opts)
|
29
23
|
do_after(opts)
|
30
24
|
rescue Open4::SpawnError
|
31
25
|
message = "Failed while running '#{command_name}'."
|
@@ -37,21 +31,70 @@ module RubyTerraform
|
|
37
31
|
|
38
32
|
attr_reader :binary, :logger, :stdin, :stdout, :stderr
|
39
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
|
+
|
40
44
|
def command_name
|
41
45
|
self.class.to_s.split('::')[-1].downcase
|
42
46
|
end
|
43
47
|
|
44
|
-
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
|
+
|
45
59
|
Lino::CommandLineBuilder
|
46
|
-
.for_command(binary)
|
60
|
+
.for_command(@binary)
|
61
|
+
.with_options_after_subcommands
|
47
62
|
.with_option_separator('=')
|
63
|
+
.with_appliables(options(values))
|
64
|
+
.with_subcommands(subcommands(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 subcommands(_values)
|
84
|
+
[]
|
48
85
|
end
|
49
86
|
|
50
|
-
def
|
87
|
+
def options(values)
|
88
|
+
RubyTerraform::Options::Factory.from(values, switches)
|
89
|
+
end
|
51
90
|
|
52
|
-
def
|
91
|
+
def switches
|
92
|
+
[]
|
93
|
+
end
|
53
94
|
|
54
|
-
def
|
95
|
+
def arguments(_values)
|
96
|
+
[]
|
97
|
+
end
|
55
98
|
end
|
56
99
|
end
|
57
100
|
end
|
@@ -3,45 +3,33 @@ 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[
|
8
|
+
-auto-approve
|
9
|
+
-backup
|
10
|
+
-force
|
11
|
+
-no-color
|
12
|
+
-state
|
13
|
+
-target
|
14
|
+
-var
|
15
|
+
-var-file
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def subcommands(_values)
|
20
|
+
%w[destroy]
|
21
|
+
end
|
22
|
+
|
23
|
+
def arguments(values)
|
24
|
+
[values[:directory]]
|
25
|
+
end
|
26
|
+
|
27
|
+
def option_default_values(_opts)
|
28
|
+
{ vars: {}, var_files: [], targets: [] }
|
29
|
+
end
|
19
30
|
|
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
|
-
)
|
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)
|
31
|
+
def option_override_values(opts)
|
32
|
+
{ backup: opts[:no_backup] ? '-' : opts[:backup] }
|
45
33
|
end
|
46
34
|
end
|
47
35
|
end
|
@@ -1,29 +1,25 @@
|
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
def switches
|
7
|
+
%w[
|
8
|
+
-check
|
9
|
+
-diff
|
10
|
+
-list
|
11
|
+
-no-color
|
12
|
+
-recursive
|
13
|
+
-write
|
14
|
+
]
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def subcommands(_values)
|
18
|
+
%w[fmt]
|
19
|
+
end
|
20
20
|
|
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)
|
21
|
+
def arguments(values)
|
22
|
+
[values[:directory]]
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
@@ -3,14 +3,19 @@ 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[
|
8
|
+
-no-color
|
9
|
+
-update
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
def subcommands(_values)
|
14
|
+
%w[get]
|
15
|
+
end
|
16
|
+
|
17
|
+
def arguments(values)
|
18
|
+
[values[:directory]]
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|