kitchen-terraform 1.0.2 → 2.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 (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +3 -3
  5. data/lib/kitchen/driver/terraform.rb +363 -221
  6. data/lib/kitchen/provisioner/terraform.rb +2 -3
  7. data/lib/kitchen/terraform.rb +3 -1
  8. data/lib/kitchen/terraform/clear_directory.rb +38 -0
  9. data/lib/kitchen/terraform/client/command.rb +168 -0
  10. data/lib/kitchen/terraform/client/options.rb +275 -0
  11. data/lib/kitchen/terraform/client_version_verifier.rb +57 -0
  12. data/lib/{terraform/debug_logger.rb → kitchen/terraform/config_attribute.rb} +7 -13
  13. data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +53 -0
  14. data/lib/kitchen/terraform/config_attribute/color.rb +56 -0
  15. data/lib/kitchen/terraform/config_attribute/command_timeout.rb +52 -0
  16. data/lib/kitchen/terraform/config_attribute/directory.rb +54 -0
  17. data/lib/kitchen/terraform/config_attribute/groups.rb +96 -0
  18. data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +52 -0
  19. data/lib/kitchen/terraform/config_attribute/parallelism.rb +53 -0
  20. data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +55 -0
  21. data/lib/kitchen/terraform/config_attribute/state.rb +55 -0
  22. data/lib/kitchen/terraform/config_attribute/variable_files.rb +51 -0
  23. data/lib/kitchen/terraform/config_attribute/variables.rb +53 -0
  24. data/lib/kitchen/terraform/config_attribute/verify_plugins.rb +52 -0
  25. data/lib/kitchen/terraform/config_attribute_cacher.rb +44 -0
  26. data/lib/kitchen/terraform/config_attribute_definer.rb +66 -0
  27. data/lib/kitchen/terraform/config_predicates.rb +21 -0
  28. data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +72 -0
  29. data/lib/{terraform.rb → kitchen/terraform/config_schemas.rb} +4 -2
  30. data/lib/kitchen/terraform/config_schemas/array_of_hashes_of_symbols_and_strings.rb +47 -0
  31. data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +31 -0
  32. data/lib/kitchen/terraform/config_schemas/boolean.rb +27 -0
  33. data/lib/kitchen/terraform/config_schemas/hash_of_symbols_and_strings.rb +32 -0
  34. data/lib/kitchen/terraform/config_schemas/integer.rb +27 -0
  35. data/lib/kitchen/terraform/config_schemas/optional_string.rb +31 -0
  36. data/lib/kitchen/terraform/config_schemas/string.rb +26 -0
  37. data/lib/kitchen/terraform/configurable.rb +75 -0
  38. data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +48 -0
  39. data/lib/{terraform/project_version.rb → kitchen/terraform/version.rb} +3 -3
  40. data/lib/kitchen/verifier/terraform.rb +40 -129
  41. data/lib/kitchen/verifier/terraform/configure_inspec_runner_attributes.rb +7 -4
  42. data/lib/kitchen/verifier/terraform/enumerate_groups_and_hostnames.rb +2 -2
  43. metadata +69 -43
  44. metadata.gz.sig +0 -0
  45. data/lib/kitchen/driver/terraform/verify_client_version.rb +0 -44
  46. data/lib/kitchen/driver/terraform/workflow.rb +0 -90
  47. data/lib/kitchen/terraform/client/apply.rb +0 -38
  48. data/lib/kitchen/terraform/client/execute_command.rb +0 -56
  49. data/lib/kitchen/terraform/client/get.rb +0 -35
  50. data/lib/kitchen/terraform/client/output.rb +0 -50
  51. data/lib/kitchen/terraform/client/plan.rb +0 -42
  52. data/lib/kitchen/terraform/client/process_options.rb +0 -87
  53. data/lib/kitchen/terraform/client/validate.rb +0 -35
  54. data/lib/kitchen/terraform/client/version.rb +0 -48
  55. data/lib/kitchen/terraform/define_config_attribute.rb +0 -39
  56. data/lib/kitchen/terraform/define_integer_config_attribute.rb +0 -43
  57. data/lib/kitchen/terraform/define_string_config_attribute.rb +0 -43
  58. data/lib/terraform/configurable.rb +0 -42
@@ -0,0 +1,72 @@
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/logic"
18
+ require "kitchen/terraform/config_predicates"
19
+
20
+ # Behaviour to provide a configuration attribute predicate for a hash including only symbol keys and string values.
21
+ #
22
+ # This module must be declared as providing predicates and extended in a schema's configuration in order to be used.
23
+ #
24
+ # @see http://dry-rb.org/gems/dry-validation/custom-predicates/ DRY Logic Custom Predicates
25
+ module ::Kitchen::Terraform::ConfigPredicates::HashOfSymbolsAndStrings
26
+ include ::Dry::Logic::Predicates
27
+
28
+ predicate :hash_of_symbols_and_strings? do |value|
29
+ value.kind_of? ::Hash and
30
+ all_symbols? keys: value.keys and
31
+ all_strings? values: value.values
32
+ end
33
+
34
+ private_class_method
35
+
36
+ # If all keys are symbols then the result is +true+; else the result is +false+.
37
+ #
38
+ # @api private
39
+ # @param keys [::Enumerable] keys that must be only symbols
40
+ # @return [::TrueClass, ::FalseClass] the result
41
+ def self.all_symbols?(keys:)
42
+ keys
43
+ .all? do |key|
44
+ key.kind_of? ::Symbol
45
+ end
46
+ end
47
+
48
+ # If all values are strings then the result is +true+; else the result is +false+.
49
+ #
50
+ # @api private
51
+ # @param values [::Enumerable] values that must be only strings
52
+ # @return [::TrueClass, ::FalseClass] the result
53
+ def self.all_strings?(values:)
54
+ values
55
+ .all? do |value|
56
+ value.kind_of? ::String
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def messages
63
+ super
64
+ .merge(
65
+ en: {
66
+ errors: {
67
+ hash_of_symbols_and_strings?: "must be a hash which includes only symbol keys and string values"
68
+ }
69
+ }
70
+ )
71
+ end
72
+ end
@@ -14,6 +14,8 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- # Namespace for kitchen-terraform
18
- module Terraform
17
+ require "kitchen/terraform"
18
+
19
+ # The namespace for configuration attribute schemas.
20
+ module ::Kitchen::Terraform::ConfigSchemas
19
21
  end
@@ -0,0 +1,47 @@
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-validation"
18
+ require "kitchen/terraform/config_predicates/hash_of_symbols_and_strings"
19
+ require "kitchen/terraform/config_schemas"
20
+
21
+ # A validation schema for a configuration attribute which is an array of hashes including only symbol keys and string
22
+ # values.
23
+ #
24
+ # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
25
+ ::Kitchen::Terraform::ConfigSchemas::ArrayOfHashesOfSymbolsAndStrings =
26
+ ::Dry::Validation
27
+ .Schema do
28
+ configure do
29
+ predicates ::Kitchen::Terraform::ConfigPredicates::HashOfSymbolsAndStrings
30
+ extend ::Kitchen::Terraform::ConfigPredicates::HashOfSymbolsAndStrings
31
+ end
32
+ required(:value)
33
+ .each do
34
+ schema do
35
+ required(:name).filled :str?
36
+ optional(:attributes).value :hash_of_symbols_and_strings?
37
+ optional(:controls)
38
+ .each(
39
+ :filled?,
40
+ :str?
41
+ )
42
+ optional(:hostnames).value :str?
43
+ optional(:port).value :int?
44
+ optional(:username).value :str?
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
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-validation"
18
+ require "kitchen/terraform/config_schemas"
19
+
20
+ # A validation schema for a configuration attribute which is an array including only strings.
21
+ #
22
+ # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
23
+ ::Kitchen::Terraform::ConfigSchemas::ArrayOfStrings =
24
+ ::Dry::Validation
25
+ .Schema do
26
+ required(:value)
27
+ .each(
28
+ :filled?,
29
+ :str?
30
+ )
31
+ end
@@ -0,0 +1,27 @@
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-validation"
18
+ require "kitchen/terraform/config_schemas"
19
+
20
+ # A validation schema for a configuration attribute which is a boolean.
21
+ #
22
+ # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
23
+ ::Kitchen::Terraform::ConfigSchemas::Boolean =
24
+ ::Dry::Validation
25
+ .Schema do
26
+ required(:value).filled :bool?
27
+ end
@@ -0,0 +1,32 @@
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-validation"
18
+ require "kitchen/terraform/config_predicates/hash_of_symbols_and_strings"
19
+ require "kitchen/terraform/config_schemas"
20
+
21
+ # A validation schema for a configuration attribute which is a hash including only symbol keys and string values.
22
+ #
23
+ # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
24
+ ::Kitchen::Terraform::ConfigSchemas::HashOfSymbolsAndStrings =
25
+ ::Dry::Validation
26
+ .Schema do
27
+ configure do
28
+ predicates ::Kitchen::Terraform::ConfigPredicates::HashOfSymbolsAndStrings
29
+ extend ::Kitchen::Terraform::ConfigPredicates::HashOfSymbolsAndStrings
30
+ end
31
+ required(:value).value :hash_of_symbols_and_strings?
32
+ end
@@ -0,0 +1,27 @@
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-validation"
18
+ require "kitchen/terraform/config_schemas"
19
+
20
+ # A validation schema for a configuration attribute which is an integer.
21
+ #
22
+ # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
23
+ ::Kitchen::Terraform::ConfigSchemas::Integer =
24
+ ::Dry::Validation
25
+ .Schema do
26
+ required(:value).filled :int?
27
+ end
@@ -0,0 +1,31 @@
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-validation"
18
+ require "kitchen/terraform/config_schemas"
19
+
20
+ # A validation schema for a configuration attribute which is an optional string.
21
+ #
22
+ # @see http://dry-rb.org/gems/dry-validation/basics/working-with-schemas/ DRY Validation Working With Schemas
23
+ ::Kitchen::Terraform::ConfigSchemas::OptionalString =
24
+ ::Dry::Validation
25
+ .Schema do
26
+ required(:value)
27
+ .maybe(
28
+ :str?,
29
+ :filled?
30
+ )
31
+ end
@@ -0,0 +1,26 @@
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-validation"
18
+ require "kitchen/terraform/config_schemas"
19
+
20
+ # Defines a validation schema for a string.
21
+
22
+ ::Kitchen::Terraform::ConfigSchemas::String =
23
+ ::Dry::Validation
24
+ .Schema do
25
+ required(:value).filled :str?
26
+ end
@@ -0,0 +1,75 @@
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"
19
+ require "kitchen/terraform/version"
20
+
21
+ # Refinements to Kitchen::Configurable.
22
+ #
23
+ # @see https://github.com/test-kitchen/test-kitchen/blob/v1.16.0/lib/kitchen/configurable.rb Kitchen::Configurable
24
+ module ::Kitchen::Terraform::Configurable
25
+ # A callback to define the plugin version which is invoked when this module is included in a plugin class.
26
+ #
27
+ # @return [void]
28
+ def self.included(configurable_class)
29
+ configurable_class.plugin_version ::Kitchen::Terraform::VERSION
30
+ end
31
+
32
+ # @return [::Kitchen::Driver::Terraform] the driver which will manage the lifecycle actions of the instance.
33
+ def driver
34
+ instance.driver
35
+ end
36
+
37
+ # Alternative implementation of Kitchen::Configurable#finalize_config! which validates the configuration before
38
+ # attempting to expand paths.
39
+ #
40
+ # @note this method should be removed when Test Kitchen: Issue #1229 is solved.
41
+ # @param instance [::Kitchen::Instance] an associated instance.
42
+ # @return [self] itself, for use in chaining.
43
+ # @raise [::Kitchen::ClientError] if the instance is nil.
44
+ # @see https://github.com/test-kitchen/test-kitchen/blob/v1.16.0/lib/kitchen/configurable.rb#L46
45
+ # Kitchen::Configurable#finalize_config!
46
+ # @see https://github.com/test-kitchen/test-kitchen/issues/1229 Test Kitchen: Issue #1229
47
+ def finalize_config!(instance)
48
+ instance or
49
+ raise(
50
+ ::Kitchen::ClientError,
51
+ "Instance must be provided to #{self}"
52
+ )
53
+
54
+ @instance = instance
55
+ validate_config!
56
+ expand_paths!
57
+ load_needed_dependencies!
58
+
59
+ self
60
+ end
61
+
62
+ # Constructs a pathname under the Test Kitchen instance directory.
63
+ #
64
+ # @return [::String] +"<kitchen-root>/.kitchen/kitchen-terraform/<suite-platform>/<filename>"+.
65
+ def instance_pathname(filename:)
66
+ ::File
67
+ .join(
68
+ config.fetch(:kitchen_root),
69
+ ".kitchen",
70
+ "kitchen-terraform",
71
+ instance.name,
72
+ filename
73
+ )
74
+ end
75
+ end
@@ -0,0 +1,48 @@
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"
18
+ require "kitchen/terraform/config_attribute_definer"
19
+
20
+ # Defines a file path configuration attribute on a plugin class.
21
+ class ::Kitchen::Terraform::FilePathConfigAttributeDefiner
22
+ # Defines the file path configuration attribute on a plugin class.
23
+ #
24
+ # @param plugin_class [::Kitchen::ConfigAttributeVerifier] A plugin class which has configuration
25
+ # attribute verification behaviour.
26
+ # @return [void]
27
+ def define(plugin_class:)
28
+ @definer.define plugin_class: plugin_class
29
+ plugin_class.expand_path_for @attribute.to_sym
30
+ end
31
+
32
+ private
33
+
34
+ # Initializes a definer.
35
+ #
36
+ # @api private
37
+ # @param attribute [::Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class.
38
+ # @param schema [::Dry::Validation::Schema] a schema to use for validation of values of the attribute.
39
+ def initialize(attribute:, schema:)
40
+ @attribute = attribute
41
+ @definer =
42
+ ::Kitchen::Terraform::ConfigAttributeDefiner
43
+ .new(
44
+ attribute: attribute,
45
+ schema: schema
46
+ )
47
+ end
48
+ end
@@ -14,6 +14,6 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- module Terraform
18
- PROJECT_VERSION = "1.0.2".freeze
19
- end
17
+ require "kitchen/terraform"
18
+
19
+ ::Kitchen::Terraform::VERSION = "2.0.0".freeze