kitchen-terraform 0.1.0 → 0.1.1

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.
@@ -50,7 +50,7 @@ module Kitchen
50
50
  end
51
51
 
52
52
  def evaluate(exit_code:)
53
- raise "Inspec Runner returns #{exit_code}" unless 0 == exit_code
53
+ raise "Inspec Runner returns #{exit_code}" unless exit_code.zero?
54
54
  end
55
55
 
56
56
  def groups
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module Terraform
18
- VERSION = '0.1.0'
18
+ VERSION = '0.1.1'
19
19
  end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lane
8
+ - Nick Willever
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain:
@@ -31,7 +32,7 @@ cert_chain:
31
32
  KucGZX3OeACVUSpmCOCQyma6sDHYWQZM/IgWi7tbLtG5b2GslkauPm4S3wadHi6W
32
33
  LOU=
33
34
  -----END CERTIFICATE-----
34
- date: 2016-07-22 00:00:00.000000000 Z
35
+ date: 2016-07-26 00:00:00.000000000 Z
35
36
  dependencies:
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: bundler-audit
@@ -259,6 +260,8 @@ executables: []
259
260
  extensions: []
260
261
  extra_rdoc_files: []
261
262
  files:
263
+ - LICENSE
264
+ - README.md
262
265
  - lib/kitchen/driver/terraform.rb
263
266
  - lib/kitchen/provisioner/terraform.rb
264
267
  - lib/kitchen/verifier/terraform.rb
@@ -277,24 +280,6 @@ files:
277
280
  - lib/terraform/validate_command.rb
278
281
  - lib/terraform/version.rb
279
282
  - lib/terraform/version_command.rb
280
- - spec/lib/kitchen/driver/terraform_spec.rb
281
- - spec/lib/kitchen/provisioner/terraform_spec.rb
282
- - spec/lib/kitchen/verifier/terraform_spec.rb
283
- - spec/lib/terraform/apply_command_spec.rb
284
- - spec/lib/terraform/client_spec.rb
285
- - spec/lib/terraform/command_options_spec.rb
286
- - spec/lib/terraform/get_command_spec.rb
287
- - spec/lib/terraform/inspec_runner_spec.rb
288
- - spec/lib/terraform/output_command_spec.rb
289
- - spec/lib/terraform/plan_command_spec.rb
290
- - spec/lib/terraform/validate_command_spec.rb
291
- - spec/lib/terraform/version_command_spec.rb
292
- - spec/spec_helper.rb
293
- - spec/support/coverage.rb
294
- - spec/support/terraform/client_holder_context.rb
295
- - spec/support/terraform/client_holder_examples.rb
296
- - spec/support/terraform/command_examples.rb
297
- - spec/support/terraform/versions_are_set_examples.rb
298
283
  homepage: https://github.com/newcontext/kitchen-terraform
299
284
  licenses:
300
285
  - Apache-2.0
