kitchen-terraform 5.2.0 → 5.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df1c8cf5af302e8ff0157356cdcd17b629b4613a279f44f6776b1c83532fee55
4
- data.tar.gz: ddf2fee8e8b4191bdae7305ca3c2fb1464c58aa9eff9edbfe14495051f31d757
3
+ metadata.gz: 6a04795845f5a5170e57deaad7c5741daacfd678429a0089d1b94bd14c1affe6
4
+ data.tar.gz: 6e448fa5468092c57bb10876b4d326db67ebd845cd863b4ce6866712d8238b8b
5
5
  SHA512:
6
- metadata.gz: 179e8d7217c594ad88c2bcfe3c81537a7ac18a4b9a0ff9645a56261ec6143468e08d026e99fdd105c253a8567e19f0df9293a1b91a0143a81687ae7b69c963ac
7
- data.tar.gz: f32b9ebb0be2ca34102d51650bf0d73e83807a6d49ab38de21aac89c188be9850ff9d2c1a995d9a154c4a83fe044a3529f2ee53f3f8153158b77049bbd655aee
6
+ metadata.gz: 6808efc6bdeee619f164e8f6f9d06efec200828a21d79138ae481ca2eec756e4904694c55ed9c87fc0b619f724e5e3d641ab1da9e742549ef34c327a0656d7a7
7
+ data.tar.gz: 89acb6a22c11637b82afdf6c42fedaff6adab1f18dc4501c3a829b00b03750d6af8904062e940c276cd63727a0d33cc5c794375312acb3773f548518e1b6b5e6
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ![Kitchen-Terraform Logo][kitchen-terraform-logo] Kitchen-Terraform
2
2
 
3
- > Kitchen-Terraform enables verification of Terraform state.
3
+ > Kitchen-Terraform enables verification of infrastructure systems provisioned with Terraform.
4
4
 
5
5
  [![Gem version][gem-version-shield]][kitchen-terraform-gem]
6
6
  [![Gem downloads version][gem-downloads-version-shield]][kitchen-terraform-gem]
@@ -15,10 +15,10 @@
15
15
 
16
16
  [![Gitter chat][gitter-shield]][gitter]
17
17
 
18
- Kitchen-Terraform provides a set of [Test Kitchen][test-kitchen] plugins
19
- which enable a system to use Test Kitchen to converge a
20
- [Terraform][terraform] configuration and verify the resulting Terraform
21
- state with [InSpec][inspec] controls.
18
+ Kitchen-Terraform provides a set of [Kitchen][kitchen] plugins
19
+ which enable the use of Kitchen to converge a [Terraform][terraform]
20
+ configuration and verify the resulting infrastructure systems with
21
+ [InSpec][inspec] controls.
22
22
 
23
23
  As Kitchen-Terraform integrates several distinctive technologies in a
24
24
  nontrivial manner, reviewing the documentation of each of the
@@ -36,7 +36,7 @@ Installation instructions can be found in the
36
36
  [Terraform: Install Terraform][terraform-install] article.
37
37
 
38
38
  Kitchen-Terraform supports versions of Terraform in the interval of
39
- `>= 0.11.4, < 0.13.0`.
39
+ `>= 0.11.4, < 0.15.0`.
40
40
 
41
41
  [tfenv] can be used to manage versions of Terraform on the system.
42
42
 
@@ -50,7 +50,7 @@ Installation instructions can be found in the
50
50
 
51
51
  Kitchen-Terraform aims to support all versions of Ruby that are in
52
52
  ["normal" or "security" maintenance][ruby-branches], which is currently
53
- the interval of `>= 2.4, < 2.7`.
53
+ the interval of `>= 2.4, < 2.8`.
54
54
 
55
55
  [rbenv] can be used to manage versions of Ruby on the system.
56
56
 
@@ -75,7 +75,7 @@ the semantic versioning of the Ruby gem.
75
75
 
76
76
  ```ruby
77
77
  source "https://rubygems.org/" do
78
- gem "kitchen-terraform", "~> 5.2"
78
+ gem "kitchen-terraform", "~> 5.6"
79
79
  end
80
80
  ```
81
81
 
@@ -102,7 +102,7 @@ example.
102
102
  > Installing Kitchen-Terraform with RubyGems
103
103
 
104
104
  ```sh
105
- gem install kitchen-terraform --version 5.2.0
105
+ gem install kitchen-terraform --version 5.7.0
106
106
  ```
107
107
 
108
108
  This approach is not recommended as it requires more effort to install
@@ -128,7 +128,7 @@ Ed25519-type SSH keys.
128
128
 
129
129
  Kitchen-Terraform provides three Test Kitchen plugins which must be
130
130
  configured in a
131
- [Test Kitchen configuration file][test-kitchen-configuration-file] in
131
+ [Kitchen configuration file][kitchen-configuration-file] in
132
132
  order to successfully test Terraform configuration.
133
133
 
134
134
  The [Terraform driver][terraform-driver] manages the state of the
@@ -143,167 +143,27 @@ Terraform state.
143
143
  More information can be found in the
144
144
  [Ruby gem documentation][ruby-gem-documentation].
145
145
 
146
- ### Example
146
+ ### Caveats
147
147
 
