kitchen-terraform 5.1.1 → 5.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +37 -173
- data/lib/kitchen/driver/terraform.rb +196 -514
- data/lib/kitchen/provisioner/terraform.rb +88 -86
- data/lib/kitchen/terraform.rb +5 -6
- data/lib/kitchen/terraform/breaking.rb +7 -5
- data/lib/kitchen/terraform/command.rb +7 -5
- data/lib/kitchen/terraform/command/apply.rb +87 -0
- data/lib/kitchen/terraform/command/destroy.rb +88 -0
- data/lib/kitchen/terraform/command/get.rb +32 -0
- data/lib/kitchen/terraform/command/init.rb +102 -0
- data/lib/kitchen/terraform/command/output.rb +11 -50
- data/lib/kitchen/terraform/command/validate.rb +63 -0
- data/lib/kitchen/terraform/command/version.rb +5 -42
- data/lib/kitchen/terraform/command/workspace_delete.rb +41 -0
- data/lib/kitchen/terraform/command/workspace_new.rb +43 -0
- data/lib/kitchen/terraform/command/workspace_select.rb +43 -0
- data/lib/kitchen/terraform/command_executor.rb +60 -0
- data/lib/kitchen/terraform/command_flag.rb +23 -0
- data/lib/kitchen/terraform/command_flag/backend_config.rb +43 -0
- data/lib/kitchen/terraform/command_flag/color.rb +45 -0
- data/lib/kitchen/terraform/command_flag/lock_timeout.rb +42 -0
- data/lib/kitchen/terraform/command_flag/plugin_dir.rb +47 -0
- data/lib/kitchen/terraform/command_flag/upgrade.rb +45 -0
- data/lib/kitchen/terraform/command_flag/var.rb +43 -0
- data/lib/kitchen/terraform/command_flag/var_file.rb +45 -0
- data/lib/kitchen/terraform/config_attribute.rb +58 -55
- data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/client.rb +10 -3
- data/lib/kitchen/terraform/config_attribute/color.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/command_timeout.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/fail_fast.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/lock.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/parallelism.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +3 -3
- data/lib/kitchen/terraform/config_attribute/root_module_directory.rb +4 -4
- data/lib/kitchen/terraform/config_attribute/systems.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/variable_files.rb +4 -4
- data/lib/kitchen/terraform/config_attribute/variables.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/verify_version.rb +2 -2
- data/lib/kitchen/terraform/config_attribute_cacher.rb +27 -25
- data/lib/kitchen/terraform/config_attribute_definer.rb +37 -43
- data/lib/kitchen/terraform/config_attribute_type.rb +7 -5
- data/lib/kitchen/terraform/config_attribute_type/hash_of_symbols_and_strings.rb +32 -27
- data/lib/kitchen/terraform/config_attribute_type/integer.rb +4 -4
- data/lib/kitchen/terraform/config_predicates.rb +7 -5
- data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +6 -6
- data/lib/kitchen/terraform/config_schemas.rb +7 -5
- data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +20 -13
- data/lib/kitchen/terraform/config_schemas/boolean.rb +16 -9
- data/lib/kitchen/terraform/config_schemas/optional_string.rb +20 -13
- data/lib/kitchen/terraform/config_schemas/string.rb +13 -7
- data/lib/kitchen/terraform/config_schemas/system.rb +38 -16
- data/lib/kitchen/terraform/config_schemas/systems.rb +5 -2
- data/lib/kitchen/terraform/configurable.rb +41 -21
- data/lib/kitchen/terraform/debug_logger.rb +1 -1
- data/lib/kitchen/terraform/deprecating.rb +7 -5
- data/lib/kitchen/terraform/driver.rb +23 -0
- data/lib/kitchen/terraform/driver/create.rb +120 -0
- data/lib/kitchen/terraform/driver/destroy.rb +169 -0
- data/lib/kitchen/terraform/error.rb +7 -5
- data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +30 -27
- data/lib/kitchen/terraform/inspec.rb +3 -57
- data/lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb +59 -0
- data/lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb +69 -0
- data/lib/kitchen/terraform/inspec/without_hosts.rb +52 -0
- data/lib/kitchen/terraform/inspec_factory.rb +68 -0
- data/lib/kitchen/terraform/inspec_options_factory.rb +86 -0
- data/lib/kitchen/terraform/inspec_runner.rb +88 -0
- data/lib/kitchen/terraform/outputs_manager.rb +64 -0
- data/lib/kitchen/terraform/outputs_parser.rb +39 -0
- data/lib/kitchen/terraform/outputs_reader.rb +63 -0
- data/lib/kitchen/terraform/provisioner.rb +23 -0
- data/lib/kitchen/terraform/provisioner/converge.rb +206 -0
- data/lib/kitchen/terraform/raise.rb +23 -0
- data/lib/kitchen/terraform/raise/action_failed.rb +49 -0
- data/lib/kitchen/terraform/raise/client_error.rb +49 -0
- data/lib/kitchen/terraform/shell_out.rb +90 -59
- data/lib/kitchen/terraform/system.rb +63 -93
- data/lib/kitchen/terraform/system_attrs_inputs_resolver.rb +49 -0
- data/lib/kitchen/terraform/system_attrs_outputs_resolver.rb +80 -0
- data/lib/kitchen/terraform/system_bastion_host_resolver.rb +72 -0
- data/lib/kitchen/terraform/system_hosts_resolver.rb +39 -17
- data/lib/kitchen/terraform/system_inspec_map.rb +49 -0
- data/lib/kitchen/terraform/systems_verifier.rb +23 -0
- data/lib/kitchen/terraform/systems_verifier/fail_fast.rb +52 -0
- data/lib/kitchen/terraform/systems_verifier/fail_slow.rb +62 -0
- data/lib/kitchen/terraform/systems_verifier_factory.rb +50 -0
- data/lib/kitchen/terraform/unsupported_client_version_error.rb +26 -0
- data/lib/kitchen/terraform/variables_manager.rb +64 -0
- data/lib/kitchen/terraform/verify_version.rb +63 -20
- data/lib/kitchen/terraform/verify_version_rescue_strategy.rb +23 -0
- data/lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb +50 -0
- data/lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb +47 -0
- data/lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb +51 -0
- data/lib/kitchen/terraform/version.rb +59 -58
- data/lib/kitchen/terraform/version_verifier.rb +50 -0
- data/lib/kitchen/terraform/version_verifier_strategy.rb +25 -0
- data/lib/kitchen/terraform/version_verifier_strategy/supported.rb +33 -0
- data/lib/kitchen/terraform/version_verifier_strategy/unsupported.rb +34 -0
- data/lib/kitchen/terraform/version_verifier_strategy_factory.rb +50 -0
- data/lib/kitchen/verifier/terraform.rb +71 -62
- metadata +143 -80
- metadata.gz.sig +0 -0
- data/lib/kitchen/terraform/inspec_options_mapper.rb +0 -73
- data/lib/kitchen/terraform/inspec_with_hosts.rb +0 -50
- data/lib/kitchen/terraform/inspec_without_hosts.rb +0 -45
- data/lib/kitchen/terraform/system_attrs_resolver.rb +0 -60
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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/inspec_runner"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module InSpec
|
22
|
+
# FailFastWithHosts is the class of objects which execute InSpec against multiple hosts and raise rescued errors
|
23
|
+
# immediately.
|
24
|
+
class FailFastWithHosts
|
25
|
+
# exec executes the InSpec controls of an InSpec profile.
|
26
|
+
#
|
27
|
+
# @raise [Kitchen::TransientFailure] if the execution of InSpec fails.
|
28
|
+
# @return [self]
|
29
|
+
def exec
|
30
|
+
hosts.each do |host|
|
31
|
+
::Kitchen::Terraform::InSpecRunner.new(
|
32
|
+
options: options.merge(host: host),
|
33
|
+
profile_locations: profile_locations,
|
34
|
+
).exec
|
35
|
+
end
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# #initialize prepares a new instance of the class.
|
41
|
+
#
|
42
|
+
# @param hosts [Array<::String>] the names or addresses of hosts on which Inspec controls will be executed.
|
43
|
+
# @param options [Hash] options for execution.
|
44
|
+
# @param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls
|
45
|
+
# to be executed.
|
46
|
+
# @return [Kitchen::Terraform::InSpec::FailFastWithHosts]
|
47
|
+
def initialize(hosts:, options:, profile_locations:)
|
48
|
+
self.hosts = hosts
|
49
|
+
self.options = options
|
50
|
+
self.profile_locations = profile_locations
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
attr_accessor :hosts, :options, :profile_locations
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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/inspec_runner"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
module InSpec
|
23
|
+
# FailSlowWithHosts is the class of objects which execute InSpec against multiple hosts and raise rescued errors
|
24
|
+
# after all hosts have been tested.
|
25
|
+
class FailSlowWithHosts
|
26
|
+
# exec executes the InSpec controls of an InSpec profile.
|
27
|
+
#
|
28
|
+
# @raise [Kitchen::TransientFailure] if the execution of InSpec fails.
|
29
|
+
# @return [self]
|
30
|
+
def exec
|
31
|
+
hosts.each do |host|
|
32
|
+
exec_and_continue host: host
|
33
|
+
end
|
34
|
+
|
35
|
+
raise ::Kitchen::TransientFailure, messages.join("\n\n") if !messages.empty?
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# #initialize prepares a new instance of the class.
|
41
|
+
#
|
42
|
+
# @param hosts [Array<::String>] the names or addresses of hosts on which Inspec controls will be executed.
|
43
|
+
# @param options [Hash] options for execution.
|
44
|
+
# @param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls
|
45
|
+
# to be executed.
|
46
|
+
# @return [Kitchen::Terraform::InSpec::FailSlowWithHosts]
|
47
|
+
def initialize(hosts:, options:, profile_locations:)
|
48
|
+
self.hosts = hosts
|
49
|
+
self.messages = []
|
50
|
+
self.options = options
|
51
|
+
self.profile_locations = profile_locations
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_accessor :hosts, :messages, :options, :profile_locations
|
57
|
+
|
58
|
+
def exec_and_continue(host:)
|
59
|
+
::Kitchen::Terraform::InSpecRunner.new(
|
60
|
+
options: options.merge(host: host),
|
61
|
+
profile_locations: profile_locations,
|
62
|
+
).exec
|
63
|
+
rescue => error
|
64
|
+
messages.push error.message
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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/inspec_runner"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
module InSpec
|
23
|
+
# WithoutHosts is the class of objects which execute InSpec without hosts.
|
24
|
+
class WithoutHosts
|
25
|
+
# #exec executes the InSpec controls of an InSpec profile.
|
26
|
+
#
|
27
|
+
# @raise [Kitchen::TransientFailure] if the execution of InSpec fails.
|
28
|
+
# @return [self]
|
29
|
+
def exec
|
30
|
+
::Kitchen::Terraform::InSpecRunner.new(options: options, profile_locations: profile_locations).exec
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# #initialize prepares a new instance of the class.
|
36
|
+
#
|
37
|
+
# @param options [Hash] a mapping of InSpec options.
|
38
|
+
# @param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls
|
39
|
+
# to be executed.
|
40
|
+
# @return [Kitchen::Terraform::InSpec::WithoutHosts]
|
41
|
+
def initialize(options:, profile_locations:)
|
42
|
+
self.options = options
|
43
|
+
self.profile_locations = profile_locations
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_accessor :options, :profile_locations
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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/inspec/fail_fast_with_hosts"
|
18
|
+
require "kitchen/terraform/inspec/fail_slow_with_hosts"
|
19
|
+
require "kitchen/terraform/inspec/without_hosts"
|
20
|
+
|
21
|
+
module Kitchen
|
22
|
+
module Terraform
|
23
|
+
# InSpecFactory is the class of objects which build InSpec objects.
|
24
|
+
class InSpecFactory
|
25
|
+
# #build creates a new instance of an InSpec object.
|
26
|
+
#
|
27
|
+
# @param options [Hash] a mapping of InSpec options.
|
28
|
+
# @param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls to
|
29
|
+
# be executed.
|
30
|
+
# @return [Kitchen::Terraform::InSpec::WithoutHosts, Kitchen::Terraform::InSpec::FailFastWithHosts,
|
31
|
+
# Kitchen::Terraform::InSpec::FailFastWithoutHosts]
|
32
|
+
def build(options:, profile_locations:)
|
33
|
+
if hosts.empty?
|
34
|
+
::Kitchen::Terraform::InSpec::WithoutHosts.new(
|
35
|
+
options: options,
|
36
|
+
profile_locations: profile_locations,
|
37
|
+
)
|
38
|
+
elsif fail_fast
|
39
|
+
::Kitchen::Terraform::InSpec::FailFastWithHosts.new(
|
40
|
+
hosts: hosts,
|
41
|
+
options: options,
|
42
|
+
profile_locations: profile_locations,
|
43
|
+
)
|
44
|
+
else
|
45
|
+
::Kitchen::Terraform::InSpec::FailSlowWithHosts.new(
|
46
|
+
hosts: hosts,
|
47
|
+
options: options,
|
48
|
+
profile_locations: profile_locations,
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# #initialize prepares a new instance of the class
|
54
|
+
#
|
55
|
+
# @param fail_fast [Boolean] a toggle for fail fast or fail slow behaviour.
|
56
|
+
# @param hosts [Array<String>] a list of hosts to verify with InSpec.
|
57
|
+
# @return [Kitchen::Terraform::InSpecFactory]
|
58
|
+
def initialize(fail_fast:, hosts:)
|
59
|
+
self.fail_fast = fail_fast
|
60
|
+
self.hosts = hosts
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
attr_accessor :fail_fast, :hosts
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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/terraform/system_bastion_host_resolver"
|
19
|
+
require "kitchen/terraform/system_inspec_map"
|
20
|
+
require "rubygems"
|
21
|
+
|
22
|
+
module Kitchen
|
23
|
+
module Terraform
|
24
|
+
# InSpecOptionsMapper is the class of objects which build Inspec options.
|
25
|
+
class InSpecOptionsFactory
|
26
|
+
class << self
|
27
|
+
# #inputs_key provides a key for InSpec profile inputs which depends on the version of InSpec.
|
28
|
+
#
|
29
|
+
# @return [Symbol] if the version is less than 4.3.2, :attributes; else, :inputs.
|
30
|
+
def inputs_key
|
31
|
+
if ::Gem::Requirement.new("< 4.3.2").satisfied_by? ::Gem::Version.new ::Inspec::VERSION
|
32
|
+
:attributes
|
33
|
+
else
|
34
|
+
:inputs
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# #build creates a mapping of InSpec options. Most key-value pairs are derived from the configuration attributes
|
40
|
+
# of a system; some key-value pairs are hard-coded.
|
41
|
+
#
|
42
|
+
# @param attributes [Hash] the attributes to be added to the InSpec options.
|
43
|
+
# @param system_configuration_attributes [Hash] the configuration attributes of a system.
|
44
|
+
# @raise [Kitchen::ClientError] if the system bastion host fails to be resolved.
|
45
|
+
# @return [Hash] a mapping of InSpec options.
|
46
|
+
def build(attributes:, system_configuration_attributes:)
|
47
|
+
map_system_to_inspec system_configuration_attributes: system_configuration_attributes
|
48
|
+
options.store self.class.inputs_key, attributes
|
49
|
+
resolve_bastion_host system_configuration_attributes: system_configuration_attributes
|
50
|
+
|
51
|
+
options
|
52
|
+
end
|
53
|
+
|
54
|
+
# #initialize prepares a new instance of the class.
|
55
|
+
#
|
56
|
+
# @param outputs [Hash] the Terraform output variables.
|
57
|
+
# @return [Kitchen::Terraform::InSpecOptionsFactory]
|
58
|
+
def initialize(outputs:)
|
59
|
+
self.options = { "distinct_exit" => false }
|
60
|
+
self.system_bastion_host_resolver = ::Kitchen::Terraform::SystemBastionHostResolver.new outputs: outputs
|
61
|
+
self.system_inspec_map = ::Kitchen::Terraform::SYSTEM_INSPEC_MAP.dup
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
attr_accessor :options, :system_bastion_host_resolver, :system_inspec_map
|
67
|
+
|
68
|
+
def map_system_to_inspec(system_configuration_attributes:)
|
69
|
+
system_configuration_attributes.lazy.select do |attribute_name, _|
|
70
|
+
system_inspec_map.key?(attribute_name)
|
71
|
+
end.each do |attribute_name, attribute_value|
|
72
|
+
options.store system_inspec_map.fetch(attribute_name), attribute_value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def resolve_bastion_host(system_configuration_attributes:)
|
77
|
+
system_bastion_host_resolver.resolve(
|
78
|
+
bastion_host: system_configuration_attributes.fetch(:bastion_host, ""),
|
79
|
+
bastion_host_output: system_configuration_attributes.fetch(:bastion_host_output, ""),
|
80
|
+
) do |bastion_host:|
|
81
|
+
options.store :bastion_host, bastion_host
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
# InSpecRunner is the class of objects which act as interfaces to the InSpec gem.
|
23
|
+
class InSpecRunner
|
24
|
+
class << self
|
25
|
+
# .logger= sets the logger for all InSpec processes.
|
26
|
+
#
|
27
|
+
# The logdev of the logger is extended to conform to interface expected by InSpec.
|
28
|
+
#
|
29
|
+
# @param logger [Kitchen::Logger] the logger to use.
|
30
|
+
# @return [Kitchen::Logger] the logger.
|
31
|
+
def logger=(logger)
|
32
|
+
logger.logdev.define_singleton_method :filename do
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
::Inspec::Log.logger = logger
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# #exec executes InSpec.
|
41
|
+
#
|
42
|
+
# @raise [Kitchen::TransientFailure] if the execution of InSpec fails.
|
43
|
+
# @return [self]
|
44
|
+
def exec
|
45
|
+
run do |exit_code:|
|
46
|
+
if 0 != exit_code
|
47
|
+
raise ::Kitchen::TransientFailure, "#{action} failed due to a non-zero exit code of #{exit_code}."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
# #initialize prepares a new instance of the class.
|
55
|
+
#
|
56
|
+
# @param options [Hash] options to configure the runner.
|
57
|
+
# @param profile_locations [Array<String>] a list of pathnames of profiles.
|
58
|
+
# @return [Kitchen::Terraform::InSpecRunner]
|
59
|
+
def initialize(options:, profile_locations:)
|
60
|
+
self.host = options.fetch :host do
|
61
|
+
""
|
62
|
+
end
|
63
|
+
self.runner = ::Inspec::Runner.new options.merge logger: ::Inspec::Log.logger
|
64
|
+
profile_locations.each do |profile_location|
|
65
|
+
runner.add_target profile_location
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
attr_accessor :host, :runner
|
72
|
+
|
73
|
+
def action
|
74
|
+
if host.empty?
|
75
|
+
"Running InSpec"
|
76
|
+
else
|
77
|
+
"Running InSpec against the '#{host}' host"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def run
|
82
|
+
yield exit_code: runner.run
|
83
|
+
rescue => error
|
84
|
+
raise ::Kitchen::TransientFailure, "#{action} failed:\n\t\t#{error.message}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, 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
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
# OutputsManager manages Terraform outputs in the Kitchen instance state.
|
22
|
+
class OutputsManager
|
23
|
+
# #initialize prepares a new instance of the class.
|
24
|
+
#
|
25
|
+
# @return [Kitchen::Terraform::OutputsManager]
|
26
|
+
def initialize
|
27
|
+
self.state_key = :kitchen_terraform_outputs
|
28
|
+
end
|
29
|
+
|
30
|
+
# #load reads the Terraform outputs from the Kitchen instance state and writes them to a container.
|
31
|
+
#
|
32
|
+
# @param outputs [Hash] the container to which the Terraform outputs will be written.
|
33
|
+
# @param state [Hash] the Kitchen instance state from which the Terraform outputs will be read.
|
34
|
+
# @return [self]
|
35
|
+
def load(outputs:, state:)
|
36
|
+
outputs.replace state.fetch state_key
|
37
|
+
|
38
|
+
self
|
39
|
+
rescue ::KeyError
|
40
|
+
raise(
|
41
|
+
::Kitchen::ClientError,
|
42
|
+
"Reading the Terraform output variables from the Kitchen instance state failed due to the absence of the " \
|
43
|
+
"'#{state_key}' key. This error could indicate that the Kitchen-Terraform provisioner plugin was not used " \
|
44
|
+
"to converge the Kitchen instance."
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
# #save reads the Terraform outputs from container and writes them to the Kitchen instance state.
|
49
|
+
#
|
50
|
+
# @param outputs [Hash] the container from which the Terraform outputs will be read.
|
51
|
+
# @param state [Hash] the Kitchen instance state to which the Terraform outputs will be written.
|
52
|
+
# @return [self]
|
53
|
+
def save(outputs:, state:)
|
54
|
+
state.store state_key, outputs.dup
|
55
|
+
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
attr_accessor :state_key
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|