kitchen-terraform 6.1.0 → 7.0.0

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.

Potentially problematic release.


This version of kitchen-terraform might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8549ab850779ffc15ccb46e62033077103d76ccc0a57b87ee30dd8de88838b70
4
- data.tar.gz: c7f65d4ef1e3f37e7e1cd1d73e48b294517d5911292a787350749f7ef9a99d41
3
+ metadata.gz: '06987257a4c260d1b96418960d13dfa4098745d75e175da00abd74b9e79578a2'
4
+ data.tar.gz: b160ce915cde5c453b646e7afa0bf5f74c9b62dc134cedd4ce275e1078359cfa
5
5
  SHA512:
6
- metadata.gz: daa80765cdb58cd956a4b42aee2c9bc86f40172bd349fdbb683727f6d3ac925b9347c4e22c9b5c89b62ebc8d8ff771e2ee0140dbd496407ac1910193918eb4a6
7
- data.tar.gz: 33401e979b8f07aacfbcf206b9b9c721d08641920d0178334485a7c1a8359269552db38400886175c15a8c0f4dab1e3f88a277bbd1e1c06f52d44681cdb01d86
6
+ metadata.gz: 2f8fdd9a82a62c2e97d78935b95caee26f51a0e1df52acf511d1354bace0a740c1605fad44fdb7b5a089c7796b973236db980194505662ca2862dc8edbb08690
7
+ data.tar.gz: 03f6b585277114646e9fffc00e3ee4c562d3f3a8c0ba9185a601d213097114740ab3f4fc1ad7c9c1fe8dc373e4f7152bbb38cd8cf444517b5e5f0c556f999d32
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -6,17 +6,16 @@
6
6
  [![Gem downloads version][gem-downloads-version-shield]][kitchen-terraform-gem]
7
7
  [![Gem downloads total][gem-downloads-total-shield]][kitchen-terraform-gem]
8
8
 
9
- [![Kitchen tests workflow][kitchen-tests-workflow-shield]][kitchen-tests-workflow]
10
- [![RSpec tests workflow][rspec-tests-workflow-shield]][rspec-tests-workflow]
9
+ [![Delivery][delivery-shield]][delivery-workflow]
10
+ [![Pages Build and Deployment][pages-build-deployment-shield]][pages-build-deployment-workflow]
11
11
  [![Code coverage][code-coverage-shield]][code-coverage]
12
12
  [![Maintainability][maintainability-shield]][maintainability]
13
13
  [![Technical debt][technical-debt-shield]][technical-debt]
14
- [![Dependencies][hakiri-shield]][hakiri]
15
14
 
16
15
  [![Gitter chat][gitter-shield]][gitter]
17
16
 
18
- Kitchen-Terraform provides a set of [Kitchen][kitchen] plugins
19
- which enable the use of Kitchen to converge a [Terraform][terraform]
17
+ Kitchen-Terraform provides a set of [Test Kitchen][test-kitchen] plugins
18
+ which enable the use of Test Kitchen to converge a [Terraform][terraform]
20
19
  configuration and verify the resulting infrastructure systems with
21
20
  [InSpec][inspec] controls.
22
21
 
@@ -73,20 +72,28 @@ the semantic versioning of the Ruby gem.
73
72
 
74
73
  > Defining Kitchen-Terraform as a dependency for Bundler in a Gemfile
75
74
 
75
+ ---
76
+
76
77
  ```ruby
77
78
  source "https://rubygems.org/" do
78
- gem "kitchen-terraform", "~> 5.7"
79
+ gem "kitchen-terraform", "~> 7.0"
79
80
  end
80
81
  ```
81
82
 
83
+ ---
84
+
82
85
  Second, run the following command.
83
86
 
84
87
  > Installing Kitchen-Terraform with Bundler
85
88
 
89
+ ---
90
+
86
91
  ```sh
87
92
  bundle install
88
93
  ```
89
94
 
95
+ ---
96
+
90
97
  The preceding command will create a `Gemfile.lock` comprising a list
91
98
  of the resolved Ruby gem dependencies.
92
99
 
@@ -101,10 +108,14 @@ example.
101
108
 
102
109
  > Installing Kitchen-Terraform with RubyGems
103
110
 
111
+ ---
112
+
104
113
  ```sh
105
- gem install kitchen-terraform --version 6.1.0
114
+ gem install kitchen-terraform --version 7.0.0
106
115
  ```
