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
@@ -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,27 +14,70 @@
|
|
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/
|
19
|
-
require "kitchen/terraform/
|
17
|
+
require "kitchen"
|
18
|
+
require "kitchen/terraform/unsupported_client_version_error"
|
19
|
+
require "kitchen/terraform/verify_version_rescue_strategy_factory"
|
20
|
+
require "kitchen/terraform/version_verifier"
|
20
21
|
require "rubygems"
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
23
|
+
module Kitchen
|
24
|
+
module Terraform
|
25
|
+
# VerifyVersion is the class of objects which verify the version of the Terraform client against a version
|
26
|
+
# requirement.
|
27
|
+
class VerifyVersion
|
28
|
+
# #call invokes the verification.
|
29
|
+
#
|
30
|
+
# @param command [Kitchen::Terraform::Command::Version] the version command.
|
31
|
+
# @param options [Hash] options for running the command.
|
32
|
+
# @raise [Kitchen::ActionFailed] if the verification fails.
|
33
|
+
# @return [self]
|
34
|
+
def call(command:, options:)
|
35
|
+
logger.warn start_message
|
36
|
+
run_version_and_verify command: command, options: options
|
37
|
+
logger.warn finish_message
|
38
|
+
rescue ::Kitchen::Terraform::UnsupportedClientVersionError
|
39
|
+
rescue_strategy.call
|
40
|
+
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# #initialize prepares a new instance of the class.
|
45
|
+
#
|
46
|
+
# @param config [Hash] the configuration of the driver.
|
47
|
+
# @param logger [Kitchen::Logger] a logger for logging messages.
|
48
|
+
# @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
|
49
|
+
# @option config [Boolean] :verify_version a toggle of strict or permissive verification of support for the
|
50
|
+
# version of the Terraform client.
|
51
|
+
# @return [Kitchen::Terraform::VerifyVersion]
|
52
|
+
def initialize(command_executor:, config:, logger:, version_requirement:)
|
53
|
+
self.command_executor = command_executor
|
54
|
+
self.finish_message = "Finished verifying the Terraform client version."
|
55
|
+
self.logger = logger
|
56
|
+
self.rescue_strategy = ::Kitchen::Terraform::VerifyVersionRescueStrategyFactory.new(
|
57
|
+
verify_version: config.fetch(:verify_version),
|
58
|
+
).build logger: logger
|
59
|
+
self.start_message = "Verifying the Terraform client version is in the supported interval of " \
|
60
|
+
"#{version_requirement}..."
|
61
|
+
self.version_verifier = ::Kitchen::Terraform::VersionVerifier.new version_requirement: version_requirement
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
attr_accessor(
|
67
|
+
:command_executor,
|
68
|
+
:finish_message,
|
69
|
+
:logger,
|
70
|
+
:options,
|
71
|
+
:rescue_strategy,
|
72
|
+
:start_message,
|
73
|
+
:version_verifier
|
74
|
+
)
|
75
|
+
|
76
|
+
def run_version_and_verify(command:, options:)
|
77
|
+
logger.warn "Reading the Terraform client version..."
|
78
|
+
command_executor.run command: command, options: options do |standard_output:|
|
79
|
+
logger.warn "Finished reading the Terraform client version."
|
80
|
+
version_verifier.verify version: ::Gem::Version.new(standard_output.slice(/Terraform v(\d+\.\d+\.\d+)/, 1))
|
38
81
|
end
|
39
82
|
end
|
40
83
|
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
|
+
# VerifyVersionRescueStrategy is the namespace for rescue strategies of instances of VerifyVersion.
|
20
|
+
module VerifyVersionRescueStrategy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module VerifyVersionRescueStrategy
|
22
|
+
# Permissive is the class of objects which provide a permissive rescue strategy to handle a failure to verify the
|
23
|
+
# Terraform client version.
|
24
|
+
class Permissive
|
25
|
+
# #call warns the user that the version is unsupported.
|
26
|
+
#
|
27
|
+
# @return [self]
|
28
|
+
def call
|
29
|
+
logger.warn message
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
# #initialize prepares a new instance of the class.
|
35
|
+
#
|
36
|
+
# @param logger [Kitchen::Logger] a logger to log messages.
|
37
|
+
# @return [Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive]
|
38
|
+
def initialize(logger:)
|
39
|
+
self.logger = logger
|
40
|
+
self.message = "Verifying the Terraform client version failed. Set `driver.verify_version: true` to " \
|
41
|
+
"upgrade this warning to an error."
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_accessor :logger, :message
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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/unsupported_client_version_error"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module VerifyVersionRescueStrategy
|
22
|
+
# Strict is the class of objects which provide a strict strategy rescue strategy to handle a failure to verify the
|
23
|
+
# Terraform client version.
|
24
|
+
class Strict
|
25
|
+
# #call raises an error.
|
26
|
+
#
|
27
|
+
# @raise [Kitchen::Terraform::UnsupportedClientVersionError]
|
28
|
+
# @return [void]
|
29
|
+
def call
|
30
|
+
raise ::Kitchen::Terraform::UnsupportedClientVersionError, message
|
31
|
+
end
|
32
|
+
|
33
|
+
# #initialize prepares a new instance of the class.
|
34
|
+
#
|
35
|
+
# @return [Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive]
|
36
|
+
def initialize
|
37
|
+
self.message = "Verifying the Terraform client version failed. Set `driver.verify_version: false` to " \
|
38
|
+
"downgrade this error to a warning."
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_accessor :message
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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/verify_version_rescue_strategy/permissive"
|
18
|
+
require "kitchen/terraform/verify_version_rescue_strategy/strict"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
# VerifyVersionRescueStrategyFactory is the class of objects which build rescue strategies for instances of
|
23
|
+
# VerifyVersion.
|
24
|
+
class VerifyVersionRescueStrategyFactory
|
25
|
+
# #build creates a strategy.
|
26
|
+
#
|
27
|
+
# @param logger [Kitchen::Logger] a logger to log messages.
|
28
|
+
# @return [Kitchen::Terraform::VerifyVersionRescueStrategy::Strict,
|
29
|
+
# Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive]
|
30
|
+
def build(logger:)
|
31
|
+
if verify_version
|
32
|
+
::Kitchen::Terraform::VerifyVersionRescueStrategy::Strict.new
|
33
|
+
else
|
34
|
+
::Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive.new logger: logger
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# #initialize prepares a new instance of the class.
|
39
|
+
#
|
40
|
+
# @param verify_version [Boolean] a toggle for a strict strategy or a permissive strategy.
|
41
|
+
# @return [Kitchen::Terraform::VerifyVersionRescueStrategyFactory]
|
42
|
+
def initialize(verify_version:)
|
43
|
+
self.verify_version = verify_version
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_accessor :verify_version
|
49
|
+
end
|
50
|
+
end
|
51
|
+
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.
|
@@ -15,71 +15,72 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
17
|
require "rubygems"
|
18
|
-
require "kitchen/terraform"
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
# Kitchen::Terraform::Version represents the version of the Kitchen-Terraform gem. The module can send the version to
|
22
|
+
# different containers as well as conditionally yield to blocks based on version requirements.
|
23
|
+
module Version
|
24
|
+
class << self
|
25
|
+
# assign_plugin_version assigns the version to a class which includes Kitchen::Configurable.
|
26
|
+
#
|
27
|
+
# @param configurable_class [Kitchen::Configurable] the configurable class to which the version will be assigned.
|
28
|
+
# @return [self]
|
29
|
+
def assign_plugin_version(configurable_class:)
|
30
|
+
configurable_class.plugin_version value.to_s
|
31
|
+
self
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
# assign_specification_version assigns the version to a Gem::Specification.
|
35
|
+
#
|
36
|
+
# @param specification [Gem::Specification] the specification to which the version will be assigned.
|
37
|
+
# @return [self]
|
38
|
+
def assign_specification_version(specification:)
|
39
|
+
specification.version = value
|
40
|
+
self
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
::Gem::Requirement
|
51
|
-
.new(requirement).satisfied_by? value
|
43
|
+
# if_satisfies yields control if the provided requirement is satisfied by the version.
|
44
|
+
#
|
45
|
+
# @param requirement [Gem::Requirement, ::String] the requirement to be satisfied by the version.
|
46
|
+
# @raise [Gem::Requirement::BadRequirementError] if the requirement is illformed.
|
47
|
+
# @return [self]
|
48
|
+
# @yield [] if the requirement is satisfied by the version.
|
49
|
+
def if_satisfies(requirement:)
|
50
|
+
yield if ::Gem::Requirement.new(requirement).satisfied_by? value
|
52
51
|
|
53
|
-
|
54
|
-
|
52
|
+
self
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
55
|
+
# temporarily_override overrides the current version with the version provided, yields control, and then resets the
|
56
|
+
# version.
|
57
|
+
#
|
58
|
+
# @note temporarily_override must only be used in tests to validate version flow control logic.
|
59
|
+
# @raise [ArgumentError] if the version is malformed.
|
60
|
+
# @return [self]
|
61
|
+
# @yield [] the value of the version will be overridden while control is yielded.
|
62
|
+
def temporarily_override(version:)
|
63
|
+
current_value = value
|
64
|
+
self.value = version
|
65
|
+
yield
|
66
|
+
self.value = current_value
|
67
|
+
self
|
68
|
+
end
|
70
69
|
|
71
|
-
|
70
|
+
private
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
# @api private
|
73
|
+
def value
|
74
|
+
self.value = ::Gem::Version.new "5.6.0" if not @value
|
75
|
+
@value
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
# @api private
|
79
|
+
def value=(version)
|
80
|
+
@value = ::Gem::Version.new version
|
81
|
+
self
|
82
|
+
end
|
83
|
+
end
|
83
84
|
end
|
84
85
|
end
|
85
86
|
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/version_verifier_strategy_factory"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
# VersionVerifier is the class of objects which verify a Terraform client version against a requirement.
|
22
|
+
class VersionVerifier
|
23
|
+
# #verify verifies a version against the requirement.
|
24
|
+
#
|
25
|
+
# @param version [Gem::Version] the Terraform client version.
|
26
|
+
# @raise [Kitchen::TransientFailure] if running the command fails.
|
27
|
+
# @raise [Kitchen::UserError] if the version is unsupported.
|
28
|
+
# @return [self]
|
29
|
+
def verify(version:)
|
30
|
+
version_verifier_strategy_factory.build(version: version).call
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# #initialize prepares a new instance of the class.
|
36
|
+
#
|
37
|
+
# @param version_requirement [Gem::Requirement] the requirement for version support.
|
38
|
+
# @return [Kitchen::Terraform::VersionVerifier]
|
39
|
+
def initialize(version_requirement:)
|
40
|
+
self.version_verifier_strategy_factory = ::Kitchen::Terraform::VersionVerifierStrategyFactory.new(
|
41
|
+
version_requirement: version_requirement,
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
attr_accessor :version_verifier_strategy_factory
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|