ruby-terraform 0.65.0.pre.2 → 0.65.0.pre.7
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 +10 -10
- data/README.md +29 -9
- data/Rakefile +19 -3
- data/lib/ruby_terraform.rb +20 -54
- data/lib/ruby_terraform/commands/apply.rb +30 -39
- data/lib/ruby_terraform/commands/base.rb +58 -15
- data/lib/ruby_terraform/commands/destroy.rb +26 -37
- 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 -27
- data/lib/ruby_terraform/commands/output.rb +19 -20
- data/lib/ruby_terraform/commands/plan.rb +22 -36
- data/lib/ruby_terraform/commands/refresh.rb +20 -32
- data/lib/ruby_terraform/commands/remote_config.rb +12 -15
- data/lib/ruby_terraform/commands/show.rb +13 -15
- data/lib/ruby_terraform/commands/validate.rb +20 -29
- data/lib/ruby_terraform/commands/workspace.rb +13 -12
- 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 +32 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9addf5887a0f81258238fceea9f31f92f8653b4593c0684e3511723e5d7ee969
|
4
|
+
data.tar.gz: 660b6fb332e8b93e4ca3f7bb8dc1b48052a2116130273968d148d983b9ee0f4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 444f51e2e53816404a78770d21873b060b2b117fe36a34516c1c1748db60d87ed10a1fa07bd75e0d7ff010617b1ce7ed3618ede7bc80263539be6454a703b962
|
7
|
+
data.tar.gz: cbb17a6a9b74be5a809b3d68058f383634482fdc3aa06151fc70b165195f230dd692da4b8494a20ffbe09bb7075acd15d9238b07a8a5dc53c3d4590990369000
|
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.7)
|
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)
|
@@ -157,18 +157,18 @@ DEPENDENCIES
|
|
157
157
|
bundler (~> 2.0)
|
158
158
|
faker (~> 2.17)
|
159
159
|
gem-release (~> 2.1)
|
160
|
-
guard
|
161
|
-
guard-rspec
|
160
|
+
guard (~> 2.16)
|
161
|
+
guard-rspec (~> 4.7)
|
162
162
|
rake (~> 13.0)
|
163
163
|
rake_circle_ci (~> 0.9)
|
164
164
|
rake_github (~> 0.5)
|
165
165
|
rake_gpg (~> 0.12)
|
166
166
|
rake_ssh (~> 0.4)
|
167
167
|
rspec (~> 3.9)
|
168
|
-
rubocop
|
169
|
-
rubocop-rspec
|
168
|
+
rubocop (~> 1.12)
|
169
|
+
rubocop-rspec (~> 2.2)
|
170
170
|
ruby-terraform!
|
171
|
-
simplecov
|
171
|
+
simplecov (~> 0.21)
|
172
172
|
|
173
173
|
BUNDLED WITH
|
174
174
|
2.2.15
|
data/README.md
CHANGED
@@ -467,7 +467,7 @@ RubyTerraform.workspace(operation: 'delete', workspace: 'staging')
|
|
467
467
|
arguments:
|
468
468
|
* `directory`: the directory containing terraform configuration, the default is
|
469
469
|
the current path.
|
470
|
-
* `operation`: `list`, `select`, `new` or
|
470
|
+
* `operation`: `list`, `select`, `new` or `delete`. default `list`.
|
471
471
|
* `workspace`: Workspace name.
|
472
472
|
|
473
473
|
|
@@ -551,15 +551,35 @@ interactive input from the terminal.
|
|
551
551
|
|
552
552
|
## Development
|
553
553
|
|
554
|
-
|
555
|
-
run `rake spec` to run the tests. You can also run `bin/console` for an
|
556
|
-
interactive prompt that will allow you to experiment.
|
554
|
+
To install dependencies and run the build, run the pre-commit build:
|
557
555
|
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
556
|
+
```shell script
|
557
|
+
./go
|
558
|
+
```
|
559
|
+
|
560
|
+
This runs all unit tests and other checks including coverage and code linting /
|
561
|
+
formatting.
|
562
|
+
|
563
|
+
To run only the unit tests, including coverage:
|
564
|
+
|
565
|
+
```shell script
|
566
|
+
./go test:unit
|
567
|
+
```
|
568
|
+
|
569
|
+
To attempt to fix any code linting / formatting issues:
|
570
|
+
|
571
|
+
```shell script
|
572
|
+
./go library:fix
|
573
|
+
```
|
574
|
+
|
575
|
+
To check for code linting / formatting issues without fixing:
|
576
|
+
|
577
|
+
```shell script
|
578
|
+
./go library:check
|
579
|
+
```
|
580
|
+
|
581
|
+
You can also run `bin/console` for an interactive prompt that will allow you to
|
582
|
+
experiment.
|
563
583
|
|
564
584
|
### Managing CircleCI keys
|
565
585
|
|
data/Rakefile
CHANGED
@@ -5,10 +5,12 @@ require 'rake_ssh'
|
|
5
5
|
require 'rake_gpg'
|
6
6
|
require 'securerandom'
|
7
7
|
require 'rspec/core/rake_task'
|
8
|
+
require 'rubocop/rake_task'
|
8
9
|
|
9
|
-
task default:
|
10
|
-
|
11
|
-
|
10
|
+
task default: [
|
11
|
+
#:'library:fix',
|
12
|
+
:'test:unit'
|
13
|
+
]
|
12
14
|
|
13
15
|
namespace :encryption do
|
14
16
|
namespace :passphrase do
|
@@ -39,6 +41,20 @@ namespace :keys do
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
44
|
+
RuboCop::RakeTask.new
|
45
|
+
|
46
|
+
namespace :library do
|
47
|
+
desc 'Run all checks of the library'
|
48
|
+
task check: [:rubocop]
|
49
|
+
|
50
|
+
desc 'Attempt to automatically fix issues with the library'
|
51
|
+
task fix: [:'rubocop:auto_correct']
|
52
|
+
end
|
53
|
+
|
54
|
+
namespace :test do
|
55
|
+
RSpec::Core::RakeTask.new(:unit)
|
56
|
+
end
|
57
|
+
|
42
58
|
RakeCircleCI.define_project_tasks(
|
43
59
|
namespace: :circle_ci,
|
44
60
|
project_slug: 'github/infrablocks/ruby_terraform'
|
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,48 +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
|
-
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)
|
35
|
+
def option_override_values(opts)
|
36
|
+
{ backup: opts[:no_backup] ? '-' : opts[:backup] }
|
46
37
|
end
|
47
38
|
end
|
48
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,44 +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
|
-
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)
|
31
|
+
def option_override_values(opts)
|
32
|
+
{ backup: opts[:no_backup] ? '-' : opts[:backup] }
|
44
33
|
end
|
45
34
|
end
|
46
35
|
end
|