kitchen-terraform 4.5.0 → 4.6.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: 151779b97d4bc65896d6ed19b7f21fd62c9d28c3de359070acebe8c6b9fb1c93
4
- data.tar.gz: 4459af4b43c7b85098cd87ec86739004e74ef42a40126c58c1b6d4eb8df5d5ea
3
+ metadata.gz: 2e916889997cb402f0784bca7fd292359454ccebd072cf4a83d2859f54c689c7
4
+ data.tar.gz: 40837369dda96179987ea46fb225dc72f857ed4a47cee224f60eaa52f1bcb3f1
5
5
  SHA512:
6
- metadata.gz: fb16cd67f5f1113eba6f48ec7e3584fd8d97ca1fb75348f9c5f87bd0cd597f8f7256de83eb1f889a71b936b2c27bc186fa06cdda8abe634a31b8581027a952d8
7
- data.tar.gz: 7e85036cae0a55cadfa38d5bb43281717a70d0ef7ce5077bc03ba27f201b94fc407e5b148123c0067cbe9b0f4c85092c52f647d39d6ee82563bcb6c5dc0974dc
6
+ metadata.gz: 6f3a09a6ed6392d19f8a78502a3dc1a16db82eebeae3b4e2f30e527cbebdbc4b50acc1e5b542b876620c02653d034548d20dad0e6e3568a3bf73785721cffbb5
7
+ data.tar.gz: d9ee18045c6070dd4b500e7c8208af3adc8662ecb756bcafdfe32279c49a0598d471caf7909f99c751e71b68f18307bd1dc0246f1f164553d02bef03fb896aee
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2016 New Context Services, 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
+ require "kitchen/terraform/config_attribute"
19
+ require "kitchen/terraform/config_schemas/boolean"
20
+
21
+ # This attribute toggles fail fast behaviour when verifying systems.
22
+ #
23
+ # If fail fast behaviour is enabled then Kitchen will halt on the first error raised by a system during verification;
24
+ # else errors raised by systems will be queued until all systems have attempted verification.
25
+ #
26
+ # Type:: {http://www.yaml.org/spec/1.2/spec.html#id2803629 Boolean}
27
+ # Required:: False
28
+ # Default:: <code>true</code>
29
+ # Example:: <code>fail_fast: false</code>
30
+ module ::Kitchen::Terraform::ConfigAttribute::FailFast
31
+ ::Kitchen::Terraform::ConfigAttribute.new(
32
+ attribute: :fail_fast,
33
+ default_value: lambda do
34
+ true
35
+ end,
36
+ schema: ::Kitchen::Terraform::ConfigSchemas::Boolean,
37
+ ).apply config_attribute: self
38
+ end
@@ -40,6 +40,7 @@ module Kitchen
40
40
 
41
41
  # #exec executes InSpec.
42
42
  #
43
+ # @raise [::Kitchen::Terraform::Error] if executing InSpec fails.
43
44
  # @return [self]
44
45
  def exec
45
46
  @runner.run.tap do |exit_code|
@@ -14,8 +14,11 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require "kitchen/terraform/error"
17
18
  require "kitchen/terraform/inspec_with_hosts"
18
19
  require "kitchen/terraform/inspec_without_hosts"
20
+ require "kitchen/terraform/system_attrs_resolver"
21
+ require "kitchen/terraform/system_hosts_resolver"
19
22
 
20
23
  module Kitchen
21
24
  module Terraform
@@ -53,32 +56,6 @@ module Kitchen
53
56
  self
54
57
  end
55
58
 
56
- # #resolve_attrs resolves the attributes of the system which are contained in Terraform outputs.
57
- #
58
- # @param system_attrs_resolver [::Kitchen::Terraform::SystemAttrsResolver] the resolver.
59
- # @return [self]
60
- def resolve_attrs(system_attrs_resolver:)
61
- system_attrs_resolver.resolve attrs_outputs_keys: @attrs_outputs.keys,
62
- attrs_outputs_values: @attrs_outputs.values, system: self
63
-
64
- self
65
- end
66
-
67
- # #resolve_hosts resolves the hosts of the system which are contained a Terraform output.
68
- #
69
- # @param system_hosts_resolver [::Kitchen::Terraform::SystemHostsResolver] the resolver.
70
- # @return [self]
71
- def resolve_hosts(system_hosts_resolver:)
72
- system_hosts_resolver.resolve(
73
- hosts_output: @mapping.fetch(:hosts_output) do
74
- return self
75
- end,
76
- system: self,
77
- )
78
-
79
- self
80
- end
81
-
82
59
  # #to_s returns a string representation of the system.
83
60
  #
84
61
  # @return [::String] the name of the system.
@@ -91,20 +68,23 @@ module Kitchen
91
68
  # @param inspec_options [::Hash] the options to be passed to InSpec.