metadata.gz.sig CHANGED
Binary file
@@ -1,126 +0,0 @@
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/driver/terraform'
18
- require 'terraform/error'
19
- require 'support/terraform/client_holder_context'
20
- require 'support/terraform/client_holder_examples'
21
- require 'support/terraform/versions_are_set_examples'
22
-
23
- RSpec.describe Kitchen::Driver::Terraform do
24
- let(:described_instance) { described_class.new }
25
-
26
- it_behaves_like Terraform::ClientHolder
27
-
28
- it_behaves_like 'versions are set'
29
-
30
- describe '.serial_actions' do
31
- subject(:serial_actions) { described_class.serial_actions }
32
-
33
- it('is empty') { is_expected.to be_empty }
34
- end
35
-
36
- describe '#create(_state = nil)' do
37
- include_context '#client'
38
-
39
- before do
40
- allow(client).to receive(:fetch_version).with(no_args).and_yield output
41
- end
42
-
43
- subject { proc { described_instance.create } }
44
-
45
- context 'when the Terraform version is supported' do
46
- let(:output) { 'v0.6.1' }
47
-
48
- it('does not raise an error') { is_expected.to_not raise_error }
49
- end
50
-
51
- context 'when the Terraform version is not supported' do
52
- let(:output) { 'v0.5.2' }
53
-
54
- it 'does raise an error' do
55
- is_expected.to raise_error Kitchen::ActionFailed
56
- end
57
- end
58
-
59
- context 'when the client command fails' do
60
- before do
61
- allow(client).to receive(:fetch_version).with(no_args)
62
- .and_raise Terraform::Error
63
- end
64
-
65
- it 'does raise an error' do
66
- is_expected.to raise_error Kitchen::ActionFailed
67
- end
68
- end
69
- end
70
-
71
- describe '#destroy(_state = nil)' do
72
- include_context '#client'
73
-
74
- let(:call_method) { described_instance.destroy }
75
-
76
- context 'when the Terraform state can be destroyed' do
77
- before do
78
- allow(client).to receive(:validate_configuration_files).with no_args
79
-
80
- allow(client).to receive(:download_modules).with no_args
81
-
82
- allow(client).to receive(:plan_destructive_execution).with no_args
83
-
84
- allow(client).to receive(:apply_execution_plan).with no_args
85
- end
86
-
87
- after { call_method }
88
-
89
- subject { client }
90
-
91
- it 'validates the configuration files' do
92
- is_expected.to receive(:validate_configuration_files).with no_args
93
- end
94
-
95
- it 'gets the modules' do
96
- is_expected.to receive(:download_modules).with no_args
97
- end
98
-
99
- it 'plans the destructive execution' do
100
- is_expected.to receive(:plan_destructive_execution).with no_args
101
- end
102
-
103
- it 'applies the execution plan' do
104
- is_expected.to receive(:apply_execution_plan).with no_args
105
- end
106
- end
107
-
108
- context 'when a client command fails' do
109
- before do
110
- allow(client).to receive(:validate_configuration_files).and_raise
111
- end
112
-
113
- subject { proc { call_method } }
114
-
115
- it 'raises an error' do
116
- is_expected.to raise_error Kitchen::ActionFailed
117
- end
118
- end
119
- end
120
-
121
- describe '#supported_version' do
122
- subject { described_instance.supported_version }
123
-
124
- it('equals v0.6') { is_expected.to eq 'v0.6' }
125
- end
126
- end
@@ -1,106 +0,0 @@
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/provisioner/terraform'
18
- require 'terraform/error'
19
- require 'support/terraform/client_holder_context'
20
- require 'support/terraform/client_holder_examples'
21
- require 'support/terraform/versions_are_set_examples'
22
-
23
- RSpec.describe Kitchen::Provisioner::Terraform do
24
- let(:described_instance) { described_class.new kitchen_root: kitchen_root }
25
-
26
- let(:kitchen_root) { '<kitchen_root>' }
27
-
28
- it_behaves_like Terraform::ClientHolder
29
-
30
- it_behaves_like 'versions are set'
31
-
32
- describe '#call(_state = nil)' do
33
- include_context '#client'
34
-
35
- let(:call_method) { described_instance.call }
36
-
37
- context 'when the configuration can be applied' do
38
- before do
39
- allow(client).to receive(:validate_configuration_files).with no_args
40
-
41
- allow(client).to receive(:download_modules).with no_args
42
-
43
- allow(client).to receive(:plan_execution).with no_args
44
-
45
- allow(client).to receive(:apply_execution_plan).with no_args
46
- end
47
-
48
- after { call_method }
49
-
50
- subject { client }
51
-
52
- it 'validates the configuration files' do
53
- is_expected.to receive(:validate_configuration_files).with no_args
54
- end
55
-
56
- it 'downloads the modules' do
57
- is_expected.to receive(:download_modules).with no_args
58
- end
59
-
60
- it 'plans the execution' do
61
- is_expected.to receive(:plan_execution).with no_args
62
- end
63
-
64
- it 'applies the execution plan' do
65
- is_expected.to receive(:apply_execution_plan).with no_args
66
- end
67
- end
68
-
69
- context 'when the configuration can not be applied due to failed command' do
70
- before do
71
- allow(client).to receive(:validate_configuration_files)
72
- .and_raise Terraform::Error
73
- end
74
-
75
- subject { proc { call_method } }
76
-
77
- it('raises an error') { is_expected.to raise_error Kitchen::ActionFailed }
78
- end
79
- end
80
-
81
- describe '#directory' do
82
- subject { described_instance.directory.to_s }
83
-
84
- it 'defaults to the Test Kitchen root directory' do
85
- is_expected.to eq kitchen_root
86
- end
87
- end
88
-
89
- describe '#kitchen_root' do
90
- subject { described_instance.kitchen_root.to_s }
91
-
92
- it('is the Test Kitchen root directory') { is_expected.to eq kitchen_root }
93
- end
94
-
95
- describe '#variable_files' do
96
- subject { described_instance.variable_files }
97
-
98
- it('defaults to empty array') { is_expected.to eq [] }
99
- end
100
-
101
- describe '#variables' do
102
- subject { described_instance.variables }
103
-
104
- it('defaults to empty array') { is_expected.to eq [] }
105
- end
106
- end
@@ -1,302 +0,0 @@
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 'inspec'
18
- require 'kitchen/verifier/terraform'
19
- require 'support/terraform/client_holder_context'
20
- require 'support/terraform/client_holder_examples'
21
- require 'support/terraform/versions_are_set_examples'
22
-
23
- RSpec.describe Kitchen::Verifier::Terraform do
24
- let(:config) { { kitchen_root: '<kitchen_root>' } }
25
-
26
- let(:described_instance) { described_class.new config }
27
-
28
- let(:state) { {} }
29
-
30
- shared_context '#instance' do
31
- let(:instance) { instance_double Kitchen::Instance }
32
-
33
- let(:logger) { instance_double Kitchen::Logger }
34
-
35
- let(:transport) { Kitchen::Transport::Ssh.new }
36
-
37
- let(:transport_config) { {} }
38
-
39
- before do
40
- described_instance.finalize_config! instance
41
-
42
- allow(instance).to receive(:logger).with(no_args).and_return logger
43
-
44
- allow(instance).to receive(:transport).with(no_args).and_return transport
45
-
46
- allow(logger).to receive :info
47
-
48
- allow(transport).to receive(:config).with(no_args)
49
- .and_return Kitchen::LazyHash
50
- .new(transport_config, instance_double(Object))
51
-
52
- allow(transport).to receive(:diagnose).with(no_args)
53
- .and_return transport_config
54
-
55
- allow(transport).to receive(:name).with(no_args)
56
- .and_return instance_double Object
57
- end
58
- end
59
-
60
- it_behaves_like Terraform::ClientHolder
61
-
62
- it_behaves_like 'versions are set'
63
-
64
- describe '#attributes(group:)' do
65
- subject { described_instance.attributes group: {} }
66
-
67
- it('defaults to an empty hash') { is_expected.to eq({}) }
68
- end
69
-
70
- describe '#call(state)' do
71
- include_context '#client'
72
-
73
- let(:call_method) { described_instance.call state }
74
-
75
- let(:config) { { groups: [group] } }
76
-
77
- let(:group) { { hostnames: hostnames } }
78
-
79
- let(:hostnames) { instance_double Object }
80
-
81
- context 'when the hostnames list output can be extracted' do
82
- let(:output) { instance_double Object }
83
-
84
- before do
85
- allow(client).to receive(:extract_list_output).with(name: hostnames)
86
- .and_yield output
87
- end
88
-
89
- after { call_method }
90
-
91
- subject { described_instance }
92
-
93
- it 'verifies the hosts of each group' do
94
- is_expected.to receive(:verify).with group: group, hostnames: output,
95
- state: state
96
- end
97
- end
98
-
99
- context 'when the hostnames list output can not be extracted' do
100
- before do
101
- allow(client).to receive(:extract_list_output).with(name: hostnames)
102
- .and_raise Terraform::Error
103
- end
104
-
105
- subject { proc { call_method } }
106
-
107
- it('raises an error') { is_expected.to raise_error Kitchen::ActionFailed }
108
- end
109
- end
110
-
111
- describe '#controls(group:)' do
112
- subject { described_instance.controls group: {} }
113
-
114
- it('defaults to an empty array') { is_expected.to eq [] }
115
- end
116
-
117
- describe '#evaluate(exit_code:)' do
118
- subject { proc { described_instance.evaluate exit_code: exit_code } }
119
-
120
- context 'when the exit code is 0' do
121
- let(:exit_code) { 0 }
122
-
123
- it('does not raise an error') { is_expected.to_not raise_error }
124
- end
125
-
126
- context 'when the exit code is not 0' do
127
- let(:exit_code) { 1 }
128
-
129
- it('raises an error') { is_expected.to raise_error RuntimeError }
130
- end
131
- end
132
-
133
- describe '#groups' do
134
- subject { described_instance.groups }
135
-
136
- it('defaults to an empty array') { is_expected.to eq [] }
137
- end
138
-
139
- describe '#initialize_runner(group:, hostname:, state:)' do
140
- let(:group) { instance_double Object }
141
-
142
- let(:hostname) { instance_double Object }
143
-
144
- let(:inspec_runner) { instance_double Terraform::InspecRunner }
145
-
146
- let :inspec_runner_class do
147
- class_double(Terraform::InspecRunner).as_stubbed_const
148
- end
149
-
150
- let(:name) { instance_double Object }
151
-
152
- let(:options) { instance_double Object }
153
-
154
- let(:state) { instance_double Object }
155
-
156
- let(:value) { instance_double Object }
157
-
158
- before do
159
- allow(described_instance).to receive(:runner_options_for_terraform)
160
- .with(group: group, hostname: hostname, state: state).and_return options
161
-
162
- allow(inspec_runner_class).to receive(:new).with(options)
163
- .and_yield inspec_runner
164
-
165
- allow(described_instance).to receive(:resolve_attributes)
166
- .with(group: group).and_yield name, value
167
-
168
- allow(inspec_runner).to receive(:define_attribute).with name: name,
169
- value: value
170
-
171
- allow(described_instance).to receive(:collect_tests).and_return []
172
-
173
- allow(inspec_runner).to receive(:add).with targets: kind_of(Array)
174
- end
175
-
176
- subject do
177
- lambda do |block|
178
- described_instance.initialize_runner group: group, hostname: hostname,
179
- state: state, &block
180
- end
181
- end
182
-
183
- it 'yields an InspecRunner for the group host' do
184
- is_expected.to yield_with_args inspec_runner
185
- end
186
- end
187
-
188
- describe '#port(group:)' do
189
- include_context '#instance'
190
-
191
- let(:group) { {} }
192
-
193
- let(:port) { instance_double Object }
194
-
195
- let(:transport_config) { { port: port } }
196
-
197
- subject { described_instance.port group: group }
198
-
199
- it 'defaults to the transport port configuration' do
200
- is_expected.to be port
201
- end
202
- end
203
-
204
- describe '#resolve_attributes(group:)' do
205
- include_context '#client'
206
-
207
- let(:method_name) { instance_double Object }
208
-
209
- let(:output) { instance_double Object }
210
-
211
- let(:variable_name) { instance_double Object }
212
-
213
- before do
214
- allow(client).to receive(:extract_output).with(name: variable_name)
215
- .and_yield output
216
- end
217
-
218
- subject do
219
- lambda do |block|
220
- described_instance.resolve_attributes group:
221
- { attributes: { method_name => variable_name } }, &block
222
- end
223
- end
224
-
225
- it 'extracts an output value for each attribute pair in the group' do
226
- is_expected.to yield_with_args method_name, output
227
- end
228
- end
229
-
230
- describe '#runner_options_for_terraform(group:, hostname:, state:)' do
231
- include_context '#instance'
232
-
233
- let(:controls) { instance_double Object }
234
-
235
- let(:group) { { controls: controls, port: port, username: username } }
236
-
237
- let(:hostname) { instance_double Object }
238
-
239
- let(:port) { instance_double Object }
240
-
241
- let(:username) { instance_double Object }
242
-
243
- before do
244
- allow(described_instance).to receive(:runner_options)
245
- .with(transport, state).and_return({})
246
- end
247
-
248
- subject do
249
- described_instance.runner_options_for_terraform group: group,
250
- hostname: hostname,
251
- state: state
252
- end
253
-
254
- it 'adds the group controls, host, port and user to the runner options' do
255
- is_expected.to include controls: controls, host: hostname, port: port,
256
- user: username
257
- end
258
- end
259
-
260
- describe '#username(group:)' do
261
- include_context '#instance'
262
-
263
- let(:transport_config) { { username: username } }
264
-
265
- let(:username) { instance_double Object }
266
-
267
- before do
268
- allow(transport_config).to receive(:fetch).with(:username)
269
- .and_return username
270
- end
271
-
272
- subject { described_instance.username group: {} }
273
-
274
- it('defaults to the transport username') { is_expected.to be username }
275
- end
276
-
277
- describe '#verify(group:, hostnames:, state:)' do
278
- let(:group) { { name: instance_double(Object) } }
279
-
280
- let(:hostname) { instance_double Object }
281
-
282
- let(:runner) { instance_double Terraform::InspecRunner }
283
-
284
- before do
285
- allow(described_instance).to receive(:initialize_runner)
286
- .with(group: group, hostname: hostname, state: state).and_yield runner
287
-
288
- allow(runner).to receive(:verify_run).with verifier: described_instance
289
- end
290
-
291
- after do
292
- described_instance.verify group: group, hostnames: [hostname],
293
- state: state
294
- end
295
-
296
- subject { runner }
297
-
298
- it 'verifies the Inspec run' do
299
- is_expected.to receive(:verify_run).with verifier: described_instance
300
- end
301
- end
302
- end