kitchen-terraform 3.3.1 → 4.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 (36) 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 +45 -28
  5. data/lib/kitchen/driver/terraform.rb +87 -66
  6. data/lib/kitchen/provisioner/terraform.rb +1 -1
  7. data/lib/kitchen/terraform/client_version_verifier.rb +3 -3
  8. data/lib/kitchen/terraform/command/output.rb +43 -40
  9. data/lib/kitchen/{verifier/terraform/configure_inspec_runner_host.rb → terraform/config_attribute/systems.rb} +18 -11
  10. data/lib/kitchen/terraform/config_attribute/variable_files.rb +1 -1
  11. data/lib/kitchen/terraform/config_schemas/system.rb +555 -0
  12. data/lib/kitchen/terraform/{breaking/kitchen_instance.rb → config_schemas/systems.rb} +16 -5
  13. data/lib/kitchen/terraform/configurable.rb +2 -6
  14. data/lib/kitchen/terraform/inspec.rb +74 -0
  15. data/lib/kitchen/terraform/inspec_options_mapper.rb +49 -0
  16. data/lib/kitchen/terraform/inspec_with_hosts.rb +49 -0
  17. data/lib/kitchen/terraform/inspec_without_hosts.rb +44 -0
  18. data/lib/kitchen/terraform/shell_out.rb +13 -10
  19. data/lib/kitchen/terraform/system.rb +120 -0
  20. data/lib/kitchen/terraform/system_attrs_resolver.rb +57 -0
  21. data/lib/kitchen/terraform/system_hosts_resolver.rb +45 -0
  22. data/lib/kitchen/terraform/version.rb +60 -17
  23. data/lib/kitchen/verifier/terraform.rb +162 -156
  24. metadata +45 -41
  25. metadata.gz.sig +0 -0
  26. data/lib/kitchen/terraform/config_attribute/groups.rb +0 -148
  27. data/lib/kitchen/terraform/config_schemas/groups.rb +0 -52
  28. data/lib/kitchen/terraform/deprecating/kitchen_instance.rb +0 -61
  29. data/lib/kitchen/terraform/kitchen_instance.rb +0 -49
  30. data/lib/kitchen/verifier/terraform/configure_inspec_runner_attributes.rb +0 -98
  31. data/lib/kitchen/verifier/terraform/configure_inspec_runner_backend.rb +0 -32
  32. data/lib/kitchen/verifier/terraform/configure_inspec_runner_controls.rb +0 -41
  33. data/lib/kitchen/verifier/terraform/configure_inspec_runner_port.rb +0 -40
  34. data/lib/kitchen/verifier/terraform/configure_inspec_runner_ssh_key.rb +0 -41
  35. data/lib/kitchen/verifier/terraform/configure_inspec_runner_user.rb +0 -40
  36. data/lib/kitchen/verifier/terraform/enumerate_groups_and_hostnames.rb +0 -82