92
69
  # @param inspec_profile_path [::String] the path to the profile which InSpec will execute.
93
70
  # @return [self]
94
- def verify(inspec_options:, inspec_profile_path:)
95
- if @hosts.empty?
96
- ::Kitchen::Terraform::InSpecWithoutHosts
97
- else
98
- ::Kitchen::Terraform::InSpecWithHosts
99
- end
100
- .new(options: inspec_options.merge(attributes: @attributes), profile_path: inspec_profile_path)
101
- .exec(system: self)
71
+ def verify(inspec_options:, inspec_profile_path:, outputs:)
72
+ resolve outputs: outputs
73
+ execute_inspec options: inspec_options, profile_path: inspec_profile_path
102
74
 
103
75
  self
76
+ rescue => error
77
+ raise ::Kitchen::Terraform::Error, "#{self}: #{error.message}"
104
78
  end
105
79
 
106
80
  private
107
81
 
82
+ def execute_inspec(options:, profile_path:)
83
+ inspec.new(options: options_with_attributes(options: options), profile_path: profile_path).exec(
84
+ system: self
85
+ )
86
+ end
87
+
108
88
  def initialize(mapping:)
109
89
  @attributes = {}
110
90
  @attrs_outputs = mapping.fetch :attrs_outputs do
@@ -115,6 +95,46 @@ module Kitchen
115
95
  end
116
96
  @mapping = mapping
117
97
  end
98
+
99
+ def inspec
100
+ if @hosts.empty?
101
+ ::Kitchen::Terraform::InSpecWithoutHosts
102
+ else
103
+ ::Kitchen::Terraform::InSpecWithHosts
104
+ end
105
+ end
106
+
107
+ def options_with_attributes(options:)
108
+ options.merge attributes: @attributes
109
+ end
110
+
111
+ def resolve(outputs:)
112
+ resolve_attrs outputs: outputs
113
+ resolve_hosts outputs: outputs
114
+ end
115
+
116
+ def resolve_attrs(outputs:)
117
+ ::Kitchen::Terraform::SystemAttrsResolver.new(outputs: outputs).resolve(
118
+ attrs_outputs_keys: @attrs_outputs.keys,
119
+ attrs_outputs_values: @attrs_outputs.values,
120
+ system: self
121
+ )
122
+
123
+ self
124
+ end
125
+
126
+ def resolve_hosts(outputs:)
127
+ if !@mapping.key? :hosts_output
128
+ return self
129
+ end
130
+
131
+ ::Kitchen::Terraform::SystemHostsResolver.new(outputs: outputs).resolve(
132
+ hosts_output: @mapping.fetch(:hosts_output),
133
+ system: self,
134
+ )
135
+
136
+ self
137
+ end
118
138
  end
119
139
  end
120
140
  end
@@ -34,8 +34,7 @@ module Kitchen
34
34
 
35
35
  self
36
36
  rescue ::KeyError => key_error
37
- raise ::Kitchen::Terraform::Error,
38
- "Resolving the attrs of system #{system} failed\n#{key_error}"
37
+ raise ::Kitchen::Terraform::Error, "Resolving attrs failed\n#{key_error}"
39
38
  end
40
39
 
41
40
  private
@@ -29,7 +29,7 @@ module Kitchen
29
29
  def resolve(hosts_output:, system:)
30
30
  system.add_hosts hosts: @outputs.fetch(hosts_output).fetch("value")
31
31
  rescue ::KeyError => key_error
32
- raise ::Kitchen::Terraform::Error, "Resolving the hosts of system #{system} failed\n#{key_error}"
32
+ raise ::Kitchen::Terraform::Error, "Resolving hosts failed\n#{key_error}"
33
33
  end
34
34
 
35
35
  private
@@ -72,7 +72,7 @@ module ::Kitchen::Terraform::Version
72
72
 
73
73
  # @api private
74
74
  def value
75
- self.value = ::Gem::Version.new "4.5.0" if not @value
75
+ self.value = ::Gem::Version.new "4.6.0" if not @value
76
76
  @value
77
77
  end
78
78
 
@@ -16,12 +16,11 @@
16
16
 
17
17
  require "kitchen"
18
18
  require "kitchen/terraform/config_attribute/color"
19
+ require "kitchen/terraform/config_attribute/fail_fast"
19
20
  require "kitchen/terraform/config_attribute/systems"
20
21
  require "kitchen/terraform/configurable"
21
22
  require "kitchen/terraform/error"
22
23
  require "kitchen/terraform/inspec_options_mapper"
23
- require "kitchen/terraform/system_attrs_resolver"
24
- require "kitchen/terraform/system_hosts_resolver"
25
24
 
26
25
  module Kitchen
