kitchen-terraform 4.7.0 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/kitchen/driver/terraform.rb +15 -3
- data/lib/kitchen/terraform/command/output.rb +1 -1
- data/lib/kitchen/terraform/config_schemas/system.rb +18 -9
- data/lib/kitchen/terraform/system.rb +10 -8
- data/lib/kitchen/terraform/system_attrs_resolver.rb +13 -9
- data/lib/kitchen/terraform/version.rb +1 -1
- data/lib/kitchen/verifier/terraform.rb +11 -19
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47a51e0ce916a62c6b14c16662703371bdff9256fb2ab127080cc3b18723f80a
|
4
|
+
data.tar.gz: 5088420cf548532cf0f845f208ede28e41fe1d9a9d989c01cfd72eaba9fceaa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9bb569f6a8a0b9da54935a1b3e4009ca4f5d7174d989949f5fb919490f4cf0ff4e422bc00c15b4629ca62776620753e9d4cab71c1d3c23579c380a6b9806ee
|
7
|
+
data.tar.gz: 742477dc25ee6e48d39a477a3f3e2565c3b3563a8f0f4112b949d670a4778db224822a6c96c0a83e08992d20859107b94d8746f62e161aa0b020fb37eae3ec80
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -266,19 +266,31 @@ class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
|
|
266
266
|
raise ::Kitchen::ActionFailed, error.message
|
267
267
|
end
|
268
268
|
|
269
|
+
# Retrieves the Terraform input variables for a Kitchen instance provided by the configuration.
|
270
|
+
#
|
271
|
+
# @return [self]
|
272
|
+
# @yieldparam inputs [::Hash] the input variables.
|
273
|
+
def retrieve_inputs
|
274
|
+
yield inputs: config_variables
|
275
|
+
|
276
|
+
self
|
277
|
+
end
|
278
|
+
|
269
279
|
# Retrieves the Terraform state outputs for a Kitchen instance by selecting the test workspace and fetching the
|
270
280
|
# outputs.
|
271
281
|
#
|
272
282
|
# @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
|
273
|
-
# @return [
|
274
|
-
# @yieldparam
|
283
|
+
# @return [self]
|
284
|
+
# @yieldparam outputs [::Hash] the state output.
|
275
285
|
def retrieve_outputs(&block)
|
276
286
|
run_workspace_select_instance
|
277
287
|
::Kitchen::Terraform::Command::Output.run(
|
278
288
|
client: config_client,
|
279
|
-
options: {cwd: config_root_module_directory,
|
289
|
+
options: { cwd: config_root_module_directory, live_stream: debug_logger, timeout: config_command_timeout },
|
280
290
|
&block
|
281
291
|
)
|
292
|
+
|
293
|
+
self
|
282
294
|
rescue ::Kitchen::Terraform::Error => error
|
283
295
|
raise ::Kitchen::ActionFailed, error.message
|
284
296
|
end
|
@@ -62,7 +62,7 @@ module ::Kitchen::Terraform::Command::Output
|
|
62
62
|
# @api private
|
63
63
|
def run_shell_out(client:, options:)
|
64
64
|
::Kitchen::Terraform::ShellOut.run client: client, command: "output -json", options: options do |standard_output:|
|
65
|
-
yield outputs: ::JSON.parse(standard_output)
|
65
|
+
yield outputs: ::Kitchen::Util.stringified_hash(::JSON.parse(standard_output))
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -21,19 +21,28 @@ module Kitchen
|
|
21
21
|
module Terraform
|
22
22
|
module ConfigSchemas
|
23
23
|
# A system is a mapping which is used to configure the execution of {https://www.inspec.io/docs/ InSpec tests}
|
24
|
-
# against a system in the Terraform state.
|
24
|
+
# against a system in the Terraform state. The keys of a system mapping correlate to the arguments and the
|
25
|
+
# options of the {https://www.inspec.io/docs/reference/cli/#exec +inspec exec+} command-line interface
|
26
|
+
# subcomamand.
|
25
27
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
+
# ===== InSpec Profiles
|
29
|
+
#
|
30
|
+
# All systems within the same {https://kitchen.ci/docs/getting-started/adding-suite Kitchen suite} are by default
|
31
|
+
# tested using the same {https://www.inspec.io/docs/reference/profiles/ InSpec profile}. The profile must be
|
28
32
|
# implemented in the directory located at `<Kitchen root>/test/integration/<suite name>`. This behaviour can be
|
29
33
|
# overridden with the <code>profile_locations</code> key.
|
30
34
|
#
|
31
|
-
# The values of
|
32
|
-
# with
|
33
|
-
# {https://www.
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
35
|
+
# The values of any {https://www.terraform.io/docs/configuration/variables.html Terraform input variables}
|
36
|
+
# configured with the driver's <code>variables</code> attribute and the values of any
|
37
|
+
# {https://www.terraform.io/docs/configuration/outputs.html Terraform output variables} which exist in the
|
38
|
+
# Terraform state are associated with equivalently named
|
39
|
+
# {https://www.inspec.io/docs/reference/profiles/#profile-attributes InSpec profile attributes}, prefixed with
|
40
|
+
# <code>input_</code> or <code>output_</code>, respectively. The values of the output variables are also
|
41
|
+
# associated with equivalently named profile attributes without any prefixes for backward compatibility. Output
|
42
|
+
# variable associations can be overridden with the <code>attrs_outputs</code> key. For example, the value of an
|
43
|
+
# input variable named `test` will be associated with an attribute named `input_test`, and the value of an output
|
44
|
+
# variable named `test` will be associated with an attribute named `output_test` as well as an attribute named
|
45
|
+
# `test`.
|
37
46
|
#
|
38
47
|
# ===== Required Keys
|
39
48
|
#
|
@@ -65,10 +65,12 @@ module Kitchen
|
|
65
65
|
|
66
66
|
# #verify verifies the system by executing InSpec.
|
67
67
|
#
|
68
|
+
# @param inputs [::Hash] the Terraform input variables to be utilized as InSpec profile attributes.
|
68
69
|
# @param inspec_options [::Hash] the options to be passed to InSpec.
|
70
|
+
# @param outputs [::Hash] the Terraform output variables to be utilized as InSpec profile attributes.
|
69
71
|
# @return [self]
|
70
|
-
def verify(inspec_options:, outputs:)
|
71
|
-
resolve outputs: outputs
|
72
|
+
def verify(inputs:, inspec_options:, outputs:)
|
73
|
+
resolve inputs: inputs, outputs: outputs
|
72
74
|
execute_inspec options: inspec_options
|
73
75
|
|
74
76
|
self
|
@@ -81,7 +83,7 @@ module Kitchen
|
|
81
83
|
def execute_inspec(options:)
|
82
84
|
inspec.new(
|
83
85
|
options: options_with_attributes(options: options),
|
84
|
-
profile_locations: @mapping.fetch(:profile_locations)
|
86
|
+
profile_locations: @mapping.fetch(:profile_locations),
|
85
87
|
).exec(system: self)
|
86
88
|
end
|
87
89
|
|
@@ -108,16 +110,16 @@ module Kitchen
|
|
108
110
|
options.merge attributes: @attributes
|
109
111
|
end
|
110
112
|
|
111
|
-
def resolve(outputs:)
|
112
|
-
resolve_attrs outputs: outputs
|
113
|
+
def resolve(inputs:, outputs:)
|
114
|
+
resolve_attrs inputs: inputs, outputs: outputs
|
113
115
|
resolve_hosts outputs: outputs
|
114
116
|
end
|
115
117
|
|
116
|
-
def resolve_attrs(outputs:)
|
117
|
-
::Kitchen::Terraform::SystemAttrsResolver.new(outputs: outputs).resolve(
|
118
|
+
def resolve_attrs(inputs:, outputs:)
|
119
|
+
::Kitchen::Terraform::SystemAttrsResolver.new(inputs: inputs, outputs: outputs).resolve(
|
118
120
|
attrs_outputs_keys: @attrs_outputs.keys,
|
119
121
|
attrs_outputs_values: @attrs_outputs.values,
|
120
|
-
system: self
|
122
|
+
system: self,
|
121
123
|
)
|
122
124
|
|
123
125
|
self
|
@@ -28,9 +28,9 @@ module Kitchen
|
|
28
28
|
# @param system [::Kitchen::Terraform::System] the system.
|
29
29
|
# @raise [::Kitchen::Terraform::Error] if the fetching the value of the output fails.
|
30
30
|
def resolve(attrs_outputs_keys:, attrs_outputs_values:, system:)
|
31
|
-
system.add_attrs
|
32
|
-
|
33
|
-
|
31
|
+
system.add_attrs(attrs: @inputs.merge(@outputs.merge(
|
32
|
+
attrs_outputs_keys.lazy.map(&:to_s).zip(@outputs.fetch_values(*attrs_outputs_values)).to_h
|
33
|
+
)))
|
34
34
|
|
35
35
|
self
|
36
36
|
rescue ::KeyError => key_error
|
@@ -42,12 +42,16 @@ module Kitchen
|
|
42
42
|
# #initialize prepares the instance to be used.
|
43
43
|
#
|
44
44
|
# @param outputs [#to_hash] the outputs of the Terraform state under test.
|
45
|
-
def initialize(outputs:)
|
46
|
-
@
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def initialize(inputs:, outputs:)
|
46
|
+
@inputs = inputs.map do |key, value|
|
47
|
+
["input_#{key}", value]
|
48
|
+
end.to_h
|
49
|
+
@outputs = Hash[outputs].map do |key, value|
|
50
|
+
[key, value.fetch("value")]
|
51
|
+
end.to_h
|
52
|
+
@outputs.merge!(@outputs.map do |key, value|
|
53
|
+
["output_#{key}", value]
|
54
|
+
end.to_h)
|
51
55
|
rescue ::KeyError => key_error
|
52
56
|
raise ::Kitchen::Terraform::Error, "Preparing to resolve attrs failed\n#{key_error}"
|
53
57
|
end
|
@@ -87,7 +87,7 @@ module Kitchen
|
|
87
87
|
# @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
|
88
88
|
# @return [void]
|
89
89
|
def call(_kitchen_state)
|
90
|
-
|
90
|
+
load_variables
|
91
91
|
verify_systems
|
92
92
|
if !@error_messages.empty?
|
93
93
|
raise ::Kitchen::ActionFailed, @error_messages.join("\n\n")
|
@@ -105,17 +105,6 @@ module Kitchen
|
|
105
105
|
false
|
106
106
|
end
|
107
107
|
|
108
|
-
# finalize_config! configures InSpec options which remain consistent between systems.
|
109
|
-
#
|
110
|
-
# @param kitchen_instance [::Kitchen::Instance] an associated Kitchen instance.
|
111
|
-
# @return [self]
|
112
|
-
def finalize_config!(kitchen_instance)
|
113
|
-
super kitchen_instance
|
114
|
-
@inspec_options.merge! "color" => config_color
|
115
|
-
|
116
|
-
self
|
117
|
-
end
|
118
|
-
|
119
108
|
private
|
120
109
|
|
121
110
|
def handle_error(message:)
|
@@ -127,20 +116,21 @@ module Kitchen
|
|
127
116
|
end
|
128
117
|
end
|
129
118
|
|
130
|
-
def
|
119
|
+
def load_variables
|
131
120
|
instance.driver.retrieve_outputs do |outputs:|
|
132
|
-
@outputs.replace
|
121
|
+
@outputs.replace outputs
|
122
|
+
end.retrieve_inputs do |inputs:|
|
123
|
+
@inputs.replace inputs
|
133
124
|
end
|
134
125
|
end
|
135
126
|
|
136
127
|
def initialize(configuration = {})
|
137
128
|
init_config configuration
|
138
129
|
@error_messages = []
|
139
|
-
@
|
130
|
+
@inputs = {}
|
140
131
|
@outputs = {}
|
141
132
|
end
|
142
133
|
|
143
|
-
|
144
134
|
# load_needed_dependencies! loads the InSpec libraries required to verify a Terraform state.
|
145
135
|
#
|
146
136
|
# @raise [::Kitchen::ClientError] if loading the InSpec libraries fails.
|
@@ -154,13 +144,15 @@ module Kitchen
|
|
154
144
|
end
|
155
145
|
|
156
146
|
def system_inspec_options(system:)
|
157
|
-
::Kitchen::Terraform::InSpecOptionsMapper.new(system: system)
|
147
|
+
::Kitchen::Terraform::InSpecOptionsMapper.new(system: system)
|
148
|
+
.map(options: { "color" => config_color, "distinct_exit" => false })
|
158
149
|
end
|
159
150
|
|
160
151
|
def verify(system:)
|
161
152
|
::Kitchen::Terraform::System.new(
|
162
|
-
mapping: {profile_locations: [::File.join(config.fetch(:test_base_path), instance.suite.name)]}
|
163
|
-
|
153
|
+
mapping: { profile_locations: [::File.join(config.fetch(:test_base_path), instance.suite.name)] }
|
154
|
+
.merge(system),
|
155
|
+
).verify(inputs: @inputs, inspec_options: system_inspec_options(system: system), outputs: @outputs)
|
164
156
|
rescue => error
|
165
157
|
handle_error message: error.message
|
166
158
|
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: 4.
|
4
|
+
version: 4.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lane
|
@@ -61,7 +61,7 @@ cert_chain:
|
|
61
61
|
XAjP/LERlXAwM+NCUycJw7BZMn7L2wIdnq6Le1rL6VJS17CZt2heuRtsF+3g0egR
|
62
62
|
x97GmUumeM67PGeVodlIV65tdXrdlqKlHcE=
|
63
63
|
-----END CERTIFICATE-----
|
64
|
-
date: 2019-04-
|
64
|
+
date: 2019-04-14 00:00:00.000000000 Z
|
65
65
|
dependencies:
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
name: guard-bundler
|
metadata.gz.sig
CHANGED
Binary file
|