107
116
 
117
+ ---
118
+
108
119
  This approach is not recommended as it requires more effort to install
109
120
  the gem in a manner that is reproducible and free of dependency
110
121
  conflicts.
@@ -124,25 +135,34 @@ Ed25519-type SSH keys.
124
135
 
125
136
  ## Usage
126
137
 
138
+ A familiarity with [Test Kitchen][test-kitchen] workflows and commands is required to use Kitchen-Terraform.
139
+
127
140
  ### Configuration
128
141
 
129
- Kitchen-Terraform provides three Test Kitchen plugins which must be
142
+ Kitchen-Terraform provides four Test Kitchen plugins which must be
130
143
  configured in a
131
- [Kitchen configuration file][kitchen-configuration-file] in
144
+ [Test Kitchen configuration file][kitchen-configuration-file] in
132
145
  order to successfully test Terraform configuration.
133
146
 
134
- The [Terraform driver][terraform-driver] manages the state of the
135
- Terraform root module.
147
+ The [Terraform driver][terraform-driver] is the bridge between Test
148
+ Kitchen and Terraform. It manages the [state][terraform-state] of the
149
+ Terraform root module under test by shelling out and running Terraform commands.
136
150
 
137
- The [Terraform provisioner][terraform-provisioner] uses the Terraform
138
- driver to apply changes to the Terraform state.
151
+ The [Terraform provisioner][terraform-provisioner] applies changes to
152
+ the Terraform state based on the configuration of the root module.
139
153
 
140
- The [Terraform verifier][terraform-verifier] uses InSpec to verify the
141
- Terraform state.
154
+ The [Terraform transport][terraform-transport] is responsible for the
155
+ integration with the Terraform CLI.
156
+
157
+ The [Terraform verifier][terraform-verifier] utilizes InSpec to verify
158
+ the behaviour and state of resources in the Terraform state.
142
159
 
143
160
  More information can be found in the
144
161
  [Ruby gem documentation][ruby-gem-documentation].
145
162
 
163
+ The `kitchen doctor` command can be used to validate the system and the
164
+ configuration file.
165
+
146
166
  ### Caveats
147
167
 
148
168
  Versions of Terraform in the 0.11 series may cause `kitchen test` to
@@ -159,7 +179,7 @@ Several tutorials are available on the
159
179
 
160
180
  The integration tests for Kitchen-Terraform can also be viewed as
161
181
  examples of how it works. The
162
- [integration test Kitchen configuration file][int-kitchen-config]
182
+ [integration test Test Kitchen configuration file][int-kitchen-config]
163
183
  and the [integration test directory][test-directory] provide several
164
184
  functional examples which exercise various features of
165
185
  Kitchen-Terraform.
@@ -226,9 +246,6 @@ Kitchen-Terraform is distributed under the [Apache License][license].
226
246
 
227
247
  <!-- Markdown links and image definitions -->
228
248
 
229
- [appveyor-build-status-shield]: https://ci.appveyor.com/api/projects/status/8d7t014gij5grk5r/branch/master?svg=true
230
- [appveyor-build-status]: https://ci.appveyor.com/project/aaron-lane/kitchen-terraform/branch/master
231
- [bundler-getting-started]: https://bundler.io/#getting-started
232
249
  [bundler-in-depth]: https://bundler.io/gemfile.html
233
250
  [bundler]: https://bundler.io/index.html#getting-started
234
251
  [changelog]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/CHANGELOG.md
@@ -236,37 +253,30 @@ Kitchen-Terraform is distributed under the [Apache License][license].
236
253
  [code-coverage]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/
237
254
  [contributing-document]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/CONTRIBUTING.md
238
255
  [contributors]: https://github.com/newcontext-oss/kitchen-terraform/graphs/contributors
239
- [docker]: https://www.docker.com/
240
- [docker-community-edition]: https://store.docker.com/editions/community/docker-ce-server-ubuntu
241
- [docker-provider]: https://www.terraform.io/docs/providers/docker/index.html
256
+ [copado-github]: https://github.com/CopadoSolutions
257
+ [copado-linkedin]: https://www.linkedin.com/company/copado-solutions-s.l
258
+ [copado-twitter]: https://twitter.com/CopadoSolutions
259
+ [copado]: https://copado.com/
260
+ [delivery-shield]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/delivery.yml/badge.svg
261
+ [delivery-workflow]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/delivery.yml
242
262
  [gem-downloads-total-shield]: https://img.shields.io/gem/dt/kitchen-terraform.svg