148
- This example demonstrates how to test a simple Terraform configuration
149
- which utilizes the [Docker provider][docker-provider].
148
+ Versions of Terraform in the 0.11 series may cause `kitchen test` to
149
+ fail if the initial destroy targets an empty Terraform state. A
150
+ workaround for this problem is to use
151
+ `kitchen verify && kitchen destroy` instead of `kitchen test`. More
152
+ details about the problem are available in
153
+ [issue #271](issue-271).
150
154
 
151
- The test system is assumed to be running Ubuntu 17.04.
155
+ ### Tutorials and Examples
152
156
 
153
- Terraform, Ruby, and Bundler are assumed to have been installed on the
154
- test system as described in the [Installation](#installation) section.
155
-
156
- The [Docker Community Edition][docker-community-edition] is assumed to
157
- have been installed on the test system.
158
-
159
- The working directory on the test system is assumed to contain a
160
- hierarchy of files comprising the following blocks.
161
-
162
- > Directory hierarchy
163
-
164
- ```
165
- .
166
- ├── .kitchen.yml
167
- ├── Gemfile
168
- ├── main.tf
169
- ├── outputs.tf
170
- └── test
171
- └── integration
172
- └── example
173
- ├── controls
174
- │   ├── operating_system.rb
175
- └── inspec.yml
176
- ```
177
-
178
- > Gemfile
179
-
180
- ```ruby
181
- source "https://rubygems.org/"
182
-
183
- gem 'kitchen-terraform', '~> 5.1'
184
- ```
185
-
186
- > ./kitchen.yml (Test Kitchen configuration)
187
-
188
- ```yaml
189
- driver:
190
- name: terraform
191
-
192
- provisioner:
193
- name: terraform
194
-
195
- verifier:
196
- name: terraform
197
- systems:
198
- - name: container
199
- backend: ssh
200
- hosts_output: container_hostname
201
- password: root
202
- port: 2222
203
- user: root
204
-
205
- platforms:
206
- - name: ubuntu
207
-
208
- suites:
209
- - name: example
210
- ```
211
-
212
- Although Kitchen-Terraform supports multiple versions of Terraform, below snippets are compatible with v0.12:
213
- > ./main.tf
214
-
215
- ```hcl
216
- provider "docker" {
217
- host = "unix:///var/run/docker.sock"
218
- }
219
-
220
- data "docker_registry_image" "ubuntu" {
221
- name = "rastasheep/ubuntu-sshd:latest"
222
- }
223
-
224
- resource "docker_image" "ubuntu" {
225
- name = data.docker_registry_image.ubuntu.name
226
- pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"]
227
- }
228
-
229
- resource "docker_container" "ubuntu" {
230
- image = docker_image.ubuntu.name
231
- must_run = true
232
- name = "ubuntu_container"
233
-
234
- ports {
235
- external = 2222
236
- internal = 22
237
- }
238
- }
239
- ```
240
-
241
- > ./outputs.tf
242
-
243
- ```hcl
244
- output "container_hostname" {
245
- description = "The hostname of the container."
246
- value = "127.0.0.1"
247
- }
248
- ```
249
-
250
- > ./test/integration/example/inspec.yml
251
-
252
- ```yaml
253
- name: example
254
- ```
255
-
256
- > ./test/integration/example/controls/operating_system.rb
257
-
258
- ```ruby
259
- # frozen_string_literal: true
260
-
261
- control "operating_system" do
262
- describe "the operating system" do
263
- subject do
264
- command("cat /etc/os-release").stdout
265
- end
266
-
267
- it "is Ubuntu" do
268
- is_expected.to match /Ubuntu/
269
- end
270
- end
271
- end
272
- ```
273
-
274
- Running the following command would initialize the working directory for
275
- Terraform, create a Docker container by applying the configuration file,
276
- and verify that the container is running Ubuntu.
277
-
278
- > Verifying with Kitchen-Terraform
279
-
280
- ```sh
281
- $ bundle install
282
- $ bundle exec kitchen test
283
- -----> Starting Kitchen...
284
- ...
285
- $$$$$$ Running command `terraform init...`
286
- ...
287
- $$$$$$ Running command `terraform apply...`
288
- ...
289
- docker_container.ubuntu: Creation complete after 1s...
290
-
291
- Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
292
- ...
293
- Finished converging <example-ubuntu>...
294
- ...
295
- -----> Verifying <example-ubuntu>...
296
- Verifying host 'localhost' of system 'container'
297
- ...
298
- ✔ operating_system: the operating system is Ubuntu
299
- ...
300
- Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
301
- ...
302
- ```
303
-
304
- More information can be found on the
157
+ Several tutorials are available on the
305
158
  [Kitchen-Terraform Tutorials][kitchen-terraform-tutorials] page.
306
159
 
160
+ The integration tests for Kitchen-Terraform can also be viewed as
161
+ examples of how it works. The
162
+ [integration test Kitchen configuration file][int-kitchen-config]
163
+ and the [integration test directory][test-directory] provide several
164
+ functional examples which exercise various features of
165
+ Kitchen-Terraform.
166
+
307
167
  ## Contributing
308
168
 
309
169
  Kitchen-Terraform thrives on community contributions.
@@ -321,7 +181,8 @@ Information about changes to Kitchen-Terraform can be found in the
321
181
 
322
182
  ## Maintainers
323
183
 
324
- Kitchen-Terraform is maintained by New Context.
184
+ Kitchen-Terraform is maintained by [community contributors][contributors]
185
+ and New Context.
325
186
 
326
187
  <img
327
188
  alt="New Context logo"
@@ -374,17 +235,22 @@ Kitchen-Terraform is distributed under the [Apache License][license].
374
235
  [code-coverage-shield]: https://img.shields.io/codeclimate/coverage/newcontext-oss/kitchen-terraform.svg
375
236
  [code-coverage]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/
376
237
  [contributing-document]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/CONTRIBUTING.md
238
+ [contributors]: https://github.com/newcontext-oss/kitchen-terraform/graphs/contributors
377
239
  [docker]: https://www.docker.com/
378
240
  [docker-community-edition]: https://store.docker.com/editions/community/docker-ce-server-ubuntu
379
241
  [docker-provider]: https://www.terraform.io/docs/providers/docker/index.html
380
242
  [gem-downloads-total-shield]: https://img.shields.io/gem/dt/kitchen-terraform.svg
381
243
  [gem-downloads-version-shield]: https://img.shields.io/gem/dtv/kitchen-terraform.svg
382
244
  [gem-version-shield]: https://img.shields.io/gem/v/kitchen-terraform.svg
383
- [hakiri-shield]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/master.svg
384
- [hakiri]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/
385
245
  [gitter-shield]: https://img.shields.io/gitter/room/kitchen-terraform/Lobby.svg
386
246
  [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/
387
249
  [inspec]: https://www.inspec.io/
250
+ [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
+ [kitchen-configuration-file]: https://docs.chef.io/config_yml_kitchen.html
388
254
  [kitchen-terraform-gem]: https://rubygems.org/gems/kitchen-terraform
389
255
  [kitchen-terraform-logo]: https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/logo.png
390
256
  [kitchen-terraform-tutorials]: https://newcontext-oss.github.io/kitchen-terraform/tutorials/
@@ -411,8 +277,7 @@ Kitchen-Terraform is distributed under the [Apache License][license].
411
277
  [terraform-provisioner]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Provisioner/Terraform
412
278
  [terraform-verifier]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Verifier/Terraform
413
279
  [terraform]: https://www.terraform.io/
414
- [test-kitchen-configuration-file]: https://docs.chef.io/config_yml_kitchen.html
415
- [test-kitchen]: http://kitchen.ci/index.html
280
+ [test-directory]: https://github.com/newcontext-oss/kitchen-terraform/tree/master/test
416
281
  [tfenv]: https://github.com/kamatama41/tfenv
417
282
  [travis-build-status-shield]: https://img.shields.io/travis/com/newcontext-oss/kitchen-terraform.svg
418
283
  [travis-build-status]: https://travis-ci.com/newcontext-oss/kitchen-terraform
@@ -130,6 +130,8 @@ module Kitchen
130
130
  #
131
131
  # The +bastion_host+ key must be used in combination with a backend which supports remote connections.
132
132
  #
133
+ # The +bastion_host_output+ key will take priority over the +bastion_host+ key.
134
+ #
133
135
  # <em>Example kitchen.yml</em>
134
136
  # verifier:
135
137
  # name: terraform
@@ -138,12 +140,29 @@ module Kitchen
138
140
  # backend: ssh
139
141
  # bastion_host: bastion-host.domain
140
142
  #
143
+ # ====== bastion_host_output
144
+ #
145
+ # The value of the +bastion_host_output+ key is a scalar which is used to obtain the address of a bastion host in
146
+ # the system from a Terraform output.
147
+ #
148
+ # The scalar must match the name of an output with a value which is a string.
149
+ #
150
+ # The +bastion_host_output+ key must be used in combination with a backend which enables remote connections.
151
+ #
152
+ # <em>Example kitchen.yml</em>
153
+ # verifier:
154
+ # name: terraform
155
+ # systems:
156
+ # - name: a system
157
+ # backend: ssh
158
+ # bastion_host_output: an_output
159
+ #
141
160
  # ====== bastion_port
142
161
  #
143
162
  # The value of the +bastion_port+ key is an integer which is used as the port number to connect to on the bastion
144
163
  # host.
145
164
  #
146
- # The +bastion_port+ key must be used in combination with the +bastion_host+ key.
165
+ # The +bastion_port+ key must be used in combination with the +bastion_host_output+ key or the +bastion_host+ key.
147
166
  #
148
167
  # <em>Example kitchen.yml</em>
149
168
  # verifier:
@@ -151,7 +170,7 @@ module Kitchen
151
170
  # systems:
152
171
  # - name: a system
153
172
  # backend: ssh
154
- # bastion_host: bastion-host.domain
173
+ # bastion_host_output: an_output
155
174
  # bastion_port: 1234
156
175
  #
157
176
  # ====== bastion_user
@@ -159,7 +178,7 @@ module Kitchen
159
178
  # The value of the +bastion_user+ key is a scalar which is used as the username for authentication with the
160
179
  # bastion host.
161
180
  #
162
- # The +bastion_user+ key must be used in combination with the +bastion_host+ key.
181
+ # The +bastion_user+ key must be used in combination with the +bastion_host_output+ key or the +bastion_host+ key.
163
182
  #
164
183
  # <em>Example kitchen.yml</em>
165
184
  # verifier:
@@ -167,7 +186,7 @@ module Kitchen
167
186
  # systems:
168
187
  # - name: a system
169
188
  # backend: ssh
170
- # bastion_host: bastion-host.domain
189
+ # bastion_host_output: an_output
171
190
  # bastion_user: bastion-user
172
191
  #
173
192
  # ====== controls
@@ -554,6 +573,7 @@ module Kitchen
554
573
  optional(:attrs_outputs).filled :hash?
555
574
  optional(:backend_cache).value :bool?
556
575
  optional(:bastion_host).filled :str?
576
+ optional(:bastion_host_output).filled :str?
557
577
  optional(:bastion_port).value :int?
558
578
  optional(:bastion_user).filled :str?
559
579
  optional(:controls).each(:filled?, :str?)
@@ -42,7 +42,7 @@ module Kitchen
42
42
  # @see Kitchen::Configurable#finalize_config!
43
43
  def finalize_config!(instance)
44
44
  super instance
45
- self.version_requirement = ::Gem::Requirement.new ">= 0.11.4", "< 0.13.0"
45
+ self.version_requirement = ::Gem::Requirement.new ">= 0.11.4", "< 0.15.0"
46
46
  self.workspace_name = "kitchen-terraform-#{::Shellwords.escape instance.name}"
47
47
  end
48
48
 
@@ -15,6 +15,7 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require "inspec"
18
+ require "kitchen/terraform/system_bastion_host_resolver"
18
19
  require "kitchen/terraform/system_inspec_map"
19
20
  require "rubygems"
20
21
 
@@ -40,28 +41,46 @@ module Kitchen
40
41
  #
41
42
  # @param attributes [Hash] the attributes to be added to the InSpec options.
42
43
  # @param system_configuration_attributes [Hash] the configuration attributes of a system.
44
+ # @raise [Kitchen::ClientError] if the system bastion host fails to be resolved.
43
45
  # @return [Hash] a mapping of InSpec options.
44
46
  def build(attributes:, system_configuration_attributes:)
45
- system_configuration_attributes.lazy.select do |attribute_name, _|
46
- system_inspec_map.key?(attribute_name)
47
- end.each do |attribute_name, attribute_value|
48
- options.store system_inspec_map.fetch(attribute_name), attribute_value
49
- end
47
+ map_system_to_inspec system_configuration_attributes: system_configuration_attributes
48
+ options.store self.class.inputs_key, attributes
49
+ resolve_bastion_host system_configuration_attributes: system_configuration_attributes
50
50
 
51
- options.merge self.class.inputs_key => attributes
51
+ options
52
52
  end
53
53
 
54
54
  # #initialize prepares a new instance of the class.
55
55
  #
56
+ # @param outputs [Hash] the Terraform output variables.
56
57
  # @return [Kitchen::Terraform::InSpecOptionsFactory]
57
- def initialize
58
+ def initialize(outputs:)
58
59
  self.options = { "distinct_exit" => false }
60
+ self.system_bastion_host_resolver = ::Kitchen::Terraform::SystemBastionHostResolver.new outputs: outputs
59
61
  self.system_inspec_map = ::Kitchen::Terraform::SYSTEM_INSPEC_MAP.dup
60
62
  end
61
63
 
62
64
  private
63
65
 
64
- attr_accessor :options, :system_inspec_map
66
+ attr_accessor :options, :system_bastion_host_resolver, :system_inspec_map
67
+
68
+ def map_system_to_inspec(system_configuration_attributes:)
69
+ system_configuration_attributes.lazy.select do |attribute_name, _|
70
+ system_inspec_map.key?(attribute_name)
71
+ end.each do |attribute_name, attribute_value|
72
+ options.store system_inspec_map.fetch(attribute_name), attribute_value
73
+ end
74
+ end
75
+
76
+ def resolve_bastion_host(system_configuration_attributes:)
77
+ system_bastion_host_resolver.resolve(
78
+ bastion_host: system_configuration_attributes.fetch(:bastion_host, ""),
79
+ bastion_host_output: system_configuration_attributes.fetch(:bastion_host_output, ""),
80
+ ) do |bastion_host:|
81
+ options.store :bastion_host, bastion_host
82
+ end
83
+ end
65
84
  end
66
85
  end
67
86
  end
@@ -61,6 +61,11 @@ module Kitchen
61
61
  ""
62
62
  end
63
63
  self.runner = ::Inspec::Runner.new options.merge logger: ::Inspec::Log.logger
64
+
65
+ v2_loader = ::Inspec::Plugin::V2::Loader.new
66
+ v2_loader.load_all
67
+ v2_loader.exit_on_load_error
68
+
64
69
  profile_locations.each do |profile_location|
65
70
  runner.add_target profile_location
66
71
  end
@@ -81,7 +86,7 @@ module Kitchen
81
86
  def run
82
87
  yield exit_code: runner.run
83
88
  rescue => error
84
- raise ::Kitchen::TransientFailure, "#{action} failed:\n\t#{error.message}"
89
+ raise ::Kitchen::TransientFailure, "#{action} failed:\n\t\t#{error.message}"
85
90
  end
86
91
  end
87
92
  end
@@ -75,9 +75,10 @@ module Kitchen
75
75
  # @param workspace_name [String] the name of the Terraform workspace to select or to create.
76
76
  # @return [Kitchen::Terraform::Driver::Converge]
77
77
  def initialize(config:, logger:, version_requirement:, workspace_name:)
78
+ client = config.fetch :client
78
79
  hash_config = config.to_hash.merge workspace_name: workspace_name
79
80
  self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
80
- client: config.fetch(:client),
81
+ client: client,
81
82
  logger: logger,
82
83
  )
83
84
  self.logger = logger
@@ -86,11 +87,9 @@ module Kitchen
86
87
  self.apply = ::Kitchen::Terraform::Command::Apply.new config: config
87
88
  self.get = ::Kitchen::Terraform::Command::Get.new
88
89
  self.output = ::Kitchen::Terraform::Command::Output.new
90
+ initialize_outputs_handlers client: client, logger: logger
89
91
  self.validate = ::Kitchen::Terraform::Command::Validate.new config: config
90
92
  self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
91
- self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
92
- self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
93
- self.outputs_reader = ::Kitchen::Terraform::OutputsReader.new command_executor: command_executor
94
93
  self.variables = config.fetch :variables
95
94
  self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
96
95
  self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
@@ -144,6 +143,17 @@ module Kitchen
144
143
  build_infrastructure
145
144
  end
146
145
 
146
+ def initialize_outputs_handlers(client:, logger:)
147
+ self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
148
+ self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
149
+ self.outputs_reader = ::Kitchen::Terraform::OutputsReader.new(
150
+ command_executor: ::Kitchen::Terraform::CommandExecutor.new(
151
+ client: client,
152
+ logger: ::Kitchen::Terraform::DebugLogger.new(logger),
153
+ ),
154
+ )
155
+ end
156
+
147
157
  def parse_outputs(json_outputs:)
148
158
  logger.warn "Parsing the Terraform output variables as JSON..."
149
159
  outputs_parser.parse json_outputs: json_outputs do |parsed_outputs:|
@@ -165,7 +175,7 @@ module Kitchen
165
175
  def save_outputs(parsed_outputs:, state:)
166
176
  logger.warn "Writing the output variables to the Kitchen instance state..."
167
177
  outputs_manager.save outputs: parsed_outputs, state: state
168
- logger.warn "Finished writing the output varibales to the Kitchen instance state."
178
+ logger.warn "Finished writing the output variables to the Kitchen instance state."
169
179
  end
170
180
 
171
181
  def save_variables_and_outputs(state:)
@@ -19,31 +19,31 @@ require "kitchen"
19
19
  module Kitchen
20
20
  module Terraform
21
21
  module Raise
22
- # ActionFailed is the class of objects which handle errors resulting in failed actions.
23
- class ActionFailed
24
- # #call logs an error message and raises an error with the message.
25
- #
26
- # @param message [String] the error message.
27
- # @raise [Kitchen::ActionFailed]
28
- # @return [void]
29
- def call(message:)
30
- logger.error message
22
+ # ActionFailed is the class of objects which handle errors resulting in failed actions.
23
+ class ActionFailed
24
+ # #call logs an error message and raises an error with the message.
25
+ #
26
+ # @param message [String] the error message.
27
+ # @raise [Kitchen::ActionFailed]
28
+ # @return [void]
29
+ def call(message:)
30
+ logger.error message
31
31
 
32
- raise ::Kitchen::ActionFailed, message
33
- end
32
+ raise ::Kitchen::ActionFailed, message
33
+ end
34
34
 
35
- # #initialize prepares a new instance of the class.
36
- #
37
- # @param logger [Kitchen::Logger] a logger to log messages.
38
- # @return [Kitchen::Terraform::ActionFailed]
39
- def initialize(logger:)
40
- self.logger = logger
41
- end
35
+ # #initialize prepares a new instance of the class.
36
+ #
37
+ # @param logger [Kitchen::Logger] a logger to log messages.
38
+ # @return [Kitchen::Terraform::ActionFailed]
39
+ def initialize(logger:)
40
+ self.logger = logger
41
+ end
42
42
 
43
- private
43
+ private
44
44
 
45
- attr_accessor :logger
45
+ attr_accessor :logger
46
+ end
46
47
  end
47
48
  end
48
49
  end
49
- end
@@ -46,7 +46,6 @@ module Kitchen
46
46
  self.hosts = configuration_attributes.fetch :hosts do
47
47
  []
48
48
  end.dup
49
- self.inspec_options_factory = ::Kitchen::Terraform::InSpecOptionsFactory.new
50
49
  self.logger = logger
51
50
  end
52
51
 
@@ -72,17 +71,20 @@ module Kitchen
72
71
 
73
72
  private
74
73
 
75
- attr_accessor :attrs, :attrs_outputs, :configuration_attributes, :hosts, :inspec_options_factory, :logger
74
+ attr_accessor :attrs, :attrs_outputs, :configuration_attributes, :hosts, :logger
76
75
 
77
- def execute_inspec_runner(fail_fast:)
76
+ def execute_inspec_runner(fail_fast:, options:)
78
77
  ::Kitchen::Terraform::InSpecFactory.new(fail_fast: fail_fast, hosts: hosts).build(
79
- options: inspec_options,
78
+ options: options,
80
79
  profile_locations: configuration_attributes.fetch(:profile_locations),
81
80
  ).exec
82
81
  end
83
82
 
84
- def inspec_options
85
- inspec_options_factory.build attributes: attrs, system_configuration_attributes: configuration_attributes
83
+ def inspec_options(outputs:)
84
+ ::Kitchen::Terraform::InSpecOptionsFactory.new(outputs: outputs).build(
85
+ attributes: attrs,
86
+ system_configuration_attributes: configuration_attributes,
87
+ )
86
88
  end
87
89
 
88
90
  def resolve(outputs:, variables:)
@@ -102,7 +104,7 @@ module Kitchen
102
104
  def resolve_and_execute(fail_fast:, outputs:, variables:)
103
105
  logger.warn "Verifying the '#{self}' system..."
104
106
  resolve outputs: outputs, variables: variables
105
- execute_inspec_runner fail_fast: fail_fast
107
+ execute_inspec_runner fail_fast: fail_fast, options: inspec_options(outputs: outputs)
106
108
  logger.warn "Finished verifying the '#{self}' system."
107
109
  end
108
110
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2016-2019 New Context, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "kitchen"
18
+
19
+ module Kitchen
20
+ module Terraform
21
+ # SystemBastionHostResolver is the class of objects which resolve a bastion host of a system which may be either
22
+ # dynamically obtained from a Terraform output variable or statically defined.
23
+ class SystemBastionHostResolver
24
+ # #initialize prepares a new instance of the class.
25
+ #
26
+ # @param outputs [Hash] a map of Terraform output variables.
27
+ # @return [Kitchen::Terraform::SystemBastionHostResolver]
28
+ def initialize(outputs:)
29
+ self.outputs = Hash[outputs]
30
+ end
31
+
32
+ # #resolve resolves a bastion host from either the specified Terraform output or the static value.
33
+ #
34
+ # @param bastion_host [String] a statically defined host.
35
+ # @param bastion_host_output [String] the name of the Terraform output which contains a bastion host.
36
+ # @yieldparam bastion_host [String] the bastion host.
37
+ # @raise [Kitchen::ClientError] if the specified Terraform output is not found.
38
+ # @return [self]
39
+ def resolve(bastion_host:, bastion_host_output:)
40
+ if !bastion_host.empty?
41
+ yield bastion_host: bastion_host
42
+ elsif !bastion_host_output.empty?
43
+ yield bastion_host: resolved_output(bastion_host_output: bastion_host_output).fetch(:value)
44
+ end
45
+
46
+ self
47
+ rescue ::KeyError
48
+ raise(
49
+ ::Kitchen::ClientError,
50
+ "Resolving the system bastion host failed due to the absence of the 'value' key from the " \
51
+ "'#{bastion_host_output}' Terraform output of the Kitchen instance state. This error indicates that the " \
52
+ "output format of `terraform output -json` is unexpected."
53
+ )
54
+ end
55
+
56
+ private
57
+
58
+ attr_accessor :outputs
59
+
60
+ def resolved_output(bastion_host_output:)
61
+ outputs.fetch bastion_host_output.to_sym
62
+ rescue ::KeyError
63
+ raise(
64
+ ::Kitchen::ClientError,
65
+ "Resolving the system bastion host failed due to the absence of the '#{bastion_host_output}' key from the " \
66
+ "Terraform outputs of the Kitchen instance state. This error indicates either that `kitchen converge` must " \
67
+ "be executed again to update the Terraform outputs or that the wrong key was provided."
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
@@ -21,7 +21,6 @@ module Kitchen
21
21
  attrs: :input_file,
22
22
  backend_cache: :backend_cache,
23
23
  backend: :backend,
24
- bastion_host: :bastion_host,
25
24
  bastion_port: :bastion_port,
26
25
  bastion_user: :bastion_user,
27
26
  color: "color",
@@ -71,7 +71,7 @@ module Kitchen
71
71
 
72
72
  # @api private
73
73
  def value
74
- self.value = ::Gem::Version.new "5.2.0" if not @value
74
+ self.value = ::Gem::Version.new "5.7.0" if not @value
75
75
  @value
76
76
  end
77
77
 
@@ -160,7 +160,7 @@ module Kitchen
160
160
  def load_outputs(state:)
161
161
  logger.warn "Reading the Terraform output variables from the Kitchen instance state..."
162
162
  ::Kitchen::Terraform::OutputsManager.new.load outputs: outputs, state: state
163
- logger.warn "Finished reading the Terraform output varibales from the Kitchen instance state."
163
+ logger.warn "Finished reading the Terraform output variables from the Kitchen instance state."
164
164
  end
165
165
 
166
166
  def profile_locations
@@ -183,9 +183,9 @@ module Kitchen
183
183
  end
184
184
 
185
185
  def verify_systems
186
- logger.banner "Starting verification of the systems."
186
+ logger.warn "Verifying the systems..."
187
187
  systems_verifier.verify outputs: outputs, variables: variables
188
- logger.banner "Finished verification of the systems."
188
+ logger.warn "Finished verifying the systems."
189
189
  end
190
190
  end
191
191
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lane
@@ -21,6 +21,7 @@ authors:
21
21
  - curleighbraces
22
22
  - Austin Heiman
23
23
  - Gary Foster
24
+ - Ed Bartholomew
24
25
  autorequire:
25
26
  bindir: bin
26
27
  cert_chain:
@@ -61,7 +62,7 @@ cert_chain:
61
62
  JH4yGDzVEYaZHaohSDcYuGLK6OQylPu7oM75S+TNLWseDIT8bWgQk6NelVjtQQ2Q
62
63
  XSbgfu863jyey/0qO01cUo3+iTqzl85cWg==
63
64
  -----END CERTIFICATE-----
64
- date: 2020-02-28 00:00:00.000000000 Z
65
+ date: 2021-02-24 00:00:00.000000000 Z
65
66
  dependencies:
66
67
  - !ruby/object:Gem::Dependency
67
68
  name: bundler
@@ -204,145 +205,131 @@ dependencies:
204
205
  - !ruby/object:Gem::Version
205
206
  version: '4.2'
206
207
  - !ruby/object:Gem::Dependency
207
- name: mini_racer
208
- requirement: !ruby/object:Gem::Requirement
209
- requirements:
210
- - - "~>"
211
- - !ruby/object:Gem::Version
212
- version: 0.2.0
213
- type: :development
214
- prerelease: false
215
- version_requirements: !ruby/object:Gem::Requirement
216
- requirements:
217
- - - "~>"
218
- - !ruby/object:Gem::Version
219
- version: 0.2.0
220
- - !ruby/object:Gem::Dependency
221
- name: pry-coolline
208
+ name: rspec
222
209
  requirement: !ruby/object:Gem::Requirement
223
210
  requirements:
224
211
  - - "~>"
225
212
  - !ruby/object:Gem::Version
226
- version: '0.2'
213
+ version: '3.4'
227
214
  type: :development
228
215
  prerelease: false
229
216
  version_requirements: !ruby/object:Gem::Requirement
230
217
  requirements:
231
218
  - - "~>"
232
219
  - !ruby/object:Gem::Version
233
- version: '0.2'
220
+ version: '3.4'
234
221
  - !ruby/object:Gem::Dependency
235
- name: pry
222
+ name: rufo
236
223
  requirement: !ruby/object:Gem::Requirement
237
224
  requirements:
238
225
  - - "~>"
239
226
  - !ruby/object:Gem::Version
240
- version: '0.10'
227
+ version: '0.7'
241
228
  type: :development
242
229
  prerelease: false
243
230
  version_requirements: !ruby/object:Gem::Requirement
244
231
  requirements:
245
232
  - - "~>"
246
233
  - !ruby/object:Gem::Version
247
- version: '0.10'
234
+ version: '0.7'
248
235
  - !ruby/object:Gem::Dependency
249
- name: reek
236
+ name: simplecov
250
237
  requirement: !ruby/object:Gem::Requirement
251
238
  requirements:
252
239
  - - "~>"
253
240
  - !ruby/object:Gem::Version
254
- version: '5.5'
241
+ version: 0.16.1
255
242
  type: :development
256
243
  prerelease: false
257
244
  version_requirements: !ruby/object:Gem::Requirement
258
245
  requirements:
259
246
  - - "~>"
260
247
  - !ruby/object:Gem::Version
261
- version: '5.5'
248
+ version: 0.16.1
262
249
  - !ruby/object:Gem::Dependency
263
- name: rspec
250
+ name: travis
264
251
  requirement: !ruby/object:Gem::Requirement
265
252
  requirements:
266
253
  - - "~>"
267
254
  - !ruby/object:Gem::Version
268
- version: '3.4'
255
+ version: '1.8'
269
256
  type: :development
270
257
  prerelease: false
271
258
  version_requirements: !ruby/object:Gem::Requirement
272
259
  requirements:
273
260
  - - "~>"
274
261
  - !ruby/object:Gem::Version
275
- version: '3.4'
262
+ version: '1.8'
276
263
  - !ruby/object:Gem::Dependency
277
- name: rufo
264
+ name: yard
278
265
  requirement: !ruby/object:Gem::Requirement
279
266
  requirements:
280
267
  - - "~>"
281
268
  - !ruby/object:Gem::Version
282
- version: '0.7'
269
+ version: '0.9'
283
270
  type: :development
284
271
  prerelease: false
285
272
  version_requirements: !ruby/object:Gem::Requirement
286
273
  requirements:
287
274
  - - "~>"
288
275
  - !ruby/object:Gem::Version
289
- version: '0.7'
276
+ version: '0.9'
290
277
  - !ruby/object:Gem::Dependency
291
- name: simplecov
278
+ name: reek
292
279
  requirement: !ruby/object:Gem::Requirement
293
280
  requirements:
294
281
  - - "~>"
295
282
  - !ruby/object:Gem::Version
296
- version: 0.16.1
283
+ version: 6.0.2
297
284
  type: :development
298
285
  prerelease: false
299
286
  version_requirements: !ruby/object:Gem::Requirement
300
287
  requirements:
301
288
  - - "~>"
302
289
  - !ruby/object:Gem::Version
303
- version: 0.16.1
290
+ version: 6.0.2
304
291
  - !ruby/object:Gem::Dependency
305
- name: travis
292
+ name: delegate
306
293
  requirement: !ruby/object:Gem::Requirement
307
294
  requirements:
308
295
  - - "~>"
309
296
  - !ruby/object:Gem::Version
310
- version: '1.8'
311
- type: :development
297
+ version: 0.1.0
298
+ type: :runtime
312
299
  prerelease: false
313
300
  version_requirements: !ruby/object:Gem::Requirement
314
301
  requirements:
315
302
  - - "~>"
316
303
  - !ruby/object:Gem::Version
317
- version: '1.8'
304
+ version: 0.1.0
318
305
  - !ruby/object:Gem::Dependency
319
- name: yard
306
+ name: dry-validation
320
307
  requirement: !ruby/object:Gem::Requirement
321
308
  requirements:
322
309
  - - "~>"
323
310
  - !ruby/object:Gem::Version
324
- version: '0.9'
325
- type: :development
311
+ version: '0.13'
312
+ type: :runtime
326
313
  prerelease: false
327
314
  version_requirements: !ruby/object:Gem::Requirement
328
315
  requirements:
329
316
  - - "~>"
330
317
  - !ruby/object:Gem::Version
331
- version: '0.9'
318
+ version: '0.13'
332
319
  - !ruby/object:Gem::Dependency
333
- name: dry-validation
320
+ name: mixlib-shellout
334
321
  requirement: !ruby/object:Gem::Requirement
335
322
  requirements:
336
323
  - - "~>"
337
324
  - !ruby/object:Gem::Version
338
- version: '0.13'
325
+ version: '3.0'
339
326
  type: :runtime
340
327
  prerelease: false
341
328
  version_requirements: !ruby/object:Gem::Requirement
342
329
  requirements:
343
330
  - - "~>"
344
331
  - !ruby/object:Gem::Version
345
- version: '0.13'
332
+ version: '3.0'
346
333
  - !ruby/object:Gem::Dependency
347
334
  name: inspec
348
335
  requirement: !ruby/object:Gem::Requirement
@@ -350,6 +337,15 @@ dependencies:
350
337
  - - ">="
351
338
  - !ruby/object:Gem::Version
352
339
  version: '3'
340
+ - - "!="
341
+ - !ruby/object:Gem::Version
342
+ version: 4.24.26
343
+ - - "!="
344
+ - !ruby/object:Gem::Version
345
+ version: 4.24.28
346
+ - - "!="
347
+ - !ruby/object:Gem::Version
348
+ version: 4.24.32
353
349
  - - "<"
354
350
  - !ruby/object:Gem::Version
355
351
  version: '5'
@@ -360,6 +356,15 @@ dependencies:
360
356
  - - ">="
361
357
  - !ruby/object:Gem::Version
362
358
  version: '3'
359
+ - - "!="
360
+ - !ruby/object:Gem::Version
361
+ version: 4.24.26
362
+ - - "!="
363
+ - !ruby/object:Gem::Version
364
+ version: 4.24.28
365
+ - - "!="
366
+ - !ruby/object:Gem::Version
367
+ version: 4.24.32
363
368
  - - "<"
364
369
  - !ruby/object:Gem::Version
365
370
  version: '5'
@@ -369,28 +374,14 @@ dependencies:
369
374
  requirements:
370
375
  - - "~>"
371
376
  - !ruby/object:Gem::Version
372
- version: '2.2'
377
+ version: '2.3'
373
378
  type: :runtime
374
379
  prerelease: false
375
380
  version_requirements: !ruby/object:Gem::Requirement
376
381
  requirements:
377
382
  - - "~>"
378
383
  - !ruby/object:Gem::Version
379
- version: '2.2'
380
- - !ruby/object:Gem::Dependency
381
- name: mixlib-shellout
382
- requirement: !ruby/object:Gem::Requirement
383
- requirements:
384
- - - "~>"
385
- - !ruby/object:Gem::Version
386
- version: '3.0'
387
- type: :runtime
388
- prerelease: false
389
- version_requirements: !ruby/object:Gem::Requirement
390
- requirements:
391
- - - "~>"
392
- - !ruby/object:Gem::Version
393
- version: '3.0'
384
+ version: '2.3'
394
385
  - !ruby/object:Gem::Dependency
395
386
  name: test-kitchen
396
387
  requirement: !ruby/object:Gem::Requirement
@@ -508,6 +499,7 @@ files:
508
499
  - lib/kitchen/terraform/system.rb
509
500
  - lib/kitchen/terraform/system_attrs_inputs_resolver.rb
510
501
  - lib/kitchen/terraform/system_attrs_outputs_resolver.rb
502
+ - lib/kitchen/terraform/system_bastion_host_resolver.rb
511
503
  - lib/kitchen/terraform/system_hosts_resolver.rb
512
504
  - lib/kitchen/terraform/system_inspec_map.rb
513
505
  - lib/kitchen/terraform/systems_verifier.rb
@@ -543,16 +535,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
543
535
  version: '2.4'
544
536
  - - "<"
545
537
  - !ruby/object:Gem::Version
546
- version: '2.7'
538
+ version: '2.8'
547
539
  required_rubygems_version: !ruby/object:Gem::Requirement
548
540
  requirements:
549
541
  - - ">="
550
542
  - !ruby/object:Gem::Version
551
543
  version: '0'
552
544
  requirements:
553
- - Terraform >= v0.11.4, < v0.13.0
554
- rubyforge_project:
555
- rubygems_version: 2.7.7
545
+ - Terraform >= v0.11.4, < v0.15.0
546
+ rubygems_version: 3.0.3
556
547
  signing_key:
557
548
  specification_version: 4
558
549
  summary: Test Kitchen plugins for testing Terraform configuration
metadata.gz.sig CHANGED
Binary file