27
26
  # This namespace is defined by Kitchen.
@@ -59,6 +58,10 @@ module Kitchen
59
58
  #
60
59
  # {include:Kitchen::Terraform::ConfigAttribute::Color}
61
60
  #
61
+ # ==== fail_fast
62
+ #
63
+ # {include:Kitchen::Terraform::ConfigAttribute::FailFast}
64
+ #
62
65
  # ==== systems
63
66
  #
64
67
  # {include:Kitchen::Terraform::ConfigAttribute::Systems}
@@ -71,6 +74,7 @@ module Kitchen
71
74
  include ::Kitchen::Configurable
72
75
  include ::Kitchen::Logging
73
76
  include ::Kitchen::Terraform::ConfigAttribute::Color
77
+ include ::Kitchen::Terraform::ConfigAttribute::FailFast
74
78
  include ::Kitchen::Terraform::ConfigAttribute::Systems
75
79
  include ::Kitchen::Terraform::Configurable
76
80
  @api_version = 2
@@ -84,8 +88,9 @@ module Kitchen
84
88
  # @return [void]
85
89
  def call(_kitchen_state)
86
90
  load_outputs
87
- config_systems.each do |system|
88
- verify system: system
91
+ verify_systems
92
+ if !@error_messages.empty?
93
+ raise ::Kitchen::ActionFailed, @error_messages.join("\n\n")
89
94
  end
90
95
  rescue ::Kitchen::Terraform::Error => error
91
96
  raise ::Kitchen::ActionFailed, error.message
@@ -113,6 +118,14 @@ module Kitchen
113
118
 
114
119
  private
115
120
 
121
+ def handle_error(message:)
122
+ if config_fail_fast
123
+ raise ::Kitchen::Terraform::Error, message
124
+ else
125
+ @error_messages.push message
126
+ end
127
+ end
128
+
116
129
  def load_outputs
117
130
  instance.driver.retrieve_outputs do |outputs:|
118
131
  @outputs.replace ::Kitchen::Util.stringified_hash outputs
@@ -121,6 +134,7 @@ module Kitchen
121
134
 
122
135
  def initialize(configuration = {})
123
136
  init_config configuration
137
+ @error_messages = []
124
138
  @inspec_options = { "distinct_exit" => false }
125
139
  @outputs = {}
126
140
  end
@@ -141,24 +155,24 @@ module Kitchen
141
155
  raise ::Kitchen::ClientError, load_error.message
142
156
  end
143
157
 
144
- def system_attrs_resolver
145
- @system_attrs_resolver ||= ::Kitchen::Terraform::SystemAttrsResolver.new outputs: @outputs
146
- end
147
-
148
- def system_hosts_resolver
149
- @system_hosts_resolver ||= ::Kitchen::Terraform::SystemHostsResolver.new outputs: @outputs
150
- end
151
-
152
158
  def system_inspec_options(system:)
153
159
  ::Kitchen::Terraform::InSpecOptionsMapper.new(system: system).map options: @inspec_options.dup
154
160
  end
155
161
 
156
162
  def verify(system:)
157
- ::Kitchen::Terraform::System
158
- .new(mapping: system)
159
- .resolve_attrs(system_attrs_resolver: system_attrs_resolver)
160
- .resolve_hosts(system_hosts_resolver: system_hosts_resolver)
161
- .verify(inspec_options: system_inspec_options(system: system), inspec_profile_path: inspec_profile_path)
163
+ ::Kitchen::Terraform::System.new(mapping: system).verify(
164
+ inspec_options: system_inspec_options(system: system),
165
+ inspec_profile_path: inspec_profile_path,
166
+ outputs: @outputs
167
+ )
168
+ rescue => error
169
+ handle_error message: error.message
170
+ end
171
+
172
+ def verify_systems
173
+ config_systems.each do |system|
174
+ verify system: system
175
+ end
162
176
  end
163
177
  end
164
178
  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.5.0
4
+ version: 4.6.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-10 00:00:00.000000000 Z
64
+ date: 2019-04-11 00:00:00.000000000 Z
65
65
  dependencies:
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: guard-bundler
@@ -406,6 +406,7 @@ files:
406
406
  - lib/kitchen/terraform/config_attribute/client.rb
407
407
  - lib/kitchen/terraform/config_attribute/color.rb
408
408
  - lib/kitchen/terraform/config_attribute/command_timeout.rb
409
+ - lib/kitchen/terraform/config_attribute/fail_fast.rb
409
410
  - lib/kitchen/terraform/config_attribute/lock.rb
410
411
  - lib/kitchen/terraform/config_attribute/lock_timeout.rb
411
412
  - lib/kitchen/terraform/config_attribute/parallelism.rb
metadata.gz.sig CHANGED
Binary file