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,72 @@
|
|
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
|
+
# SystemBastionHostResolver is the class of objects which resolve a bastion host of a system which may be either
|
22
|
+
# dynamically obtained from a Terraform output variable or statically defined.
|
23
|
+
class SystemBastionHostResolver
|
24
|
+
# #initialize prepares a new instance of the class.
|
25
|
+
#
|
26
|
+
# @param outputs [Hash] a map of Terraform output variables.
|
27
|
+
# @return [Kitchen::Terraform::SystemBastionHostResolver]
|
28
|
+
def initialize(outputs:)
|
29
|
+
self.outputs = Hash[outputs]
|
30
|
+
end
|
31
|
+
|
32
|
+
# #resolve resolves a bastion host from either the specified Terraform output or the static value.
|
33
|
+
#
|
34
|
+
# @param bastion_host [String] a statically defined host.
|
35
|
+
# @param bastion_host_output [String] the name of the Terraform output which contains a bastion host.
|
36
|
+
# @yieldparam bastion_host [String] the bastion host.
|
37
|
+
# @raise [Kitchen::ClientError] if the specified Terraform output is not found.
|
38
|
+
# @return [self]
|
39
|
+
def resolve(bastion_host:, bastion_host_output:)
|
40
|
+
if !bastion_host.empty?
|
41
|
+
yield bastion_host: bastion_host
|
42
|
+
elsif !bastion_host_output.empty?
|
43
|
+
yield bastion_host: resolved_output(bastion_host_output: bastion_host_output).fetch(:value)
|
44
|
+
end
|
45
|
+
|
46
|
+
self
|
47
|
+
rescue ::KeyError
|
48
|
+
raise(
|
49
|
+
::Kitchen::ClientError,
|
50
|
+
"Resolving the system bastion host failed due to the absence of the 'value' key from the " \
|
51
|
+
"'#{bastion_host_output}' Terraform output of the Kitchen instance state. This error indicates that the " \
|
52
|
+
"output format of `terraform output -json` is unexpected."
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
attr_accessor :outputs
|
59
|
+
|
60
|
+
def resolved_output(bastion_host_output:)
|
61
|
+
outputs.fetch bastion_host_output.to_sym
|
62
|
+
rescue ::KeyError
|
63
|
+
raise(
|
64
|
+
::Kitchen::ClientError,
|
65
|
+
"Resolving the system bastion host failed due to the absence of the '#{bastion_host_output}' key from the " \
|
66
|
+
"Terraform outputs of the Kitchen instance state. This error indicates either that `kitchen converge` must " \
|
67
|
+
"be executed again to update the Terraform outputs or that the wrong key was provided."
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2016 New Context
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
@@ -14,31 +14,53 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require "kitchen
|
18
|
-
require "kitchen/terraform/error"
|
17
|
+
require "kitchen"
|
19
18
|
|
20
19
|
module Kitchen
|
21
20
|
module Terraform
|
22
|
-
# SystemHostsResolver is the class of objects which resolve
|
21
|
+
# SystemHostsResolver is the class of objects which resolve the hosts of a system which are contained in Terraform
|
22
|
+
# outputs.
|
23
23
|
class SystemHostsResolver
|
24
|
-
# #
|
24
|
+
# #initialize prepares a new instance of the class.
|
25
25
|
#
|
26
|
-
# @param
|
27
|
-
# @
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
# @param outputs [Hash] a map of Terraform output variables.
|
27
|
+
# @return [Kitchen::Terraform::SystemHostsResolver]
|
28
|
+
def initialize(outputs:)
|
29
|
+
self.outputs = Hash[outputs]
|
30
|
+
end
|
31
|
+
|
32
|
+
# #resolve reads the specified Terraform output and stores the value in a list of hosts.
|
33
|
+
#
|
34
|
+
# @param hosts [Array] the list of hosts.
|
35
|
+
# @param hosts_output [String] the name of the Terraform output which contains hosts.
|
36
|
+
# @raise [Kitchen::ClientError] if the specified Terraform output is not found.
|
37
|
+
# @return [self]
|
38
|
+
def resolve(hosts:, hosts_output:)
|
39
|
+
hosts.concat Array resolved_output(hosts_output: hosts_output).fetch :value
|
40
|
+
|
41
|
+
self
|
42
|
+
rescue ::KeyError
|
43
|
+
raise(
|
44
|
+
::Kitchen::ClientError,
|
45
|
+
"Resolving the system hosts failed due to the absence of the 'value' key from the '#{hosts_output}' " \
|
46
|
+
"Terraform output of the Kitchen instance state. This error indicates that the output format of " \
|
47
|
+
"`terraform output -json` is unexpected."
|
48
|
+
)
|
33
49
|
end
|
34
50
|
|
35
51
|
private
|
36
52
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
attr_accessor :outputs
|
54
|
+
|
55
|
+
def resolved_output(hosts_output:)
|
56
|
+
outputs.fetch hosts_output.to_sym
|
57
|
+
rescue ::KeyError
|
58
|
+
raise(
|
59
|
+
::Kitchen::ClientError,
|
60
|
+
"Resolving the system hosts failed due to the absence of the '#{hosts_output}' key from the Terraform " \
|
61
|
+
"outputs of the Kitchen instance state. This error indicates either that `kitchen converge` must be " \
|
62
|
+
"executed again to update the Terraform outputs or that the wrong key was provided."
|
63
|
+
)
|
42
64
|
end
|
43
65
|
end
|
44
66
|
end
|
@@ -0,0 +1,49 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# SYSTEM_INSPEC_MAP is a mapping of system configuration attribute keys to InSpec option keys.
|
20
|
+
SYSTEM_INSPEC_MAP = {
|
21
|
+
attrs: :input_file,
|
22
|
+
backend_cache: :backend_cache,
|
23
|
+
backend: :backend,
|
24
|
+
bastion_port: :bastion_port,
|
25
|
+
bastion_user: :bastion_user,
|
26
|
+
color: "color",
|
27
|
+
controls: :controls,
|
28
|
+
enable_password: :enable_password,
|
29
|
+
key_files: :key_files,
|
30
|
+
password: :password,
|
31
|
+
path: :path,
|
32
|
+
port: :port,
|
33
|
+
proxy_command: :proxy_command,
|
34
|
+
reporter: "reporter",
|
35
|
+
self_signed: :self_signed,
|
36
|
+
shell_command: :shell_command,
|
37
|
+
shell_options: :shell_options,
|
38
|
+
shell: :shell,
|
39
|
+
show_progress: :show_progress,
|
40
|
+
ssl: :ssl,
|
41
|
+
sudo_command: :sudo_command,
|
42
|
+
sudo_options: :sudo_options,
|
43
|
+
sudo_password: :sudo_password,
|
44
|
+
sudo: :sudo,
|
45
|
+
user: :user,
|
46
|
+
vendor_cache: :vendor_cache,
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# SystemsVerifier is the namespace of the classes of objects which verify systems.
|
20
|
+
module SystemsVerifier
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module SystemsVerifier
|
22
|
+
# FailFast is the class of objects which verify systems and raise rescued errors immediately.
|
23
|
+
class FailFast
|
24
|
+
# #initialize prepares a new instance of the class.
|
25
|
+
#
|
26
|
+
# @param systems [Array<::Kitchen::Terraform::System>] a list of systems to be verified.
|
27
|
+
# @return [Kitchen::Terraform::SystemsVerifier::FailFast]
|
28
|
+
def initialize(systems:)
|
29
|
+
self.systems = systems
|
30
|
+
end
|
31
|
+
|
32
|
+
# #verify verifies each system.
|
33
|
+
#
|
34
|
+
# @param outputs [Hash] a mapping of Terraform outputs.
|
35
|
+
# @param variables [Hash] a mapping of Terraform variables.
|
36
|
+
# @raise [Kitchen::TransientFailure] if verification of a system fails.
|
37
|
+
# @return [self]
|
38
|
+
def verify(outputs:, variables:)
|
39
|
+
systems.each do |system|
|
40
|
+
system.verify fail_fast: true, outputs: outputs, variables: variables
|
41
|
+
end
|
42
|
+
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_accessor :systems
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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
|
+
module SystemsVerifier
|
22
|
+
# FailSlow is the class of objects which verify systems and raise rescued errors after all systems have been
|
23
|
+
# verified.
|
24
|
+
class FailSlow
|
25
|
+
# #initialize prepares a new instance of the class.
|
26
|
+
#
|
27
|
+
# @param systems [Array<::Kitchen::Terraform::System>] a list of systems to be verified.
|
28
|
+
# @return [Kitchen::Terraform::SystemsVerifier::FailSlow]
|
29
|
+
def initialize(systems:)
|
30
|
+
self.messages = []
|
31
|
+
self.systems = systems
|
32
|
+
end
|
33
|
+
|
34
|
+
# #verify verifies each system.
|
35
|
+
#
|
36
|
+
# @param outputs [Hash] a mapping of Terraform outputs.
|
37
|
+
# @param variables [Hash] a mapping of Terraform variables.
|
38
|
+
# @raise [Kitchen::TransientFailure] if verification of a system fails.
|
39
|
+
# @return [self]
|
40
|
+
def verify(outputs:, variables:)
|
41
|
+
systems.each do |system|
|
42
|
+
verify_and_continue outputs: outputs, system: system, variables: variables
|
43
|
+
end
|
44
|
+
|
45
|
+
raise ::Kitchen::TransientFailure, messages.join("\n\n") if !messages.empty?
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_accessor :messages, :systems
|
53
|
+
|
54
|
+
def verify_and_continue(outputs:, system:, variables:)
|
55
|
+
system.verify fail_fast: false, outputs: outputs, variables: variables
|
56
|
+
rescue ::Kitchen::TransientFailure => error
|
57
|
+
messages.push error.message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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/systems_verifier/fail_fast"
|
18
|
+
require "kitchen/terraform/systems_verifier/fail_slow"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
# SystemsVerifierFactory is the class of objects which build SystemVerifiers.
|
23
|
+
class SystemsVerifierFactory
|
24
|
+
# #build creates a SystemVerifier.
|
25
|
+
#
|
26
|
+
# @param systems [Array<::Kitchen::Terraform::System>] the Systems to be verified.
|
27
|
+
# @return [Kitchen::Terraform::SystemsVerifier::FailFast, ::Kitchen::Terraform::SystemsVerifier::FailSlow] a
|
28
|
+
# SystemsVerifier.
|
29
|
+
def build(systems:)
|
30
|
+
if fail_fast
|
31
|
+
::Kitchen::Terraform::SystemsVerifier::FailFast.new systems: systems
|
32
|
+
else
|
33
|
+
::Kitchen::Terraform::SystemsVerifier::FailSlow.new systems: systems
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# #initialize prepares a new instance of the class.
|
38
|
+
#
|
39
|
+
# @param fail_fast [Boolean] a toggle to fail fast or fail slow.
|
40
|
+
# @return [Kitchen::Terraform::SystemsVerifierFactory]
|
41
|
+
def initialize(fail_fast:)
|
42
|
+
self.fail_fast = fail_fast
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
attr_accessor :fail_fast
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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/error"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
# UnsupportedClientVersionError is the class of objects which are raised when the Terraform client version is
|
22
|
+
# unsupported.
|
23
|
+
class UnsupportedClientVersionError < ::Kitchen::Terraform::Error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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
|
+
# VariablesManager manages Terraform variables in the Kitchen instance state.
|
22
|
+
class VariablesManager
|
23
|
+
# #initialize prepares a new instance of the class.
|
24
|
+
#
|
25
|
+
# @return [Kitchen::Terraform::VariablesManager]
|
26
|
+
def initialize
|
27
|
+
self.state_key = :kitchen_terraform_variables
|
28
|
+
end
|
29
|
+
|
30
|
+
# #load reads the Terraform variables from the Kitchen instance state and writes them to a container.
|
31
|
+
#
|
32
|
+
# @param variables [Hash] the container to which the Terraform variables will be written.
|
33
|
+
# @param state [Hash] the Kitchen instance state from which the Terraform variables will be read.
|
34
|
+
# @return [self]
|
35
|
+
def load(variables:, state:)
|
36
|
+
variables.replace state.fetch state_key
|
37
|
+
|
38
|
+
self
|
39
|
+
rescue ::KeyError => error
|
40
|
+
raise(
|
41
|
+
::Kitchen::ClientError,
|
42
|
+
"Reading the Terraform input 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 variables from a container and writes them to the Kitchen instance state.
|
49
|
+
#
|
50
|
+
# @param variables [Hash] the container from which the Terraform variables will be read.
|
51
|
+
# @param state [Hash] the Kitchen instance state to which the Terraform variables will be written.
|
52
|
+
# @return [self]
|
53
|
+
def save(variables:, state:)
|
54
|
+
state.store state_key, variables
|
55
|
+
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
attr_accessor :state_key
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|