243
263
  [gem-downloads-version-shield]: https://img.shields.io/gem/dtv/kitchen-terraform.svg
244
264
  [gem-version-shield]: https://img.shields.io/gem/v/kitchen-terraform.svg
245
265
  [gitter-shield]: https://img.shields.io/gitter/room/kitchen-terraform/Lobby.svg
246
266
  [gitter]: https://gitter.im/kitchen-terraform/Lobby
247
- [hakiri-shield]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/master.svg
248
- [hakiri]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/
249
- [inspec]: https://www.inspec.io/
267
+ [inspec]: https://community.chef.io/tools/chef-inspec
250
268
  [int-kitchen-config]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/kitchen.yml
251
- [issue-271]: https://github.com/newcontext-oss/kitchen-terraform/issues/271
252
- [kitchen]: http://kitchen.ci/index.html
253
269
  [kitchen-configuration-file]: https://docs.chef.io/config_yml_kitchen.html
254
270
  [kitchen-terraform-gem]: https://rubygems.org/gems/kitchen-terraform
255
271
  [kitchen-terraform-logo]: https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/logo.png
256
272
  [kitchen-terraform-tutorials]: https://newcontext-oss.github.io/kitchen-terraform/tutorials/
257
- [kitchen-tests-workflow]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/kitchen-tests.yml
258
- [kitchen-tests-workflow-shield]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/kitchen-tests.yml/badge.svg
259
273
  [license]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/LICENSE
260
274
  [maintainability-shield]: https://img.shields.io/codeclimate/maintainability-percentage/newcontext-oss/kitchen-terraform.svg
261
275
  [maintainability]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/
262
- [copado-github]: https://github.com/CopadoSolutions
263
- [copado-linkedin]: https://www.linkedin.com/company/copado-solutions-s.l
264
- [copado-twitter]: https://twitter.com/CopadoSolutions
265
- [copado]: https://copado.com/
276
+ [pages-build-deployment-shield]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/pages/pages-build-deployment/badge.svg
277
+ [pages-build-deployment-workflow]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/pages/pages-build-deployment
266
278
  [rbenv]: https://github.com/rbenv/rbenv
267
279
  [rbnacl-installation]: https://github.com/crypto-rb/rbnacl/tree/v4.0.2#installation
268
- [rspec-tests-workflow]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/rspec-tests.yml
269
- [rspec-tests-workflow-shield]: https://github.com/newcontext-oss/kitchen-terraform/actions/workflows/rspec-tests.yml/badge.svg
270
280
  [ruby-branches]: https://www.ruby-lang.org/en/downloads/branches/
271
281
  [ruby-gem-documentation]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/
272
282
  [ruby-gems-what-is]: http://guides.rubygems.org/ruby-gems-what-is/index.html
@@ -275,11 +285,14 @@ Kitchen-Terraform is distributed under the [Apache License][license].
275
285
  [rubygems-installing-gems]: http://guides.rubygems.org/rubygems-basics/#rubygems-installing-gems
276
286
  [technical-debt-shield]: https://img.shields.io/codeclimate/tech-debt/newcontext-oss/kitchen-terraform.svg
277
287
  [technical-debt]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/
278
- [terraform-cli]: https://www.terraform.io/docs/commands/index.html
288
+ [terraform-cli]: https://developer.hashicorp.com/terraform/cli/commands
279
289
  [terraform-driver]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Driver/Terraform
280
290
  [terraform-install]: https://www.terraform.io/intro/getting-started/install.html
281
291
  [terraform-provisioner]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Provisioner/Terraform
292
+ [terraform-state]: https://developer.hashicorp.com/terraform/language/state
293
+ [terraform-transport]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Transport/Terraform
282
294
  [terraform-verifier]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Verifier/Terraform
283
295
  [terraform]: https://www.terraform.io/
284
296
  [test-directory]: https://github.com/newcontext-oss/kitchen-terraform/tree/master/test
297
+ [test-kitchen]: http://kitchen.ci/
285
298
  [tfenv]: https://github.com/kamatama41/tfenv
@@ -32,6 +32,7 @@ require "kitchen/terraform/configurable"
32
32
  require "kitchen/terraform/driver/create"
