ruby-terraform 0.64.0 → 0.65.0.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +102 -29
- 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/command_line/builder.rb +55 -0
- data/lib/ruby_terraform/command_line/option/base.rb +24 -0
- data/lib/ruby_terraform/command_line/option/boolean.rb +16 -0
- data/lib/ruby_terraform/command_line/option/boolean_value.rb +29 -0
- data/lib/ruby_terraform/command_line/option/flag.rb +16 -0
- data/lib/ruby_terraform/command_line/option/standard.rb +40 -0
- data/lib/ruby_terraform/command_line/option/switch.rb +43 -0
- data/lib/ruby_terraform/command_line/options_factory.rb +79 -0
- data/lib/ruby_terraform/commands/apply.rb +18 -40
- data/lib/ruby_terraform/commands/base.rb +56 -20
- data/lib/ruby_terraform/commands/clean.rb +2 -2
- data/lib/ruby_terraform/commands/destroy.rb +17 -38
- data/lib/ruby_terraform/commands/format.rb +8 -20
- data/lib/ruby_terraform/commands/get.rb +11 -10
- data/lib/ruby_terraform/commands/import.rb +17 -36
- data/lib/ruby_terraform/commands/init.rb +12 -28
- data/lib/ruby_terraform/commands/output.rb +13 -21
- 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 -17
- data/lib/ruby_terraform/commands/show.rb +9 -16
- data/lib/ruby_terraform/commands/validate.rb +13 -29
- data/lib/ruby_terraform/commands/workspace.rb +14 -14
- data/lib/ruby_terraform/errors/execution_error.rb +1 -1
- data/lib/ruby_terraform/output.rb +15 -12
- data/lib/ruby_terraform/version.rb +1 -1
- 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
|
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
|
@@ -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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
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
|
10
|
-
|
11
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
10
|
+
def sub_commands(_values)
|
11
|
+
'fmt'
|
12
|
+
end
|
21
13
|
|
22
|
-
|
23
|
-
|
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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
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
|
+
'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
|
@@ -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
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
15
|
+
def arguments(values)
|
16
|
+
values[:path]
|
17
|
+
end
|
35
18
|
|
36
|
-
|
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
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
15
|
-
|
16
|
-
|
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
|
-
|
22
|
-
|
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
|
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
|
+
'plan'
|
12
|
+
end
|
13
|
+
|
14
|
+
def option_default_values(_opts)
|
15
|
+
{ vars: {}, var_files: [], targets: [] }
|
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 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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
@@ -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
|
8
|
-
backend
|
9
|
-
|
10
|
-
backend_config = opts[:backend_config] || {}
|
6
|
+
def switches
|
7
|
+
%w[-backend -backend-config -no-color]
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
22
|
-
|
23
|
-
end
|
14
|
+
def option_default_values(_opts)
|
15
|
+
{ backend_config: {} }
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
27
|
-
end
|
19
|
+
end
|