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.
Files changed (111) 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 +37 -173
  5. data/lib/kitchen/driver/terraform.rb +196 -514
  6. data/lib/kitchen/provisioner/terraform.rb +88 -86
  7. data/lib/kitchen/terraform.rb +5 -6
  8. data/lib/kitchen/terraform/breaking.rb +7 -5
  9. data/lib/kitchen/terraform/command.rb +7 -5
  10. data/lib/kitchen/terraform/command/apply.rb +87 -0
  11. data/lib/kitchen/terraform/command/destroy.rb +88 -0
  12. data/lib/kitchen/terraform/command/get.rb +32 -0
  13. data/lib/kitchen/terraform/command/init.rb +102 -0
  14. data/lib/kitchen/terraform/command/output.rb +11 -50
  15. data/lib/kitchen/terraform/command/validate.rb +63 -0
  16. data/lib/kitchen/terraform/command/version.rb +5 -42
  17. data/lib/kitchen/terraform/command/workspace_delete.rb +41 -0
  18. data/lib/kitchen/terraform/command/workspace_new.rb +43 -0
  19. data/lib/kitchen/terraform/command/workspace_select.rb +43 -0
  20. data/lib/kitchen/terraform/command_executor.rb +60 -0
  21. data/lib/kitchen/terraform/command_flag.rb +23 -0
  22. data/lib/kitchen/terraform/command_flag/backend_config.rb +43 -0
  23. data/lib/kitchen/terraform/command_flag/color.rb +45 -0
  24. data/lib/kitchen/terraform/command_flag/lock_timeout.rb +42 -0
  25. data/lib/kitchen/terraform/command_flag/plugin_dir.rb +47 -0
  26. data/lib/kitchen/terraform/command_flag/upgrade.rb +45 -0
  27. data/lib/kitchen/terraform/command_flag/var.rb +43 -0
  28. data/lib/kitchen/terraform/command_flag/var_file.rb +45 -0
  29. data/lib/kitchen/terraform/config_attribute.rb +58 -55
  30. data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +1 -1
  31. data/lib/kitchen/terraform/config_attribute/client.rb +10 -3
  32. data/lib/kitchen/terraform/config_attribute/color.rb +1 -1
  33. data/lib/kitchen/terraform/config_attribute/command_timeout.rb +1 -1
  34. data/lib/kitchen/terraform/config_attribute/fail_fast.rb +1 -1
  35. data/lib/kitchen/terraform/config_attribute/lock.rb +1 -1
  36. data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +1 -1
  37. data/lib/kitchen/terraform/config_attribute/parallelism.rb +1 -1
  38. data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +3 -3
  39. data/lib/kitchen/terraform/config_attribute/root_module_directory.rb +4 -4
  40. data/lib/kitchen/terraform/config_attribute/systems.rb +1 -1
  41. data/lib/kitchen/terraform/config_attribute/variable_files.rb +4 -4
  42. data/lib/kitchen/terraform/config_attribute/variables.rb +1 -1
  43. data/lib/kitchen/terraform/config_attribute/verify_version.rb +2 -2
  44. data/lib/kitchen/terraform/config_attribute_cacher.rb +27 -25
  45. data/lib/kitchen/terraform/config_attribute_definer.rb +37 -43
  46. data/lib/kitchen/terraform/config_attribute_type.rb +7 -5
  47. data/lib/kitchen/terraform/config_attribute_type/hash_of_symbols_and_strings.rb +32 -27
  48. data/lib/kitchen/terraform/config_attribute_type/integer.rb +4 -4
  49. data/lib/kitchen/terraform/config_predicates.rb +7 -5
  50. data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +6 -6
  51. data/lib/kitchen/terraform/config_schemas.rb +7 -5
  52. data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +20 -13
  53. data/lib/kitchen/terraform/config_schemas/boolean.rb +16 -9
  54. data/lib/kitchen/terraform/config_schemas/optional_string.rb +20 -13
  55. data/lib/kitchen/terraform/config_schemas/string.rb +13 -7
  56. data/lib/kitchen/terraform/config_schemas/system.rb +38 -16
  57. data/lib/kitchen/terraform/config_schemas/systems.rb +5 -2
  58. data/lib/kitchen/terraform/configurable.rb +41 -21
  59. data/lib/kitchen/terraform/debug_logger.rb +1 -1
  60. data/lib/kitchen/terraform/deprecating.rb +7 -5
  61. data/lib/kitchen/terraform/driver.rb +23 -0
  62. data/lib/kitchen/terraform/driver/create.rb +120 -0
  63. data/lib/kitchen/terraform/driver/destroy.rb +169 -0
  64. data/lib/kitchen/terraform/error.rb +7 -5
  65. data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +30 -27
  66. data/lib/kitchen/terraform/inspec.rb +3 -57
  67. data/lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb +59 -0
  68. data/lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb +69 -0
  69. data/lib/kitchen/terraform/inspec/without_hosts.rb +52 -0
  70. data/lib/kitchen/terraform/inspec_factory.rb +68 -0
  71. data/lib/kitchen/terraform/inspec_options_factory.rb +86 -0
  72. data/lib/kitchen/terraform/inspec_runner.rb +88 -0
  73. data/lib/kitchen/terraform/outputs_manager.rb +64 -0
  74. data/lib/kitchen/terraform/outputs_parser.rb +39 -0
  75. data/lib/kitchen/terraform/outputs_reader.rb +63 -0
  76. data/lib/kitchen/terraform/provisioner.rb +23 -0
  77. data/lib/kitchen/terraform/provisioner/converge.rb +206 -0
  78. data/lib/kitchen/terraform/raise.rb +23 -0
  79. data/lib/kitchen/terraform/raise/action_failed.rb +49 -0
  80. data/lib/kitchen/terraform/raise/client_error.rb +49 -0
  81. data/lib/kitchen/terraform/shell_out.rb +90 -59
  82. data/lib/kitchen/terraform/system.rb +63 -93
  83. data/lib/kitchen/terraform/system_attrs_inputs_resolver.rb +49 -0
  84. data/lib/kitchen/terraform/system_attrs_outputs_resolver.rb +80 -0
  85. data/lib/kitchen/terraform/system_bastion_host_resolver.rb +72 -0
  86. data/lib/kitchen/terraform/system_hosts_resolver.rb +39 -17
  87. data/lib/kitchen/terraform/system_inspec_map.rb +49 -0
  88. data/lib/kitchen/terraform/systems_verifier.rb +23 -0
  89. data/lib/kitchen/terraform/systems_verifier/fail_fast.rb +52 -0
  90. data/lib/kitchen/terraform/systems_verifier/fail_slow.rb +62 -0
  91. data/lib/kitchen/terraform/systems_verifier_factory.rb +50 -0
  92. data/lib/kitchen/terraform/unsupported_client_version_error.rb +26 -0
  93. data/lib/kitchen/terraform/variables_manager.rb +64 -0
  94. data/lib/kitchen/terraform/verify_version.rb +63 -20
  95. data/lib/kitchen/terraform/verify_version_rescue_strategy.rb +23 -0
  96. data/lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb +50 -0
  97. data/lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb +47 -0
  98. data/lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb +51 -0
  99. data/lib/kitchen/terraform/version.rb +59 -58
  100. data/lib/kitchen/terraform/version_verifier.rb +50 -0
  101. data/lib/kitchen/terraform/version_verifier_strategy.rb +25 -0
  102. data/lib/kitchen/terraform/version_verifier_strategy/supported.rb +33 -0
  103. data/lib/kitchen/terraform/version_verifier_strategy/unsupported.rb +34 -0
  104. data/lib/kitchen/terraform/version_verifier_strategy_factory.rb +50 -0
  105. data/lib/kitchen/verifier/terraform.rb +71 -62
  106. metadata +143 -80
  107. metadata.gz.sig +0 -0
  108. data/lib/kitchen/terraform/inspec_options_mapper.rb +0 -73
  109. data/lib/kitchen/terraform/inspec_with_hosts.rb +0 -50
  110. data/lib/kitchen/terraform/inspec_without_hosts.rb +0 -45
  111. 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 Services, Inc.
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/terraform"
18
- require "kitchen/terraform/command/version"
19
- require "kitchen/terraform/error"
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
- # Verifies that the output of the Terraform version command indicates a supported version of Terraform.
23
- #
24
- # Supported:: Terraform version >= 0.11.4, < 0.12.0.
25
- module ::Kitchen::Terraform::VerifyVersion
26
- class << self
27
- # Runs the function.
28
- #
29
- # @raise [::Kitchen::Terraform::Error] if the version is not supported or `terraform version` fails.
30
- # @return [void]
31
- def call
32
- ::Kitchen::Terraform::Command::Version.run do |version:|
33
- if !::Gem::Requirement.new(">= 0.11.4", "< 0.13.0").satisfied_by? version
34
- raise(
35
- ::Kitchen::Terraform::Error,
36
- "Terraform v#{version} is not supported; supported versions are in the range of >= v0.11.4, < v0.13.0"
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 Services, Inc.
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
- # Kitchen::Terraform::Version represents the version of the Kitchen-Terraform gem. The module can send the version to
21
- # different containers as well as conditionally yield to blocks based on version requirements.
22
- module ::Kitchen::Terraform::Version
23
- class << self
24
- # assign_plugin_version assigns the version to a class which includes Kitchen::Configurable.
25
- #
26
- # @param configurable_class [::Kitchen::Configurable] the configurable class to which the version will be assigned.
27
- # @return [self]
28
- def assign_plugin_version(configurable_class:)
29
- configurable_class.plugin_version value.to_s
30
- self
31
- end
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
- # assign_specification_version assigns the version to a Gem::Specification.
34
- #
35
- # @param specification [::Gem::Specification] the specification to which the version will be assigned.
36
- # @return [self]
37
- def assign_specification_version(specification:)
38
- specification.version = value
39
- self
40
- end
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
- # if_satisfies yields control if the provided requirement is satisfied by the version.
43
- #
44
- # @param requirement [::Gem::Requirement, ::String] the requirement to be satisfied by the version.
45
- # @raise [::Gem::Requirement::BadRequirementError] if the requirement is illformed.
46
- # @return [self]
47
- # @yield [] if the requirement is satisfied by the version.
48
- def if_satisfies(requirement:)
49
- yield if
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
- self
54
- end
52
+ self
53
+ end
55
54
 
56
- # temporarily_override overrides the current version with the version provided, yields control, and then resets the
57
- # version.
58
- #
59
- # @note temporarily_override must only be used in tests to validate version flow control logic.
60
- # @raise [::ArgumentError] if the version is malformed.
61
- # @return [self]
62
- # @yield [] the value of the version will be overridden while control is yielded.
63
- def temporarily_override(version:)
64
- current_value = value
65
- self.value = version
66
- yield
67
- self.value = current_value
68
- self
69
- end
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
- private
70
+ private
72
71
 
73
- # @api private
74
- def value
75
- self.value = ::Gem::Version.new "5.1.1" if not @value
76
- @value
77
- end
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
- # @api private
80
- def value=(version)
81
- @value = ::Gem::Version.new version
82
- self
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