33
33
  require "kitchen/terraform/driver/destroy"
34
34
  require "kitchen/terraform/version_verifier"
35
+ require "kitchen/transport/terraform"
35
36
  require "rubygems"
36
37
  require "shellwords"
37
38
 
@@ -44,9 +45,9 @@ module Kitchen
44
45
  # @see http://www.rubydoc.info/gems/test-kitchen/Kitchen/Driver
45
46
  module Driver
46
47
 
47
- # The driver is the bridge between Test Kitchen and Terraform. It manages the
48
- # {https://www.terraform.io/docs/state/index.html state} of the Terraform root module by shelling out and running
49
- # Terraform commands.
48
+ # The Terraform driver is the bridge between Test Kitchen and Terraform. It manages the
49
+ # {https://developer.hashicorp.com/terraform/language/state state} of the Terraform root module under test by
50
+ # shelling out and running Terraform commands.
50
51
  #
51
52
  # === Commands
52
53
  #
@@ -76,6 +77,8 @@ module Kitchen
76
77
  #
77
78
  # ==== client
78
79
  #
80
+ # driver.client is deprecated; use transport.client instead.
81
+ #
79
82
  # {include:Kitchen::Terraform::ConfigAttribute::Client}
80
83
  #
81
84
  # ==== color
@@ -84,6 +87,8 @@ module Kitchen
84
87
  #
85
88
  # ==== command_timeout
86
89
  #
90
+ # driver.command_timeout is deprecated; use transport.command_timeout instead.
91
+ #
87
92
  # {include:Kitchen::Terraform::ConfigAttribute::CommandTimeout}
88
93
  #
89
94
  # ==== lock
@@ -104,6 +109,8 @@ module Kitchen
104
109
  #
105
110
  # ==== root_module_directory
106
111
  #
112
+ # driver.root_module_directory is deprecated; use transport.root_module_directory instead.
113
+ #
107
114
  # {include:Kitchen::Terraform::ConfigAttribute::RootModuleDirectory}
108
115
  #
109
116
  # ==== variable_files
@@ -135,20 +142,15 @@ module Kitchen
135
142
  class Terraform < ::Kitchen::Driver::Base
136
143
  kitchen_driver_api_version 2
137
144
 
138
- no_parallel_for(
139
- :create,
140
- :converge,
141
- :setup,
142
- :destroy
143
- )
144
-
145
145
  include ::Kitchen::Terraform::ConfigAttribute::BackendConfigurations
146
146
 
147
147
  include ::Kitchen::Terraform::ConfigAttribute::Client
148
+ deprecate_config_for :client, "use transport.client instead"
148
149
 
149
150
  include ::Kitchen::Terraform::ConfigAttribute::Color
150
151
 
151
152
  include ::Kitchen::Terraform::ConfigAttribute::CommandTimeout
153
+ deprecate_config_for :command_timeout, "use transport.command_timeout instead"
152
154
 
153
155
  include ::Kitchen::Terraform::ConfigAttribute::Lock
154
156
 
@@ -159,6 +161,7 @@ module Kitchen
159
161
  include ::Kitchen::Terraform::ConfigAttribute::PluginDirectory
160
162
 
161
163
  include ::Kitchen::Terraform::ConfigAttribute::RootModuleDirectory
164
+ deprecate_config_for :root_module_directory, "use transport.root_module_directory instead"
162
165
 
163
166
  include ::Kitchen::Terraform::ConfigAttribute::VariableFiles
164
167
 
@@ -168,13 +171,21 @@ module Kitchen
168
171
 
169
172
  include ::Kitchen::Terraform::Configurable
170
173
 
174
+ attr_reader :transport
175
+
171
176
  # Creates a Test Kitchen instance by initializing the working directory and creating a test workspace.
172
177
  #
173
- # @param _state [Hash] the mutable instance and driver state.
178
+ # @param state [Hash] the mutable instance and driver state.
174
179
  # @raise [Kitchen::ActionFailed] if the result of the action is a failure.
175
180
  # @return [void]
176
- def create(_state)
177
- create_strategy.call
181
+ def create(state)
182
+ ::Kitchen::Terraform::Driver::Create.new(
183
+ config: config,
184
+ connection: transport.connection(state),
185
+ logger: logger,
186
+ version_requirement: version_requirement,
187
+ workspace_name: workspace_name,
188
+ ).call
178
189
  rescue => error
