kitchen-terraform 2.1.0 → 3.0.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.
Files changed (35) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +40 -43
  5. data/lib/kitchen/{terraform/client.rb → driver.rb} +4 -5
  6. data/lib/kitchen/driver/terraform.rb +367 -300
  7. data/lib/kitchen/provisioner.rb +22 -0
  8. data/lib/kitchen/provisioner/terraform.rb +70 -13
  9. data/lib/kitchen/terraform/client_version_verifier.rb +8 -3
  10. data/lib/kitchen/terraform/config_attribute.rb +0 -5
  11. data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +21 -5
  12. data/lib/kitchen/terraform/config_attribute/color.rb +15 -4
  13. data/lib/kitchen/terraform/config_attribute/command_timeout.rb +7 -4
  14. data/lib/kitchen/terraform/config_attribute/groups.rb +63 -27
  15. data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +16 -7
  16. data/lib/kitchen/terraform/config_attribute/parallelism.rb +12 -4
  17. data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +13 -6
  18. data/lib/kitchen/terraform/config_attribute/{directory.rb → root_module_directory.rb} +9 -8
  19. data/lib/kitchen/terraform/config_attribute/variable_files.rb +19 -2
  20. data/lib/kitchen/terraform/config_attribute/variables.rb +18 -4
  21. data/lib/kitchen/terraform/configurable.rb +0 -19
  22. data/lib/kitchen/terraform/shell_out.rb +66 -0
  23. data/lib/kitchen/terraform/version.rb +1 -1
  24. data/lib/kitchen/verifier.rb +22 -0
  25. data/lib/kitchen/verifier/terraform.rb +116 -60
  26. data/lib/kitchen/verifier/terraform/configure_inspec_runner_attributes.rb +37 -24
  27. data/lib/kitchen/verifier/terraform/enumerate_groups_and_hostnames.rb +35 -17
  28. metadata +29 -12
  29. metadata.gz.sig +3 -2
  30. data/lib/kitchen/terraform/clear_directory.rb +0 -38
  31. data/lib/kitchen/terraform/client/command.rb +0 -168
  32. data/lib/kitchen/terraform/client/options.rb +0 -275
  33. data/lib/kitchen/terraform/config_attribute/state.rb +0 -55
  34. data/lib/kitchen/terraform/config_attribute/verify_plugins.rb +0 -52
  35. data/lib/kitchen/terraform/create_directories.rb +0 -39
