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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +201 -0
- data/README.md +284 -0
- data/lib/kitchen/verifier/terraform.rb +1 -1
- data/lib/terraform/version.rb +1 -1
- metadata +5 -20
- metadata.gz.sig +0 -0
- data/spec/lib/kitchen/driver/terraform_spec.rb +0 -126
- data/spec/lib/kitchen/provisioner/terraform_spec.rb +0 -106
- data/spec/lib/kitchen/verifier/terraform_spec.rb +0 -302
- data/spec/lib/terraform/apply_command_spec.rb +0 -32
- data/spec/lib/terraform/client_spec.rb +0 -211
- data/spec/lib/terraform/command_options_spec.rb +0 -34
- data/spec/lib/terraform/get_command_spec.rb +0 -30
- data/spec/lib/terraform/inspec_runner_spec.rb +0 -67
- data/spec/lib/terraform/output_command_spec.rb +0 -58
- data/spec/lib/terraform/plan_command_spec.rb +0 -46
- data/spec/lib/terraform/validate_command_spec.rb +0 -30
- data/spec/lib/terraform/version_command_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -27
- data/spec/support/coverage.rb +0 -21
- data/spec/support/terraform/client_holder_context.rb +0 -26
- data/spec/support/terraform/client_holder_examples.rb +0 -36
- data/spec/support/terraform/command_examples.rb +0 -80
- data/spec/support/terraform/versions_are_set_examples.rb +0 -35
@@ -1,32 +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 'terraform/apply_command'
|
18
|
-
require 'support/terraform/command_examples'
|
19
|
-
|
20
|
-
RSpec.describe Terraform::ApplyCommand do
|
21
|
-
it_behaves_like Terraform::Command do
|
22
|
-
let(:command_options) { "-input=false -state=#{state}" }
|
23
|
-
|
24
|
-
let(:described_instance) { described_class.new state: state, plan: target }
|
25
|
-
|
26
|
-
let(:name) { 'apply' }
|
27
|
-
|
28
|
-
let(:state) { '<state_pathname>' }
|
29
|
-
|
30
|
-
let(:target) { '<plan_pathname>' }
|
31
|
-
end
|
32
|
-
end
|
@@ -1,211 +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/client'
|
19
|
-
require 'terraform/command'
|
20
|
-
|
21
|
-
RSpec.describe Terraform::Client do
|
22
|
-
let(:described_instance) { described_class.new instance: instance }
|
23
|
-
|
24
|
-
let(:instance) { instance_double Kitchen::Instance }
|
25
|
-
|
26
|
-
let :instance_directory do
|
27
|
-
"#{kitchen_root}/.kitchen/kitchen-terraform/#{instance_name}"
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:instance_name) { '<instance_name>' }
|
31
|
-
|
32
|
-
let(:kitchen_root) { '<kitchen_root>' }
|
33
|
-
|
34
|
-
let :provisioner do
|
35
|
-
Kitchen::Provisioner::Terraform.new kitchen_root: kitchen_root
|
36
|
-
end
|
37
|
-
|
38
|
-
before do
|
39
|
-
allow(instance).to receive(:name).with(no_args).and_return instance_name
|
40
|
-
|
41
|
-
allow(instance).to receive(:provisioner).with(no_args)
|
42
|
-
.and_return provisioner
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#apply_execution_plan' do
|
46
|
-
after { described_instance.apply_execution_plan }
|
47
|
-
|
48
|
-
subject { described_instance }
|
49
|
-
|
50
|
-
it 'applies the plan to the state' do
|
51
|
-
is_expected.to receive(:run)
|
52
|
-
.with command_class: Terraform::ApplyCommand,
|
53
|
-
state: described_instance.state_pathname,
|
54
|
-
plan: described_instance.plan_pathname
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#download_modules' do
|
59
|
-
after { described_instance.download_modules }
|
60
|
-
|
61
|
-
subject { described_instance }
|
62
|
-
|
63
|
-
it 'downloads the modules required in the directory' do
|
64
|
-
is_expected.to receive(:run).with command_class: Terraform::GetCommand,
|
65
|
-
dir: described_instance.directory
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#extract_list_output(name:)' do
|
70
|
-
let(:name) { instance_double Object }
|
71
|
-
|
72
|
-
let(:output) { 'foo,bar' }
|
73
|
-
|
74
|
-
before do
|
75
|
-
allow(described_instance).to receive(:extract_output).with(name: name)
|
76
|
-
.and_yield output
|
77
|
-
end
|
78
|
-
|
79
|
-
subject do
|
80
|
-
->(block) { described_instance.extract_list_output name: name, &block }
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'splits and yields the extracted comma seperated output' do
|
84
|
-
is_expected.to yield_with_args %w(foo bar)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#extract_output(name:)' do
|
89
|
-
let(:name) { instance_double Object }
|
90
|
-
|
91
|
-
let(:output) { "foo\n" }
|
92
|
-
|
93
|
-
before do
|
94
|
-
allow(described_instance).to receive(:run).with(
|
95
|
-
command_class: Terraform::OutputCommand,
|
96
|
-
state: described_instance.state_pathname, name: name
|
97
|
-
).and_yield output
|
98
|
-
end
|
99
|
-
|
100
|
-
subject do
|
101
|
-
->(block) { described_instance.extract_output name: name, &block }
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'chomps and yields the extracted output from the state' do
|
105
|
-
is_expected.to yield_with_args 'foo'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '#fetch_version' do
|
110
|
-
let(:output) { instance_double Object }
|
111
|
-
|
112
|
-
before do
|
113
|
-
allow(described_instance).to receive(:run)
|
114
|
-
.with(command_class: Terraform::VersionCommand).and_yield output
|
115
|
-
end
|
116
|
-
|
117
|
-
subject { ->(block) { described_instance.fetch_version(&block) } }
|
118
|
-
|
119
|
-
it 'yields the Terraform version' do
|
120
|
-
is_expected.to yield_with_args output
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe '#instance_directory' do
|
125
|
-
subject { described_instance.instance_directory.to_s }
|
126
|
-
|
127
|
-
it { is_expected.to eq instance_directory }
|
128
|
-
end
|
129
|
-
|
130
|
-
describe '#plan_destructive_execution' do
|
131
|
-
after { described_instance.plan_destructive_execution }
|
132
|
-
|
133
|
-
subject { described_instance }
|
134
|
-
|
135
|
-
it 'plans a destructive execution against the state' do
|
136
|
-
is_expected.to receive(:run)
|
137
|
-
.with command_class: Terraform::PlanCommand, destroy: true,
|
138
|
-
out: described_instance.plan_pathname,
|
139
|
-
state: described_instance.state_pathname,
|
140
|
-
var: described_instance.variables,
|
141
|
-
var_file: described_instance.variable_files,
|
142
|
-
dir: described_instance.directory
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe '#plan_execution' do
|
147
|
-
after { described_instance.plan_execution }
|
148
|
-
|
149
|
-
subject { described_instance }
|
150
|
-
|
151
|
-
it 'plans an execution against the state' do
|
152
|
-
is_expected.to receive(:run)
|
153
|
-
.with command_class: Terraform::PlanCommand, destroy: false,
|
154
|
-
out: described_instance.plan_pathname,
|
155
|
-
state: described_instance.state_pathname,
|
156
|
-
var: described_instance.variables,
|
157
|
-
var_file: described_instance.variable_files,
|
158
|
-
dir: described_instance.directory
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe '#plan_pathname' do
|
163
|
-
subject { described_instance.plan_pathname.to_s }
|
164
|
-
|
165
|
-
it { is_expected.to eq "#{instance_directory}/terraform.tfplan" }
|
166
|
-
end
|
167
|
-
|
168
|
-
describe '#run(command_class:, **parameters)' do
|
169
|
-
let(:command) { instance_double Terraform::Command }
|
170
|
-
|
171
|
-
let(:command_class) { Class.new.include Terraform::Command }
|
172
|
-
|
173
|
-
let(:output) { instance_double Object }
|
174
|
-
|
175
|
-
let(:parameters) { { foo: 'bar' } }
|
176
|
-
|
177
|
-
before do
|
178
|
-
allow(command_class).to receive(:new).with(**parameters)
|
179
|
-
.and_yield command
|
180
|
-
|
181
|
-
allow(command).to receive(:execute).with(no_args).and_yield output
|
182
|
-
end
|
183
|
-
|
184
|
-
subject do
|
185
|
-
lambda do |block|
|
186
|
-
described_instance.run command_class: command_class, **parameters,
|
187
|
-
&block
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
it('yields the command output') { is_expected.to yield_with_args output }
|
192
|
-
end
|
193
|
-
|
194
|
-
describe '#state_pathname' do
|
195
|
-
subject { described_instance.state_pathname.to_s }
|
196
|
-
|
197
|
-
it { is_expected.to eq "#{instance_directory}/terraform.tfstate" }
|
198
|
-
end
|
199
|
-
|
200
|
-
describe '#validate_configuration_files' do
|
201
|
-
after { described_instance.validate_configuration_files }
|
202
|
-
|
203
|
-
subject { described_instance }
|
204
|
-
|
205
|
-
it 'validates the configuration files in the directory' do
|
206
|
-
is_expected.to receive(:run)
|
207
|
-
.with command_class: Terraform::ValidateCommand,
|
208
|
-
dir: described_instance.directory
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
@@ -1,34 +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 'terraform/command_options'
|
18
|
-
|
19
|
-
RSpec.describe Terraform::CommandOptions do
|
20
|
-
describe '#to_s' do
|
21
|
-
let :described_instance do
|
22
|
-
described_class.new single_argument: 'argument',
|
23
|
-
multiple_arguments: %w(argument argument)
|
24
|
-
end
|
25
|
-
|
26
|
-
subject { described_instance.to_s }
|
27
|
-
|
28
|
-
it 'transform the options in to flags' do
|
29
|
-
is_expected.to eq '-single-argument=argument ' \
|
30
|
-
'-multiple-arguments=argument ' \
|
31
|
-
'-multiple-arguments=argument'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,30 +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 'terraform/get_command'
|
18
|
-
require 'support/terraform/command_examples'
|
19
|
-
|
20
|
-
RSpec.describe Terraform::GetCommand do
|
21
|
-
it_behaves_like Terraform::Command do
|
22
|
-
let(:command_options) { '-update=true' }
|
23
|
-
|
24
|
-
let(:described_instance) { described_class.new dir: target }
|
25
|
-
|
26
|
-
let(:name) { 'get' }
|
27
|
-
|
28
|
-
let(:target) { '<directory>' }
|
29
|
-
end
|
30
|
-
end
|
@@ -1,67 +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/verifier/terraform'
|
18
|
-
require 'terraform/inspec_runner'
|
19
|
-
|
20
|
-
RSpec.describe Terraform::InspecRunner do
|
21
|
-
let(:described_instance) { described_class.new }
|
22
|
-
|
23
|
-
describe '#add(targets:)' do
|
24
|
-
let(:target) { instance_double Object }
|
25
|
-
|
26
|
-
after { described_instance.add targets: [target] }
|
27
|
-
|
28
|
-
subject { described_instance }
|
29
|
-
|
30
|
-
it 'adds each target' do
|
31
|
-
is_expected.to receive(:add_target).with target, described_instance.conf
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#define_attribute(name:, value:)' do
|
36
|
-
let(:name) { :name }
|
37
|
-
|
38
|
-
let(:value) { instance_double Object }
|
39
|
-
|
40
|
-
before { described_instance.define_attribute name: name, value: value }
|
41
|
-
|
42
|
-
subject { described_instance.conf.fetch 'attributes' }
|
43
|
-
|
44
|
-
it 'defines an attribute on the runner' do
|
45
|
-
is_expected.to include 'name' => value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#verify_run(verifier:)' do
|
50
|
-
let(:exit_code) { instance_double Object }
|
51
|
-
|
52
|
-
let(:verifier) { instance_double Kitchen::Verifier::Terraform }
|
53
|
-
|
54
|
-
before do
|
55
|
-
allow(described_instance).to receive(:run).with(no_args)
|
56
|
-
.and_return exit_code
|
57
|
-
end
|
58
|
-
|
59
|
-
after { described_instance.verify_run verifier: verifier }
|
60
|
-
|
61
|
-
subject { verifier }
|
62
|
-
|
63
|
-
it 'verifies the exit code after running' do
|
64
|
-
is_expected.to receive(:evaluate).with exit_code: exit_code
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,58 +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 'terraform/output_command'
|
18
|
-
require 'support/terraform/command_examples'
|
19
|
-
|
20
|
-
RSpec.describe Terraform::OutputCommand do
|
21
|
-
let(:described_instance) { described_class.new state: state, name: target }
|
22
|
-
|
23
|
-
let(:state) { '<state_pathname>' }
|
24
|
-
|
25
|
-
let(:target) { '<name>' }
|
26
|
-
|
27
|
-
it_behaves_like Terraform::Command do
|
28
|
-
let(:command_options) { "-state=#{state}" }
|
29
|
-
|
30
|
-
let(:name) { 'output' }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#handle(error:)' do
|
34
|
-
let(:error) { instance_double Exception }
|
35
|
-
|
36
|
-
before do
|
37
|
-
allow(error).to receive(:message).with(no_args).and_return message
|
38
|
-
|
39
|
-
allow(error).to receive(:backtrace).with no_args
|
40
|
-
end
|
41
|
-
|
42
|
-
subject { proc { described_instance.handle error: error } }
|
43
|
-
|
44
|
-
context 'when the error message does match the pattern' do
|
45
|
-
let(:message) { 'nothing to output' }
|
46
|
-
|
47
|
-
it 'does raise an error' do
|
48
|
-
is_expected.to raise_error Terraform::OutputNotFound
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'when the error message does not match the pattern' do
|
53
|
-
let(:message) { 'a thing to output' }
|
54
|
-
|
55
|
-
it('does not raise an error') { is_expected.to_not raise_error }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,46 +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 'terraform/plan_command'
|
18
|
-
require 'support/terraform/command_examples'
|
19
|
-
|
20
|
-
RSpec.describe Terraform::PlanCommand do
|
21
|
-
it_behaves_like Terraform::Command do
|
22
|
-
let :command_options do
|
23
|
-
"-destroy=#{destroy} -input=false -out=#{out} " \
|
24
|
-
"-state=#{state} -var=#{var} -var-file=#{var_file}"
|
25
|
-
end
|
26
|
-
|
27
|
-
let :described_instance do
|
28
|
-
described_class.new destroy: destroy, out: out, state: state, var: var,
|
29
|
-
var_file: var_file, dir: target
|
30
|
-
end
|
31
|
-
|
32
|
-
let(:destroy) { true }
|
33
|
-
|
34
|
-
let(:name) { 'plan' }
|
35
|
-
|
36
|
-
let(:out) { '<plan_pathname>' }
|
37
|
-
|
38
|
-
let(:state) { '<state_pathname>' }
|
39
|
-
|
40
|
-
let(:target) { '<directory>' }
|
41
|
-
|
42
|
-
let(:var) { '"foo=bar"' }
|
43
|
-
|
44
|
-
let(:var_file) { '<variable_file>' }
|
45
|
-
end
|
46
|
-
end
|