@@ -1,49 +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"
18
- require "kitchen/terraform/breaking/kitchen_instance"
19
- require "kitchen/terraform/deprecating/kitchen_instance"
20
- require "kitchen/terraform/version"
21
- require "rubygems"
22
-
23
- # This module is a factory for KitchenInstances.
24
- #
25
- # KitchenInstances wrap ::Kitchen::Instance in order to provide a contextual deprecation warning for actions which will
26
- # no longer support concurrency.
27
- module ::Kitchen::Terraform::KitchenInstance
28
- # Creates a new KitchenInstance.
29
- #
30
- # If the version satisfies the requirement of +~> 3.3+ then a breaking KitchenInstance is created.
31
- #
32
- # If the version satisfies the requirement of +>= 4+ then a breaking KitchenInstance is created.
33
- #
34
- # @param kitchen_instance [::Kitchen::Instance] the ::Kitchen::Instance which will act as the delegate.
35
- # @param version [::Kitchen::Terraform::Version] the version to compare against the requirement.
36
- # @return [::Kitchen::Terraform::Breaking::KitchenInstance, ::Kitchen::Terraform::Deprecating::KitchenInstance] the
37
- # new KitchenInstance.
38
- def self.new(kitchen_instance:, version: ::Kitchen::Terraform::Version.new)
39
- version
40
- .if_satisfies requirement: ::Gem::Requirement.new("~> 3.3") do
41
- return ::Kitchen::Terraform::Deprecating::KitchenInstance.new kitchen_instance
42
- end
43
-
44
- version
45
- .if_satisfies requirement: ::Gem::Requirement.new(">= 4") do
46
- return ::Kitchen::Terraform::Breaking::KitchenInstance.new kitchen_instance
47
- end
48
- end
49
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016-2017 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/error"
18
- require "kitchen/verifier/terraform"
19
-
20
- # Configures the InSpec profile attributes for the Inspec::Runner used by the verifier to verify a group.
21
- #
22
- # Three different maps are merged to create the profile attributes.
23
- #
24
- # The first map is comprised of attributes that are external to the Terraform state.
25
- #
26
- # {
27
- # "terraform_state" => "/path/to/terraform/state"
28
- # }
29
- #
30
- # The second map is comprised of attributes that represent the Terraform output variables of the Terraform state. This
31
- # map takes precedence in any key conflicts with the first map.
32
- #
33
- # {
34
- # "first_output_variable_name" => "first_output_variable_value",
35
- # "second_output_variable_name" => "second_output_variable_value"
36
- # }
37
- #
38
- # The third map is comprised of attributes defined by a group's +:attributes+; the keys are converted to strings and the
39
- # values are assumed to be Terraform output variable names which are resolved. This map takes precedence in any key
40
- # conflicts with the second map.
41
- #
42
- # {
43
- # first_attribute_name: "second_output_variable_name"
44
- # }
45
- #
46
- # # becomes
47
- #
48
- # {
49
- # "first_attribute_name" => "second_output_variable_value"
50
- # }
51
- #
52
- # @see https://github.com/chef/inspec/blob/master/lib/inspec/runner.rb Inspec::Runner
53
- # @see https://github.com/chef/kitchen-inspec/blob/master/lib/kitchen/verifier/inspec.rb kitchen-inspec verifier
54
- # @see https://www.inspec.io/docs/reference/profiles/ InSpec Profiles
55
- # @see https://www.terraform.io/docs/configuration/outputs.html Terraform output variables
56
- # @see https://www.terraform.io/docs/state/index.html Terraform state
57
- module ::Kitchen::Verifier::Terraform::ConfigureInspecRunnerAttributes
58
- # Invokes the function
59
- #
60
- # @param group [::Hash] a kitchen-terraform verifier group.
61
- # @param output [::String] the output of the Terraform state.
62
- # @raise [::Kitchen::Terraform::Error] if the configuration fails.
63
- # @return [::Hash] the configured attributes.
64
- def self.call(group:, output:)
65
- group
66
- .fetch(
67
- :attributes,
68
- {}
69
- )
70
- .tap do |group_attributes|
71
- return(
72
- output
73
- .keys
74
- .+(group_attributes.keys)
75
- .zip(
76
- output
77
- .keys
78
- .+(group_attributes.values)
79
- )
80
- .reduce ::Hash.new do |resolved_attributes, (attribute_name, output_name)|
81
- resolved_attributes
82
- .merge(
83
- attribute_name
84
- .to_s =>
85
- output
86
- .fetch(output_name.to_s)
87
- .fetch("value")
88
- )
89
- end
90
- )
91
- end
92
- rescue ::KeyError => error
93
- raise(
94
- ::Kitchen::Terraform::Error,
95
- "Configuring InSpec runner attributes resulted in failure: #{error.message}"
96
- )
97
- end
98
- end
@@ -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 "kitchen/verifier/terraform"
18
-
19
- # Configures the backend for the Inspec::Runner used by the verifier to verify a group's host.
20
- #
21
- # If the hostname is "localhost" then the existing backend is overwritten to be "local".
22
- #
23
- # @see https://github.com/chef/inspec/blob/master/lib/inspec/runner.rb Inspec::Runner
24
- module ::Kitchen::Verifier::Terraform::ConfigureInspecRunnerBackend
25
- # Invokes the function.
26
- #
27
- # @param hostname [::String] the hostname being verified.
28
- # @param options [::Hash] the verifier's Inspec::Runner options.
29
- def self.call(hostname:, options:)
30
- hostname == "localhost" and options.store "backend", "local"
31
- end
32
- end
@@ -1,41 +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
-
19
- # Configures a group's InSpec profile controls to be inclued by the Inspec::Runner used by the verifier.
20
- #
21
- # If a group omits +:controls+ or if +:controls+ is empty then all of the profile's controls will be included.
22
- #
23
- # @see https://github.com/chef/inspec/blob/master/lib/inspec/runner.rb ::Inspec::Runner
24
- # @see https://www.inspec.io/docs/reference/profiles/ InSpec profiles
25
- module ::Kitchen::Verifier::Terraform::ConfigureInspecRunnerControls
26
- # Invokes the function
27
- #
28
- # @param group [::Hash] the group being verified.
29
- # @param options [:Hash] the verifier's Inspec::Runner's options.
30
- def self.call(group:, options:)
31
- group[:controls]
32
- .tap do |controls|
33
- controls and
34
- options
35
- .store(
36
- :controls,
37
- controls
38
- )
39
- end
40
- end
41
- end
@@ -1,40 +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
-
19
- # Configures the port for the Inspec::Runner used by the verifier to verify a group.
20
- #
21
- # The default port is the transport's +:port+.
22
- #
23
- # @see https://github.com/chef/inspec/blob/master/lib/inspec/runner.rb Inspec::Runner
24
- module ::Kitchen::Verifier::Terraform::ConfigureInspecRunnerPort
25
- # Invokes the function.
26
- #
27
- # @param group [::Hash] the group being verified.
28
- # @param options [::Hash] the Inspec::Runner's options.
29
- def self.call(group:, options:)
30
- group[:port]
31
- .tap do |port|
32
- port and
33
- options
34
- .store(
35
- "port",
36
- port
37
- )
38
- end
39
- end
40
- end
@@ -1,41 +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
-
19
- # Configures the private SSH key to be used by the verifier's InSpec Runner to verify a group.
20
- #
21
- # The default value is the Test Kitchen SSH Transport's +:ssh_key+ configuration attribute.
22
- #
23
- # @see https://github.com/chef/inspec/blob/master/lib/inspec/runner.rb InSpec Runner
24
- # @see https://github.com/test-kitchen/test-kitchen/blob/v1.16.0/lib/kitchen/transport/ssh.rb Test Kitchen SSH Transport
25
- module ::Kitchen::Verifier::Terraform::ConfigureInspecRunnerSSHKey
26
- # Invoke the function.
27
- #
28
- # @param group [::Hash] the group being verified.
29
- # @param options [::Hash] the Inspec::Runner's options.
30
- def self.call(group:, options:)
31
- group[:ssh_key]
32
- .tap do |ssh_key|
33
- ssh_key and
34
- options
35
- .store(
36
- "key_files",
37
- [ssh_key]
38
- )
39
- end
40
- end
41
- end
@@ -1,40 +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
-
19
- # Configures the user for the Inspec::Runner used by the verifier to verify a group.
20
- #
21
- # The default user is the transport's +:username+.
22
- #
23
- # @see https://github.com/chef/inspec/blob/master/lib/inspec/runner.rb Inspec::Runner
24
- module ::Kitchen::Verifier::Terraform::ConfigureInspecRunnerUser
25
- # Invoke the function.
26
- #
27
- # @param group [::Hash] the group being verified.
28
- # @param options [::Hash] the Inspec::Runner's options.
29
- def self.call(group:, options:)
30
- group[:username]
31
- .tap do |username|
32
- username and
33
- options
34
- .store(
35
- "user",
36
- username
37
- )
38
- end
39
- end
40
- end
@@ -1,82 +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/error"
18
- require "kitchen/verifier/terraform"
19
-
20
- # Enumerates each group and the hostnames of each group.
21
- #
22
- # If a group associates +:hostnames+ with a value then that value is assumed to be the name of a Terraform output
23
- # variable which has a value of a string or array containing one or more hostnames; those hostnames will be enumerated
24
- # with the group.
25
- #
26
- # If a group omits +:hostnames+ then the hostname +"localhost"+ will be enumerated with that group; this hostname will
27
- # cause the InSpec profile to be executed locally and enable verification of resources in the Terraform state without
28
- # the use of Secure Shell (SSH).
29
- #
30
- # @see https://en.wikipedia.org/wiki/Secure_Shell Secure Shell
31
- # @see https://www.terraform.io/docs/configuration/outputs.html Terraform output variables
32
- # @see https://www.terraform.io/docs/state/index.html Terraform state
33
- module ::Kitchen::Verifier::Terraform::EnumerateGroupsAndHostnames
34
- # Invokes the function.
35
- #
36
- # @param groups [::Array] a collection of groups.
37
- # @raise [::Kitchen::Terraform::Error] if the enumeration fails.
38
- # @return [void]
39
- # @yieldparam group [::Hash] the group from which hostnamess are being enumerated.
40
- # @yieldparam hostname [::String] a hostname from the group.
41
- def self.call(groups:, output:, &block)
42
- groups
43
- .each do |group|
44
- each_resolved_hostname_and_group(
45
- group: group,
46
- hostnames: group[:hostnames],
47
- output: output,
48
- &block
49
- )
50
- end
51
- rescue ::KeyError => error
52
- raise(
53
- ::Kitchen::Terraform::Error,
54
- "Enumeration of groups and hostnames resulted in failure due to the omission of the configured :hostnames " \
55
- "output or an unexpected output structure: #{error.message}"
56
- )
57
- end
58
-
59
- private_class_method
60
-
61
- # @api private
62
- def self.each_resolved_hostname_and_group(group:, hostnames:, output:)
63
- if hostnames
64
- Array(
65
- output
66
- .fetch(hostnames)
67
- .fetch("value")
68
- )
69
- .each do |hostname|
70
- yield(
71
- group: group,
72
- hostname: hostname
73
- )
74
- end
75
- else
76
- yield(
77
- group: group,
78
- hostname: "localhost"
79
- )
80
- end
81
- end
82
- end