@@ -1,275 +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/terraform/client"
18
-
19
- # Represents supported options for client commands.
20
- class ::Kitchen::Terraform::Client::Options
21
- # Adds -backend-config with arguments to the options.
22
- #
23
- # @param key [#to_s] the backend configuration key
24
- # @param value [#to_s] the backend configuration value
25
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
26
- def backend_config(key:, value:)
27
- add option: "-backend-config='#{key}=#{value}'"
28
- end
29
-
30
- # Adds -backend-config with arguments to the options multiple times.
31
- #
32
- # @param keys_and_values [::Hash<#to_s, #to_s>] the backend configuration keys and values
33
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
34
- def backend_configs(keys_and_values:)
35
- keys_and_values
36
- .inject self do |additional_options, (key, value)|
37
- additional_options
38
- .backend_config(
39
- key: key,
40
- value: value
41
- )
42
- end
43
- end
44
-
45
- # Adds -input=false to the options.
46
- #
47
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
48
- def disable_input
49
- add option: "-input=false"
50
- end
51
-
52
- # Adds -auto-approve=true to the options.
53
- #
54
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
55
- def enable_auto_approve
56
- add option: "-auto-approve=true"
57
- end
58
-
59
- # Adds -backend=true to the options.
60
- #
61
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
62
- def enable_backend
63
- add option: "-backend=true"
64
- end
65
-
66
- # Adds -check-variables=true to the options.
67
- #
68
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
69
- def enable_check_variables
70
- add option: "-check-variables=true"
71
- end
72
-
73
- # Adds -get=true to the options.
74
- #
75
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
76
- def enable_get
77
- add option: "-get=true"
78
- end
79
-
80
- # Adds -force to the options.
81
- #
82
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
83
- def force
84
- add option: "-force"
85
- end
86
-
87
- # Adds -force-copy to the options.
88
- #
89
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
90
- def force_copy
91
- add option: "-force-copy"
92
- end
93
-
94
- # Adds -from-module with an argument to the options.
95
- #
96
- # @param source [#to_s] the module source
97
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
98
- def from_module(source:)
99
- add option: "-from-module=#{source}"
100
- end
101
-
102
- # Adds -json to the options.
103
- #
104
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
105
- def json
106
- add option: "-json"
107
- end
108
-
109
- # Adds -lock=true to the options.
110
- #
111
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
112
- def enable_lock
113
- add option: "-lock=true"
114
- end
115
-
116
- # Adds -refresh=true to the options.
117
- #
118
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
119
- def enable_refresh
120
- add option: "-refresh=true"
121
- end
122
-
123
- # Adds -lock-timeout with an argument to the options.
124
- #
125
- # @param duration [#to_s] the lock timeout duration
126
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
127
- def lock_timeout(duration:)
128
- add option: "-lock-timeout=#{duration}"
129
- end
130
-
131
- # Conditionally adds -no-color to the options.
132
- #
133
- # @param toggle [::TrueClass, ::FalseClass] the flag toggle
134
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
135
- def maybe_no_color(toggle:)
136
- toggle and no_color or self
137
- end
138
-
139
- # Conditionally adds -plugin-dir to the options.
140
- #
141
- # @param path [::TrueClass, ::FalseClass] the path to the plugin directory
142
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
143
- def maybe_plugin_dir(path:)
144
- path and plugin_dir path: path or self
145
- end
146
-
147
- # Adds -no-color to the options.
148
- #
149
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
150
- def no_color
151
- add option: "-no-color"
152
- end
153
-
154
- # Adds -parallelism with an argument to the options.
155
- #
156
- # @param concurrent_operations [#to_s] the number of concurrent operations
157
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
158
- def parallelism(concurrent_operations:)
159
- add option: "-parallelism=#{concurrent_operations}"
160
- end
161
-
162
- # Adds -plugin-dir with an argument to the options.
163
- #
164
- # @param path [#to_s] the path to the plugin directory
165
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
166
- def plugin_dir(path:)
167
- add option: "-plugin-dir=#{path}"
168
- end
169
-
170
- # Adds -state with an argument to the options.
171
- #
172
- # @param path [#to_s] the path to the input state file
173
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
174
- def state(path:)
175
- add option: "-state=#{path}"
176
- end
177
-
178
- # Adds -state-out with an argument to the options.
179
- #
180
- # @param path [#to_s] the path to the output state file
181
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
182
- def state_out(path:)
183
- add option: "-state-out=#{path}"
184
- end
185
-
186
- # Adds -upgrade to the options.
187
- #
188
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
189
- def upgrade
190
- add option: "-upgrade"
191
- end
192
-
193
- # Adds -var with arguments to the options.
194
- #
195
- # @param key [#to_s] the variable key
196
- # @param value [#to_s] the variable value
197
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
198
- def var(key:, value:)
199
- add option: "-var='#{key}=#{value}'"
200
- end
201
-
202
- # Adds -var with arguments to the options multiple times.
203
- #
204
- # @param keys_and_values [::Hash<#to_s, #to_s>] the variable keys and values
205
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
206
- def vars(keys_and_values:)
207
- keys_and_values
208
- .inject self do |additional_options, (key, value)|
209
- additional_options
210
- .var(
211
- key: key,
212
- value: value
213
- )
214
- end
215
- end
216
-
217
- # Adds -var-file with an argument to the options.
218
- #
219
- # @param path [#to_s] the path to the variable file
220
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
221
- def var_file(path:)
222
- add option: "-var-file=#{path}"
223
- end
224
-
225
- # Adds -var-file with an argument to the options multiple times.
226
- #
227
- # @param paths [::Array<#to_s>] the paths to the variable files
228
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
229
- def var_files(paths:)
230
- paths
231
- .inject self do |additional_options, path|
232
- additional_options.var_file path: path
233
- end
234
- end
235
-
236
- # Adds -verify-plugins with an argument to the options.
237
- #
238
- # @param toggle [#to_s] toggle to enable or disable
239
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
240
- def verify_plugins(toggle:)
241
- add option: "-verify-plugins=#{toggle}"
242
- end
243
-
244
- # The options expressed as a space delimited string.
245
- #
246
- # @return [::String] the options string
247
- def to_s
248
- @options.join " "
249
- end
250
-
251
- private
252
-
253
- # Adds an option to the collection.
254
- #
255
- # @api private
256
- # @param option [::String] the option to be added
257
- # @return [::Kitchen::Terraform::Client::Options] the expanded options
258
- def add(option:)
259
- self
260
- .class
261
- .new(
262
- option: option,
263
- options: @options
264
- )
265
- end
266
-
267
- # Initializes the collection of options.
268
- #
269
- # @api private
270
- # @param option [::String] a new option to add to the collection.
271
- # @param options [::Array] the current collection
272
- def initialize(option: nil, options: [])
273
- @options = options + [option].compact
274
- end
275
- end
@@ -1,55 +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/terraform/config_attribute"
18
- require "kitchen/terraform/config_attribute_cacher"
19
- require "kitchen/terraform/config_schemas/string"
20
- require "kitchen/terraform/file_path_config_attribute_definer"
21
-
22
- # The +:state+ configuration attribute is an optianl string which contains the path to the Terraform state file which
23
- # will be generated and managed.
24
- #
25
- # @abstract It must be included by a plugin class in order to be used.
26
- # @see https://www.terraform.io/docs/commands/apply.html#state-path Terraform: Command: apply: -state-path
27
- # @see https://www.terraform.io/docs/state/index.html Terraform: State
28
- module ::Kitchen::Terraform::ConfigAttribute::State
29
- # A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
30
- #
31
- # @param plugin_class [::Kitchen::Configurable] A plugin class.
32
- # @return [void]
33
- def self.included(plugin_class)
34
- ::Kitchen::Terraform::FilePathConfigAttributeDefiner
35
- .new(
36
- attribute: self,
37
- schema: ::Kitchen::Terraform::ConfigSchemas::String
38
- )
39
- .define plugin_class: plugin_class
40
- end
41
-
42
- # @return [::Symbol] the symbol corresponding to this attribute.
43
- def self.to_sym
44
- :state
45
- end
46
-
47
- extend ::Kitchen::Terraform::ConfigAttributeCacher
48
-
49
- # The path to a file under the kitchen-terraform suite directory.
50
- #
51
- # @return [::String] +".kitchen/kitchen-terraform/<suite_name>/terraform.tfstate"+.
52
- def config_state_default_value
53
- instance_pathname filename: "terraform.tfstate"
54
- end
55
- end
@@ -1,52 +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/terraform/config_attribute"
18
- require "kitchen/terraform/config_attribute_cacher"
19
- require "kitchen/terraform/config_attribute_definer"
20
- require "kitchen/terraform/config_schemas/boolean"
21
-
22
- # The +:verify_plugins+ configuration attribute is an optional boolean which toggles verification of Terraform plugins.
23
- #
24
- # @abstract It must be included by a plugin class in order to be used.
25
- # @see https://www.terraform.io/docs/commands/init.html#plugin-installation Terraform: Command: init: Plugin
26
- # Installation
27
- module ::Kitchen::Terraform::ConfigAttribute::VerifyPlugins
28
- # A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
29
- #
30
- # @param plugin_class [::Kitchen::Configurable] A plugin class.
31
- # @return [void]
32
- def self.included(plugin_class)
33
- ::Kitchen::Terraform::ConfigAttributeDefiner
34
- .new(
35
- attribute: self,
36
- schema: ::Kitchen::Terraform::ConfigSchemas::Boolean
37
- )
38
- .define plugin_class: plugin_class
39
- end
40
-
41
- # @return [::Symbol] the symbol corresponding to the attribute.
42
- def self.to_sym
43
- :verify_plugins
44
- end
45
-
46
- extend ::Kitchen::Terraform::ConfigAttributeCacher
47
-
48
- # @return [true]
49
- def config_verify_plugins_default_value
50
- true
51
- end
52
- end
@@ -1,39 +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 "dry/monads"
18
- require "fileutils"
19
- require "kitchen/terraform"
20
-
21
- # Creates directories on the filesystem.
22
- module ::Kitchen::Terraform::CreateDirectories
23
- extend ::Dry::Monads::Either::Mixin
24
- extend ::Dry::Monads::Try::Mixin
25
-
26
- # Invokes the function.
27
- #
28
- # @param directories [::Array<::String>, ::String] the list of directories to create.
29
- # @return [::Dry::Monads::Either] the result of the function.
30
- def self.call(directories:)
31
- Try ::SystemCallError do
32
- ::FileUtils.makedirs directories
33
- end.to_either.bind do
34
- Right "Created directories #{directories}"
35
- end.or do |error|
36
- Left error.to_s
37
- end
38
- end
39
- end