179
190
  action_failed.call message: error.message
180
191
  end
@@ -182,35 +193,63 @@ module Kitchen
182
193
  # Destroys a Test Kitchen instance by initializing the working directory, selecting the test workspace,
183
194
  # deleting the state, selecting the default workspace, and deleting the test workspace.
184
195
  #
185
- # @param _state [Hash] the mutable instance and driver state.
196
+ # @param state [Hash] the mutable instance and driver state.
186
197
  # @raise [Kitchen::ActionFailed] if the result of the action is a failure.
187
198
  # @return [void]
188
- def destroy(_state)
189
- destroy_strategy.call
199
+ def destroy(state)
200
+ ::Kitchen::Terraform::Driver::Destroy.new(
201
+ config: config,
202
+ connection: transport.connection(state.merge(environment: { "TF_WARN_OUTPUT_ERRORS" => "true" })),
203
+ logger: logger,
204
+ version_requirement: version_requirement,
205
+ workspace_name: workspace_name,
206
+ ).call
190
207
  rescue => error
191
208
  action_failed.call message: error.message
192
209
  end
193
210
 
211
+ # doctor checks the system and configuration for common errors.
212
+ #
213
+ # @param state [Hash] the mutable Kitchen instance state.
214
+ # @return [Boolean] +true+ if any errors are found; +false+ if no errors are found.
215
+ def doctor(state)
216
+ errors = false
217
+
218
+ deprecated_config.each_pair do |attribute, message|
219
+ errors = true
220
+ logger.warn "driver.#{attribute} is deprecated: #{message}"
221
+ end
222
+
223
+ methods.each do |method|
224
+ next if !method.match? /doctor_config_.*/
225
+
226
+ config_error = send method
227
+ errors = errors || config_error
228
+ end
229
+
230
+ transport_errors = transport.doctor state
231
+ verifier_errors = instance.verifier.doctor state
232
+
233
+ errors || transport_errors || verifier_errors
234
+ end
235
+
194
236
  # #finalize_config! invokes the super implementation and then initializes the strategies.
195
237
  #
196
238
  # @param instance [Kitchen::Instance] an associated instance.
197
239
  # @raise [Kitchen::ClientError] if the instance is nil.
198
240
  # @return [self]
199
- # @see Kitchen::Configurable#finalize_config!
200
241
  def finalize_config!(instance)
201
- super instance
202
- self.create_strategy = ::Kitchen::Terraform::Driver::Create.new(
203
- config: config,
204
- logger: logger,
205
- version_requirement: version_requirement,
206
- workspace_name: workspace_name,
207
- )
208
- self.destroy_strategy = ::Kitchen::Terraform::Driver::Destroy.new(
209
- config: config,
210
- logger: logger,
211
- version_requirement: version_requirement,
212
- workspace_name: workspace_name,
213
- )
242
+ super
243
+
244
+ self.deprecated_config ||= {}
245
+
246
+ transport = instance.transport
247
+
248
+ self.transport = if ::Kitchen::Transport::Terraform == transport.class
249
+ transport
250
+ else
251
+ ::Kitchen::Transport::Terraform.new(config).finalize_config! instance
252
+ end
214
253
 
215
254
  self
216
255
  end
@@ -226,7 +265,8 @@ module Kitchen
226
265
 
227
266
  private
228
267
 
229
- attr_accessor :action_failed, :create_strategy, :destroy_strategy
268
+ attr_accessor :action_failed, :deprecated_config
269
+ attr_writer :transport
230
270
  end
231
271
  end
232
272
  end
@@ -24,7 +24,7 @@ module Kitchen
24
24
  #
25
25
  # @see http://www.rubydoc.info/gems/test-kitchen/Kitchen/Provisioner
26
26
  module Provisioner
27
- # The provisioner applies changes to the Terraform state based on the configuration of the root module.
27
+ # The Terraform provisioner applies changes to the Terraform state based on the configuration of the root module.
28
28
  #
29
29
  # === Commands
30
30
  #
@@ -80,33 +80,20 @@ module Kitchen
80
80
  # @param state [Hash] the mutable instance and provisioner state.
81
81
  # @raise [Kitchen::ActionFailed] if the result of the action is a failure.
82
82
  def call(state)
