kitchen-terraform 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a3511bbc6d10c08da856558d9f41949651cb0e38db183909d0f46ae885e6cdc
4
- data.tar.gz: dc2fdad8698f10114a5adfce900a60f2d203eef807350d71810a63e1958a8315
3
+ metadata.gz: 6bed93c8d3edcaa9b632a77af795ef201b1fb3f38851ad1f7b64bccaf0a562e8
4
+ data.tar.gz: 1276013ec6e8e44701db466c2f1fec4160040c55d2fdeade8b5c9819b3c1dc96
5
5
  SHA512:
6
- metadata.gz: 378c750cd2ddd73a30b04d3518a0f40d9fa01e4080d5a1014115793a51f999773c056cc46b908ca364e32780975792d77d0982b2d170316a9ec47bc63e043719
7
- data.tar.gz: 1fd8130d68184e45c1cffa8ee5fffebdd6bf2364eb24963b92411ed6ad64dc68bf9110b8d3add81bcfa1023df8b90c03b2e649d9b9a53a46321c755d0d934e18
6
+ metadata.gz: 85a1e4484b097b067041df44ef7a6e1d90ea57734df2e3f0ab45cb07d8a035da4405013ed76fa1928dafc7a65ac27a20877dfee8f933d6ecefd21db1dfbacc92
7
+ data.tar.gz: 4cbcc7946c975250266fa0dd725a1d8b7e3880929ccb592e30ae1ad1dea79859846c96914cdfd152098319f6024acf69bf6e48bc4cbc1e5d24e053f2c97dce07
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,76 +1,372 @@
1
- # ![kitchen-terraform logo](assets/logo.png) kitchen-terraform
1
+ # ![Kitchen-Terraform Logo][kitchen-terraform-logo] Kitchen-Terraform
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/kitchen-terraform.svg)](https://badge.fury.io/rb/kitchen-terraform)
4
- [![Code Climate](https://codeclimate.com/github/newcontext-oss/kitchen-terraform/badges/gpa.svg)](https://codeclimate.com/github/newcontext-oss/kitchen-terraform)
5
- [![Issue Count](https://codeclimate.com/github/newcontext-oss/kitchen-terraform/badges/issue_count.svg)](https://codeclimate.com/github/newcontext-oss/kitchen-terraform)
6
- [![Build Status Master](https://travis-ci.org/newcontext-oss/kitchen-terraform.svg?branch=master)](https://travis-ci.org/newcontext-oss/kitchen-terraform)
7
- [![Test Coverage](https://codeclimate.com/github/newcontext-oss/kitchen-terraform/badges/coverage.svg)](https://codeclimate.com/github/newcontext-oss/kitchen-terraform/coverage)
3
+ > Kitchen-Terraform enables verification of Terraform state.
8
4
 
9
- kitchen-terraform is a set of
10
- [Test Kitchen](http://kitchen.ci/index.html) plugins for testing
11
- [Terraform configuration](https://www.terraform.io/docs/configuration/index.html)
12
- .
5
+ [![Gem version][gem-version-shield]][kitchen-terraform-gem]
6
+ [![Gem downloads version][gem-downloads-version-shield]][kitchen-terraform-gem]
7
+ [![Gem downloads total][gem-downloads-total-shield]][kitchen-terraform-gem]
13
8
 
14
- ## Requirements
9
+ [![Build status][build-status-shield]][build-status]
10
+ [![Test coverage][test-coverage-shield]][test-coverage]
11
+ [![Maintainability][maintainability-shield]][maintainability]
12
+ [![Dependencies][gemnasium-shield]][gemnasium]
15
13
 
16
- - [Ruby](https://www.ruby-lang.org/en/index.html) **(~> 2.2)**
14
+ [![Gitter chat][gitter-shield]][gitter]
17
15
 
18
- - [Bundler](https://bundler.io/index.html) **(~> 1.12)**
16
+ Kitchen-Terraform provides a set of [Test Kitchen][test-kitchen] plugins
17
+ which enable a system to use Test Kitchen to converge a
18
+ [Terraform][terraform] configuration and verify the resulting Terraform
19
+ state with [InSpec][inspec] controls.
19
20
 
20
- - [Terraform](https://www.terraform.io/index.html)
21
- **(>= 0.10.2, < 0.12.0)**
21
+ As Kitchen-Terraform integrates several distinctive technologies in a
22
+ nontrivial manner, reviewing the documenation of each of the
23
+ aforementioned products is strongly encouraged.
22
24
 
23
25
  ## Installation
24
26
 
25
- kitchen-terraform is packaged as a cryptographically signed
26
- [Ruby gem](http://guides.rubygems.org/what-is-a-gem/index.html) which
27
- means it can be
28
- [installed with Bundler](https://bundler.io/index.html#getting-started).
27
+ ### Terraform
28
+
29
+ Kitchen-Terraform integrates with the
30
+ [Terraform command-line interface][terraform-cli] to implement a Test
31
+ Kitchen workflow for Terraform modules.
32
+
33
+ Installation instructions can be found in the
34
+ [Terraform: Install Terraform][terraform-install] article.
35
+
36
+ Kitchen-Terraform supports versions of Terraform in the interval of
37
+ `>= 0.10.2, < 0.12.0`.
38
+
39
+ [tfenv] can be used to manage versions of Terraform on the system.
40
+
41
+ ### Ruby
42
+
43
+ Kitchen-Terraform is written in [Ruby][ruby] which requires an
44
+ interpreter to be installed on the system.
45
+
46
+ Installation instructions can be found in the
47
+ [Ruby: Installing Ruby][ruby-installation] article.
48
+
49
+ Kitchen-Terraform aims to support all versions of Ruby that are in
50
+ ["normal" or "security" maintenance][ruby-branches], which is currently
51
+ the interval of `>= 2.2, < 2.5`.
52
+
53
+ [rbenv] can be used to manage versions of Ruby on the system.
54
+
55
+ ### Kitchen-Terraform Ruby Gem
56
+
57
+ Each version of Kitchen-Terraform is published as a
58
+ [Ruby gem][ruby-gems-what-is] to [RubyGems.org][kitchen-terraform-gem]
59
+ which makes them readily available for installation on a system.
60
+
61
+ #### RubyGems
62
+
63
+ To install a version of Kitchen-Terraform using the default Ruby package
64
+ manager, RubyGems, run a command like the following example.
65
+
66
+ > Installing Kitchen-Terraform with RubyGems
67
+
68
+ ```sh
69
+ gem install kitchen-terraform --version 3.1.0
70
+ ```
71
+
72
+ More information can be found in the
73
+ [RubyGems: Installing Gems][rubygems-installing-gems] article.
74
+
75
+ #### Bundler
29
76
 
30
- ### Adding kitchen-terraform to a Terraform project
77
+ [Bundler][bundler] can also be used to manage versions of
78
+ Kitchen-Terraform on the system in a manner that is easily reproducible
79
+ on other systems.
31
80
 
32
- Once Bundler is installed, add kitchen-terraform to the project's
33
- Gemfile:
81
+ First, create a `Gemfile` with contents like the following example. The
82
+ pessimistic pinning of the version is recommended to benefit from
83
+ the semantic versioning of the Ruby gem.
34
84
 
35
- ```rb
85
+ > Defining Kitchen-Terraform as a dependency for Bundler
86
+
87
+ ```ruby
36
88
  source "https://rubygems.org/" do
37
- gem "kitchen-terraform", "~> 3.0"
89
+ gem(
90
+ "kitchen-terraform",
91
+ "~> 3.1"
92
+ )
38
93
  end
39
94
  ```
40
95
 
41
- Then, use Bundler to install the gems:
96
+ Second, run the following command.
97
+
98
+ > Installing Kitchen-Terraform with Bundler
42
99
 
43
100
  ```sh
44
101
  bundle install
45
102
  ```
46
103
 
104
+ More information can be found in the
105
+ [Bundler: In Depth][bundler-in-depth] article.
106
+
47
107
  ## Usage
48
108
 
49
- kitchen-terraform provides three Test Kitchen plugins which must be used
50
- together in the
51
- [Test Kitchen configuration](https://docs.chef.io/config_yml_kitchen.html)
52
- in order to successfully test Terraform configuration:
109
+ ### Configuration
110
+
111
+ Kitchen-Terraform provides three Test Kitchen plugins which must be
112
+ configured in a
113
+ [Test Kitchen configuration file][test-kitchen-configuration-file] in
114
+ order to successfully test Terraform configuration.
115
+
116
+ The [Terraform driver][terraform-driver] manages the state of the
117
+ Terraform root module.
53
118
 
54
- - a [driver](http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Driver/Terraform)
55
- that creates and destroys
56
- [Terraform state](https://www.terraform.io/docs/state/index.html);
119
+ The [Terraform provisioner][terraform-provisioner] uses the Terraform
120
+ driver to apply changes to the Terraform state.
57
121
 
58
- - a [provisioner](http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Provisioner/Terraform)
59
- that applies changes to existing Terraform state;
122
+ The [Terraform verifier][terraform-verifier] uses InSpec to verify the
123
+ Terraform state.
60
124
 
61
- - a [verifier](http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Verifier/Terraform)
62
- that verifies the state and behaviour of resources in the Terraform
63
- state.
125
+ More information can be found in the
126
+ [Ruby gem documentation][ruby-gem-documentation].
64
127
 
65
- Refer to the [gem documentation](http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/)
66
- for more information about kitchen-terraform's design and behaviour.
128
+ ### Example
67
129
 
68
- Refer to the
69
- [Getting Started Tutorial](https://newcontext-oss.github.io/kitchen-terraform/tutorials/amazon_provider_ec2.html)
70
- for a detailed walkthrough of setting up and using kitchen-terraform.
130
+ Assume there is a system which has Kitchen-Terraform and
131
+ [Docker][docker] installed.
71
132
 
72
- Refer to the
73
- [tutorials](https://newcontext-oss.github.io/kitchen-terraform/tutorials)
74
- for example Terraform projects using various
75
- [Terraform providers](https://www.terraform.io/docs/configuration/providers.html)
133
+ Assume the working directory on said system a hierarchy like the
134
+ following examples.
135
+
136
+ > Directory hierarchy
137
+
138
+ ```
76
139
  .
140
+ ├── .kitchen.yml
141
+ ├── main.tf
142
+ └── test
143
+ └── integration
144
+ └── example
145
+ ├── controls
146
+ │   ├── operating_system.rb
147
+ └── inspec.yml
148
+ ```
149
+
150
+ > ./.kitchen.yml
151
+
152
+ ```yaml
153
+ driver:
154
+ name: terraform
155
+
156
+ provisioner:
157
+ name: terraform
158
+
159
+ transport:
160
+ name: ssh
161
+ password: root
162
+
163
+ verifier:
164
+ name: terraform
165
+ groups:
166
+ - name: container
167
+ port: 2222
168
+ username: root
169
+
170
+ platforms:
171
+ - name: ubuntu
172
+
173
+ suites:
174
+ - name: example
175
+ ```
176
+
177
+ > ./main.tf
178
+
179
+ ```hcl
180
+ provider "docker" {
181
+ host = "unix://localhost/var/run/docker.sock"
182
+ }
183
+
184
+ data "docker_registry_image" "ubuntu" {
185
+ name = "rastasheep/ubuntu-sshd:latest"
186
+ }
187
+
188
+ resource "docker_image" "ubuntu" {
189
+ name = "${data.docker_registry_image.ubuntu.name}"
190
+ pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"]
191
+ }
192
+
193
+ resource "docker_container" "ubuntu" {
194
+ image = "${docker_image.ubuntu.name}"
195
+ must_run = true
196
+ name = "ubuntu_container"
197
+
198
+ ports {
199
+ external = 2222
200
+ internal = 22
201
+ }
202
+ }
203
+ ```
204
+
205
+ > ./test/integration/example/inspec.yml
206
+
207
+ ```yaml
208
+ name: example
209
+ ```
210
+
211
+ > ./test/integration/example/controls/operating_system.rb
212
+
213
+ ```ruby
214
+ # frozen_string_literal: true
215
+
216
+ control "operating_system" do
217
+ describe "the operating system" do
218
+ subject do
219
+ command("lsb_release -a").stdout
220
+ end
221
+
222
+ it "is Ubuntu" do
223
+ is_expected.to match /Ubuntu/
224
+ end
225
+ end
226
+ end
227
+ ```
228
+
229
+ Running the following command would initialize the working directory for
230
+ Terraform, create a Docker container by applying the configuration file,
231
+ and verify that the container is running Ubuntu.
232
+
233
+ > Verifying with Kitchen-Terraform
234
+
235
+ ```sh
236
+ $ kitchen test
237
+ -----> Starting Kitchen...
238
+ ...
239
+ $$$$$$ Running command `terraform init...`
240
+ ...
241
+ $$$$$$ Running command `terraform apply...`
242
+ ...
243
+ docker_container.ubuntu: Creation complete after 1s...
244
+
245
+ Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
246
+ ...
247
+ Finished converging <example-ubuntu>...
248
+ ...
249
+ -----> Verifying <example-ubuntu>...
250
+ Verifying host 'localhost' of group 'container'
251
+ ...
252
+ ✔ operating_system: the operating system is Ubuntu
253
+ ...
254
+ Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
255
+ ...
256
+ ```
257
+
258
+ More information can be found on the
259
+ [Kitchen-Terraform Tutorials][kitchen-terraform-tutorials] page.
260
+
261
+ ## Contributing
262
+
263
+ Kitchen-Terraform thrives on community contributions.
264
+
265
+ Information about contributing to Kitchen-Terraform can be found in the
266
+ [Contributing document][contributing-document].
267
+
268
+ ## Developing
269
+
270
+ Pull requests to Kitchen-Terraform are always welcome!
271
+
272
+ Information about developing Kitchen-Terraform can be found in the
273
+ [Developing document][developing-document].
274
+
275
+ ## Changelog
276
+
277
+ Kitchen-Terraform adheres to semantic versioning and documents all
278
+ significant changes accordingly.
279
+
280
+ Information about changes to Kitchen-Terraform can be found in the
281
+ [Changelog][changelog].
282
+
283
+ ## Maintainers
284
+
285
+ Kitchen-Terraform is maintained by New Context.
286
+
287
+ <img
288
+ alt="New Context logo"
289
+ height="25"
290
+ src="https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/new_context_logo.png"
291
+ width="25"> [NewContext.com][new-context]
292
+
293
+ <img
294
+ alt="Twitter logo"
295
+ height="25"
296
+ src="https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/twitter_logo.png"
297
+ width="25"> [@NewContext][new-context-twitter]
298
+
299
+ <img
300
+ alt="LinkedIn logo"
301
+ height="23"
302
+ src="https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/linkedin_logo.png"
303
+ width="25"> [New Context][new-context-linkedin]
304
+
305
+ <img
306
+ alt="GitHub logo"
307
+ height="25"
308
+ src="https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/github_logo.png"
309
+ width="25"> [@NewContext][new-context-github]
310
+
311
+ <img
312
+ alt="Email logo"
313
+ height="16"
314
+ src="https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/email_logo.png"
315
+ width="25"> kitchen-terraform@newcontext.com
316
+
317
+ <img
318
+ alt="Email logo"
319
+ height="16"
320
+ src="https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/email_logo.png"
321
+ width="25"> info@newcontext.com
322
+
323
+ ## License
324
+
325
+ Kitchen-Terraform is distributed under the [Apache License][license].
326
+
327
+ <!-- Markdown links and image definitions -->
328
+ [build-status-shield]: https://img.shields.io/travis/newcontext-oss/kitchen-terraform.svg?style=plastic
329
+ [build-status]: https://travis-ci.org/newcontext-oss/kitchen-terraform
330
+ [bundler-getting-started]: https://bundler.io/#getting-started
331
+ [bundler-in-depth]: https://bundler.io/gemfile.html
332
+ [bundler]: https://bundler.io/index.html#getting-started
333
+ [changelog]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/CHANGELOG.md
334
+ [contributing-document]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/CONTRIBUTING.md
335
+ [developing-document]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/DEVELOPING.md
336
+ [docker]: https://www.docker.com/
337
+ [gem-downloads-total-shield]: https://img.shields.io/gem/dt/kitchen-terraform.svg?style=plastic
338
+ [gem-downloads-version-shield]: https://img.shields.io/gem/dtv/kitchen-terraform.svg?style=plastic
339
+ [gem-version-shield]: https://img.shields.io/gem/v/kitchen-terraform.svg?style=plastic
340
+ [gemnasium-shield]: https://img.shields.io/gemnasium/newcontext-oss/kitchen-terraform.svg?style=plastic
341
+ [gemnasium]: https://beta.gemnasium.com/projects/github.com/newcontext-oss/kitchen-terraform
342
+ [gitter-shield]: https://img.shields.io/gitter/room/kitchen-terraform/Lobby.svg?style=plastic
343
+ [gitter]: https://gitter.im/kitchen-terraform/Lobby
344
+ [inspec]: https://www.inspec.io/
345
+ [kitchen-terraform-gem]: https://rubygems.org/gems/kitchen-terraform
346
+ [kitchen-terraform-logo]: https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/logo.png
347
+ [kitchen-terraform-tutorials]: https://newcontext-oss.github.io/kitchen-terraform/tutorials/
348
+ [license]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/LICENSE
349
+ [maintainability-shield]: https://img.shields.io/codeclimate/maintainability/newcontext-oss/kitchen-terraform.svg?style=plastic
350
+ [maintainability]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/maintainability
351
+ [new-context-github]: https://github.com/newcontext
352
+ [new-context-linkedin]: https://www.linkedin.com/company/-new-context-
353
+ [new-context-twitter]: https://twitter.com/newcontext
354
+ [new-context]: https://newcontext.com/
355
+ [rbenv]: https://github.com/rbenv/rbenv
356
+ [ruby-branches]: https://www.ruby-lang.org/en/downloads/branches/
357
+ [ruby-gem-documentation]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/
358
+ [ruby-gems-what-is]: http://guides.rubygems.org/ruby-gems-what-is/index.html
359
+ [ruby-installation]: https://www.ruby-lang.org/en/documentation/installation/
360
+ [ruby]: https://www.ruby-lang.org/en/
361
+ [rubygems-installing-gems]: http://guides.rubygems.org/rubygems-basics/#rubygems-installing-gems
362
+ [terraform-cli]: https://www.terraform.io/docs/commands/index.html
363
+ [terraform-driver]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Driver/Terraform
364
+ [terraform-install]: https://www.terraform.io/intro/getting-started/install.html
365
+ [terraform-provisioner]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Provisioner/Terraform
366
+ [terraform-verifier]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Verifier/Terraform
367
+ [terraform]: https://www.terraform.io/
368
+ [test-coverage-shield]: https://img.shields.io/codeclimate/c/newcontext-oss/kitchen-terraform.svg?style=plastic
369
+ [test-coverage]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/test_coverage
370
+ [test-kitchen-configuration-file]: https://docs.chef.io/config_yml_kitchen.html
371
+ [test-kitchen]: http://kitchen.ci/index.html
372
+ [tfenv]: https://github.com/kamatama41/tfenv
@@ -14,11 +14,10 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "dry/monads"
18
- require "json"
19
17
  require "kitchen/driver/base"
20
18
  require "kitchen/errors"
21
19
  require "kitchen/terraform/client_version_verifier"
20
+ require "kitchen/terraform/command/output"
22
21
  require "kitchen/terraform/config_attribute/backend_configurations"
23
22
  require "kitchen/terraform/config_attribute/color"
24
23
  require "kitchen/terraform/config_attribute/command_timeout"
@@ -174,10 +173,6 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
174
173
 
175
174
  no_parallel_for
176
175
 
177
- include ::Dry::Monads::Either::Mixin
178
-
179
- include ::Dry::Monads::Try::Mixin
180
-
181
176
  include ::Kitchen::Terraform::ConfigAttribute::BackendConfigurations
182
177
 
183
178
  include ::Kitchen::Terraform::ConfigAttribute::Color
@@ -201,41 +196,35 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
201
196
  # Applies changes to the state by selecting the test workspace, updating the dependency modules, validating the root
202
197
  # module, applying the state changes, and retrieving the state output.
203
198
  #
204
- # @return [::Dry::Monads::Either] the result of the action.
205
- def apply
206
- apply_run_workspace_select_instance
207
- .bind do
208
- apply_run_get
209
- end
210
- .bind do
211
- apply_run_validate
212
- end
213
- .bind do
214
- apply_run_apply
215
- end
216
- .bind do
217
- apply_run_output
218
- end
199
+ # @raise [::Kitchen::Terraform::Error] if one of the steps fails.
200
+ # @return [void]
201
+ # @yieldparam output [::String] the state output.
202
+ def apply(&block)
203
+ run_workspace_select_instance
204
+ apply_run_get
205
+ apply_run_validate
206
+ apply_run_apply
207
+ ::Kitchen::Terraform::Command::Output
208
+ .run(
209
+ duration: config_command_timeout,
210
+ logger: logger,
211
+ &block
212
+ )
219
213
  end
220
214
 
221
215
  # Creates a Test Kitchen instance by initializing the working directory and creating a test workspace.
222
216
  #
223
217
  # @param _state [::Hash] the mutable instance and driver state.
224
218
  # @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
219
+ # @return [void]
225
220
  def create(_state)
226
221
  create_run_init
227
- .bind do
228
- create_run_workspace_new_instance
229
- .or do
230
- create_run_workspace_select_instance
231
- end
232
- end
233
- .or do |failure|
234
- raise(
235
- ::Kitchen::ActionFailed,
236
- failure
237
- )
238
- end
222
+ run_workspace_select_instance
223
+ rescue ::Kitchen::Terraform::Error => error
224
+ raise(
225
+ ::Kitchen::ActionFailed,
226
+ error.message
227
+ )
239
228
  end
240
229
 
241
230
  # Destroys a Test Kitchen instance by initializing the working directory, selecting the test workspace,
@@ -243,54 +232,44 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
243
232
  #
244
233
  # @param _state [::Hash] the mutable instance and driver state.
245
234
  # @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
235
+ # @return [void]
246
236
  def destroy(_state)
247
237
  destroy_run_init
248
- .bind do
249
- destroy_run_workspace_select_instance
250
- .or do
251
- destroy_run_workspace_new_instance
252
- end
253
- end
254
- .bind do
255
- destroy_run_destroy
256
- end
257
- .bind do
258
- destroy_run_workspace_select_default
259
- end
260
- .bind do
261
- destroy_run_workspace_delete_instance
262
- end
263
- .or do |failure|
264
- raise(
265
- ::Kitchen::ActionFailed,
266
- failure
267
- )
268
- end
238
+ run_workspace_select_instance
239
+ destroy_run_destroy
240
+ destroy_run_workspace_select_default
241
+ destroy_run_workspace_delete_instance
242
+ rescue ::Kitchen::Terraform::Error => error
243
+ raise(
244
+ ::Kitchen::ActionFailed,
245
+ error.message
246
+ )
269
247
  end
270
248
 
271
249
  # Verifies that the Terraform version available to the driver is supported.
272
250
  #
273
251
  # @raise [::Kitchen::UserError] if the version is not supported.
252
+ # @return [void]
274
253
  def verify_dependencies
275
- ::Kitchen::Terraform::ShellOut
276
- .run(
277
- command: "version",
278
- logger: logger
279
- )
280
- .bind do |output|
254
+ logger
255
+ .warn(
281
256
  ::Kitchen::Terraform::ClientVersionVerifier
282
257
  .new
283
- .verify version_output: output
284
- end
285
- .or do |failure|
286
- raise(
287
- ::Kitchen::UserError,
288
- failure
289
- )
290
- end
291
- .bind do |verified_client_version|
292
- logger.warn verified_client_version
293
- end
258
+ .verify(
259
+ version_output:
260
+ ::Kitchen::Terraform::ShellOut
261
+ .run(
262
+ command: "version",
263
+ duration: 600,
264
+ logger: logger
265
+ )
266
+ )
267
+ )
268
+ rescue ::Kitchen::Terraform::Error => error
269
+ raise(
270
+ ::Kitchen::UserError,
271
+ error.message
272
+ )
294
273
  end
295
274
 
296
275
  private
@@ -326,35 +305,6 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
326
305
  )
327
306
  end
328
307
 
329
- # @api private
330
- def apply_run_output
331
- ::Kitchen::Terraform::ShellOut
332
- .run(
333
- command: "output -json",
334
- duration: config_command_timeout,
335
- logger: logger
336
- )
337
- .bind do |output|
338
- Try ::JSON::ParserError do
339
- ::JSON.parse output
340
- end
341
- .to_either
342
- .or do |error|
343
- Left "Parsing Terraform output as JSON failed: #{error}"
344
- end
345
- end
346
- end
347
-
348
- # @api private
349
- def apply_run_workspace_select_instance
350
- ::Kitchen::Terraform::ShellOut
351
- .run(
352
- command: "workspace select kitchen-terraform-#{instance.name}",
353
- duration: config_command_timeout,
354
- logger: logger
355
- )
356
- end
357
-
358
308
  # @api private
359
309
  def apply_run_validate
360
310
  ::Kitchen::Terraform::ShellOut
@@ -395,26 +345,6 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
395
345
  )
396
346
  end
397
347
 
398
- # @api private
399
- def create_run_workspace_new_instance
400
- ::Kitchen::Terraform::ShellOut
401
- .run(
402
- command: "workspace new kitchen-terraform-#{instance.name}",
403
- duration: config_command_timeout,
404
- logger: logger
405
- )
406
- end
407
-
408
- # @api private
409
- def create_run_workspace_select_instance
410
- ::Kitchen::Terraform::ShellOut
411
- .run(
412
- command: "workspace select kitchen-terraform-#{instance.name}",
413
- duration: config_command_timeout,
414
- logger: logger
415
- )
416
- end
417
-
418
348
  # @api private
419
349
  def destroy_run_destroy
420
350
  ::Kitchen::Terraform::ShellOut
@@ -463,37 +393,39 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
463
393
  def destroy_run_workspace_delete_instance
464
394
  ::Kitchen::Terraform::ShellOut
465
395
  .run(
466
- command: "workspace delete kitchen-terraform-#{instance.name}",
396
+ command: "workspace delete kitchen-terraform-#{instance_name}",
467
397
  duration: config_command_timeout,
468
398
  logger: logger
469
399
  )
470
400
  end
471
401
 
472
402
  # @api private
473
- def destroy_run_workspace_new_instance
403
+ def destroy_run_workspace_select_default
474
404
  ::Kitchen::Terraform::ShellOut
475
405
  .run(
476
- command: "workspace new kitchen-terraform-#{instance.name}",
406
+ command: "workspace select default",
477
407
  duration: config_command_timeout,
478
408
  logger: logger
479
409
  )
480
410
  end
481
411
 
482
412
  # @api private
483
- def destroy_run_workspace_select_default
413
+ def instance_name
414
+ @instance_name ||= instance.name
415
+ end
416
+
417
+ # @api private
418
+ def run_workspace_select_instance
484
419
  ::Kitchen::Terraform::ShellOut
485
420
  .run(
486
- command: "workspace select default",
421
+ command: "workspace select kitchen-terraform-#{instance_name}",
487
422
  duration: config_command_timeout,
488
423
  logger: logger
489
424
  )
490
- end
491
-
492
- # @api private
493
- def destroy_run_workspace_select_instance
425
+ rescue ::Kitchen::Terraform::Error
494
426
  ::Kitchen::Terraform::ShellOut
495
427
  .run(
496
- command: "workspace select kitchen-terraform-#{instance.name}",
428
+ command: "workspace new kitchen-terraform-#{instance_name}",
497
429
  duration: config_command_timeout,
498
430
  logger: logger
499
431
  )