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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dbba56077adf66c7e32da731ddb62cc90bfea3d2ba29ead63913edf3e1da5bd
4
- data.tar.gz: 708c49c91c22e75dcc9262f3d7858d51015451ebfb56dd222bddcf37d95d0fdb
3
+ metadata.gz: 9addf5887a0f81258238fceea9f31f92f8653b4593c0684e3511723e5d7ee969
4
+ data.tar.gz: 660b6fb332e8b93e4ca3f7bb8dc1b48052a2116130273968d148d983b9ee0f4f
5
5
  SHA512:
6
- metadata.gz: 12e0d2f034a80f3d3a3b08aaac13858ef88df3a7fcd16f41320c8aa79ea895cd11165ce8fe439568c46b906b85c54f6249a109899d50c1c4e1c4bd4a2b7356c4
7
- data.tar.gz: a1e07bec999d28347645081e3d660c814f7e66a0d2c4f6079002a95e3ac021743904acc600a9a9f3965e8410b654c33381419110435cc0587cafad9acc93260a
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.2)
5
- lino (>= 1.5)
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 (1.9.0)
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.4)
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.0)
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 `delete`. default `list`.
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
- After checking out the repo, run `bin/setup` to install dependencies. Then,
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
- To install this gem onto your local machine, run `bundle exec rake install`. To
559
- release a new version, update the version number in `version.rb`, and then run
560
- `bundle exec rake release`, which will create a git tag for the version, push
561
- git commits and tags, and push the `.gem` file to
562
- [rubygems.org](https://rubygems.org).
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: :spec
10
-
11
- RSpec::Core::RakeTask.new(:spec)
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'
@@ -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
- def clean(opts = {})
25
- Commands::Clean.new.execute(opts)
26
- end
27
-
28
- def init(opts = {})
29
- Commands::Init.new.execute(opts)
30
- end
31
-
32
- def get(opts = {})
33
- Commands::Get.new.execute(opts)
34
- end
35
-
36
- def validate(opts = {})
37
- Commands::Validate.new.execute(opts)
38
- end
39
-
40
- def plan(opts = {})
41
- Commands::Plan.new.execute(opts)
42
- end
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 configure_command(builder, opts)
8
- directory = opts[:directory]
9
- plan = opts[:plan]
10
- vars = opts[:vars] || {}
11
- var_file = opts[:var_file]
12
- var_files = opts[:var_files] || []
13
- target = opts[:target]
14
- targets = opts[:targets] || []
15
- state = opts[:state]
16
- input = opts[:input]
17
- auto_approve = opts[:auto_approve]
18
- no_backup = opts[:no_backup]
19
- backup = no_backup ? '-' : opts[:backup]
20
- no_color = opts[:no_color]
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
- builder
23
- .with_subcommand('apply') do |sub|
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
- command = configure_command(builder, opts).build
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 instantiate_builder
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 do_before(opts); end
87
+ def options(values)
88
+ RubyTerraform::Options::Factory.from(values, switches)
89
+ end
51
90
 
52
- def configure_command(builder, opts); end
91
+ def switches
92
+ []
93
+ end
53
94
 
54
- def do_after(opts); end
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 configure_command(builder, opts)
7
- directory = opts[:directory]
8
- vars = opts[:vars] || {}
9
- var_file = opts[:var_file]
10
- var_files = opts[:var_files] || []
11
- target = opts[:target]
12
- targets = opts[:targets] || []
13
- state = opts[:state]
14
- force = opts[:force]
15
- no_backup = opts[:no_backup]
16
- backup = no_backup ? '-' : opts[:backup]
17
- no_color = opts[:no_color]
18
- auto_approve = opts[:auto_approve]
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
- builder
21
- .with_subcommand('destroy') do |sub|
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