83
- converge_strategy.call state: state
84
- rescue => error
85
- action_failed.call message: error.message
86
- end
83
+ driver = instance.driver
84
+ transport = driver.transport
87
85
 
88
- # #finalize_config! invokes the super implementation and then initializes the strategy.
89
- #
90
- # @param instance [Kitchen::Instance] an associated instance.
91
- # @raise [Kitchen::ClientError] if the instance is nil.
92
- # @return [self]
93
- # @see Kitchen::Configurable#finalize_config!
94
- def finalize_config!(instance)
95
- super instance
96
- self.action_failed = ::Kitchen::Terraform::Raise::ActionFailed.new logger: logger
97
- self.converge_strategy = ::Kitchen::Terraform::Provisioner::Converge.new(
98
- config: instance.driver.send(:config),
86
+ ::Kitchen::Terraform::Provisioner::Converge.new(
87
+ config: driver.send(:config),
88
+ connection: transport.connection({}),
89
+ debug_connection: transport.connection(logger: ::Kitchen::Terraform::DebugLogger.new(logger: logger)),
99
90
  logger: logger,
100
91
  version_requirement: version_requirement,
101
92
  workspace_name: workspace_name,
102
- )
103
-
104
- self
93
+ ).call state: state
94
+ rescue => error
95
+ ::Kitchen::Terraform::Raise::ActionFailed.new(logger: logger).call message: error.message
105
96
  end
106
-
107
- private
108
-
109
- attr_accessor :action_failed, :converge_strategy
110
97
  end
111
98
  end
112
99
  end
@@ -68,6 +68,24 @@ module Kitchen
68
68
  def config_client_default_value
69
69
  "terraform"
70
70
  end
71
+
72
+ # #doctor_config_client validates the client configuration.
73
+ #
74
+ # @return [Boolean] +true+ if any errors are found; +false+ if no errors are found.
75
+ def doctor_config_client
76
+ errors = false
77
+
78
+ if !::File.exist? config_client
79
+ errors = true
80
+ logger.error "client '#{config_client}' does not exist"
81
+ end
82
+ if !::File.executable? config_client
83
+ errors = true
84
+ logger.error "client '#{config_client}' is not executable"
85
+ end
86
+
87
+ errors
88
+ end
71
89
  end
72
90
  end
73
91
  end
@@ -579,6 +579,20 @@ module Kitchen
579
579
  end,
580
580
  schema: ::Kitchen::Terraform::ConfigAttributeContract::Systems.new,
581
581
  ).apply config_attribute: self
582
+
583
+ # #doctor_config_systems validates the systems configuration.
584
+ #
585
+ # @return [Boolean] +true+ if any errors are found; +false+ if no errors are found.
586
+ def doctor_config_systems
587
+ errors = false
588
+
589
+ if config_systems.empty?
590
+ errors = true
591
+ logger.error "systems is empty"
592
+ end
593
+
594
+ errors
595
+ end
582
596
  end
583
597
  end
584
598
  end
@@ -21,7 +21,7 @@ require "kitchen/terraform/config_attribute_contract/hash_of_symbols_and_strings
21
21
  module Kitchen
22
22
  module Terraform
23
23
  module ConfigAttributeType
24
- # This modules applies the behaviour of a configuration attribute of type hash of symbols and strings to a module
24
+ # This modules applies the behaviour of a configuration attribute of type hash of symbols and strings to a module
25
25
  # which must be included by a plugin class.
26
26
  #
27
27
  # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
@@ -22,7 +22,7 @@ require "kitchen/terraform/config_attribute_type"
22
22
  module Kitchen
23
23
  module Terraform
24
24
  module ConfigAttributeType
25
- # This module applies the behaviour of a configuration attribute of type integer to a module which must be
25
+ # This module applies the behaviour of a configuration attribute of type integer to a module which must be
26
26
  # included by a plugin class.
27
27
  #
28
28
  # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
@@ -39,7 +39,6 @@ module Kitchen
39
39
  # @param instance [Kitchen::Instance] an associated instance.
40
40
  # @raise [Kitchen::ClientError] if the instance is nil.
41
41
  # @return [self]
42
- # @see Kitchen::Configurable#finalize_config!
43
42
  def finalize_config!(instance)
44
43
  super instance
45
44
  self.version_requirement = ::Gem::Requirement.new ">= 0.11.4", "< 2.0.0"
@@ -15,11 +15,11 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require "kitchen"
18
+ require "kitchen/shell_out"
18
19
  require "kitchen/terraform/command/init_factory"
19
20
  require "kitchen/terraform/command/version"
20
21
  require "kitchen/terraform/command/workspace_new"
21
22
  require "kitchen/terraform/command/workspace_select"
22
- require "kitchen/terraform/command_executor"
23
23
  require "kitchen/terraform/verify_version"
24
24
  require "rubygems"
25
25
 
@@ -46,7 +46,7 @@ module Kitchen
46
46
  class Create
47
47
  # #call executes the action.
48
48
  #
49
- # @raise [Kitchen::TransientFailure] if a command fails.
49
+ # @raise [Kitchen::StandardError] if a command fails.
50
50
  # @return [self]
51
51
  def call
52
52
  read_client_version
@@ -60,23 +60,17 @@ module Kitchen
60
60
  # #initialize prepares a new instance of the class.
61
61
  #
62
62
  # @param config [Hash] the configuration of the driver.
63
+ # @param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
63
64
  # @param logger [Kitchen::Logger] a logger for logging messages.
64
65
  # @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
65
66
  # @param workspace_name [String] the name of the Terraform workspace to select or to create.
66
67
  # @option config [String] :client the pathname of the Terraform client.
67
68
  # @return [Kitchen::Terraform::Driver::Create]
68
- def initialize(config:, logger:, version_requirement:, workspace_name:)
69
+ def initialize(config:, connection:, logger:, version_requirement:, workspace_name:)
69
70
  self.complete_config = config.to_hash.merge upgrade_during_init: true, workspace_name: workspace_name
71
+ self.connection = connection
70
72
  self.client_version = ::Gem::Version.new "0.0.0"
71
- self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
72
- client: complete_config.fetch(:client),
73
- logger: logger,
74
- )
75
73
  self.logger = logger
76
- self.options = {
77
- cwd: complete_config.fetch(:root_module_directory),
78
- timeout: complete_config.fetch(:command_timeout),
79
- }
80
74
  self.workspace_name = workspace_name
81
75
  self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
82
76
  self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
@@ -92,10 +86,9 @@ module Kitchen
92
86
 
93
87
  attr_accessor(
94
88
  :client_version,
95
- :command_executor,
96
89
  :complete_config,
90
+ :connection,
97
91
  :logger,
98
- :options,
99
92
  :verify_version,
100
93
  :version,
101
94
  :workspace_name,
@@ -105,36 +98,28 @@ module Kitchen
105
98
 
106
99
  def create_or_select_workspace
107
100
  logger.warn "Creating the #{workspace_name} Terraform workspace..."
108
- command_executor.run command: workspace_new, options: options do |standard_output|
109
- end
101
+ connection.execute workspace_new
110
102
  logger.warn "Finished creating the #{workspace_name} Terraform workspace."
111
- rescue ::Kitchen::TransientFailure
103
+ rescue ::Kitchen::ShellOut::ShellCommandFailed
112
104
  select_workspace
113
105
  end
114
106
 
115
107
  def initialize_directory
116
108
  logger.warn "Initializing the Terraform working directory..."
117
- command_executor.run(
118
- command: ::Kitchen::Terraform::Command::InitFactory.new(version: client_version)
119
- .build(config: complete_config),
120
- options: options,
121
- ) do |standard_output|
122
- end
109
+ connection.execute ::Kitchen::Terraform::Command::InitFactory
110
+ .new(version: client_version).build(config: complete_config)
123
111
  logger.warn "Finished initializing the Terraform working directory."
124
112
  end
125
113
 
126
114
  def read_client_version
127
115
  logger.warn "Reading the Terraform client version..."
128
- command_executor.run command: version, options: options do |standard_output|
129
- self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
130
- end
116
+ self.client_version = ::Gem::Version.new connection.execute(version).slice /Terraform v(\d+\.\d+\.\d+)/, 1
131
117
  logger.warn "Finished reading the Terraform client version."
132
118
  end
133
119
 
134
120
  def select_workspace
135
121
  logger.warn "Selecting the #{workspace_name} Terraform workspace..."
136
- command_executor.run command: workspace_select, options: options do |standard_output|
137
- end
122
+ connection.execute workspace_select
138
123
  logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
139
124
  end
140
125
  end