kitchen-terraform 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) 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 +3 -3
  5. data/lib/kitchen/driver/terraform.rb +363 -221
  6. data/lib/kitchen/provisioner/terraform.rb +2 -3
  7. data/lib/kitchen/terraform.rb +3 -1
  8. data/lib/kitchen/terraform/clear_directory.rb +38 -0
  9. data/lib/kitchen/terraform/client/command.rb +168 -0
  10. data/lib/kitchen/terraform/client/options.rb +275 -0
  11. data/lib/kitchen/terraform/client_version_verifier.rb +57 -0
  12. data/lib/{terraform/debug_logger.rb → kitchen/terraform/config_attribute.rb} +7 -13
  13. data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +53 -0
  14. data/lib/kitchen/terraform/config_attribute/color.rb +56 -0
  15. data/lib/kitchen/terraform/config_attribute/command_timeout.rb +52 -0
  16. data/lib/kitchen/terraform/config_attribute/directory.rb +54 -0
  17. data/lib/kitchen/terraform/config_attribute/groups.rb +96 -0
  18. data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +52 -0
  19. data/lib/kitchen/terraform/config_attribute/parallelism.rb +53 -0
  20. data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +55 -0
  21. data/lib/kitchen/terraform/config_attribute/state.rb +55 -0
  22. data/lib/kitchen/terraform/config_attribute/variable_files.rb +51 -0
  23. data/lib/kitchen/terraform/config_attribute/variables.rb +53 -0
  24. data/lib/kitchen/terraform/config_attribute/verify_plugins.rb +52 -0
  25. data/lib/kitchen/terraform/config_attribute_cacher.rb +44 -0
  26. data/lib/kitchen/terraform/config_attribute_definer.rb +66 -0
  27. data/lib/kitchen/terraform/config_predicates.rb +21 -0
  28. data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +72 -0
  29. data/lib/{terraform.rb → kitchen/terraform/config_schemas.rb} +4 -2
  30. data/lib/kitchen/terraform/config_schemas/array_of_hashes_of_symbols_and_strings.rb +47 -0
  31. data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +31 -0
  32. data/lib/kitchen/terraform/config_schemas/boolean.rb +27 -0
  33. data/lib/kitchen/terraform/config_schemas/hash_of_symbols_and_strings.rb +32 -0
  34. data/lib/kitchen/terraform/config_schemas/integer.rb +27 -0
  35. data/lib/kitchen/terraform/config_schemas/optional_string.rb +31 -0
  36. data/lib/kitchen/terraform/config_schemas/string.rb +26 -0
  37. data/lib/kitchen/terraform/configurable.rb +75 -0
  38. data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +48 -0
  39. data/lib/{terraform/project_version.rb → kitchen/terraform/version.rb} +3 -3
  40. data/lib/kitchen/verifier/terraform.rb +40 -129
  41. data/lib/kitchen/verifier/terraform/configure_inspec_runner_attributes.rb +7 -4
  42. data/lib/kitchen/verifier/terraform/enumerate_groups_and_hostnames.rb +2 -2
  43. metadata +69 -43
  44. metadata.gz.sig +0 -0
  45. data/lib/kitchen/driver/terraform/verify_client_version.rb +0 -44
  46. data/lib/kitchen/driver/terraform/workflow.rb +0 -90
  47. data/lib/kitchen/terraform/client/apply.rb +0 -38
  48. data/lib/kitchen/terraform/client/execute_command.rb +0 -56
  49. data/lib/kitchen/terraform/client/get.rb +0 -35
  50. data/lib/kitchen/terraform/client/output.rb +0 -50
  51. data/lib/kitchen/terraform/client/plan.rb +0 -42
  52. data/lib/kitchen/terraform/client/process_options.rb +0 -87
  53. data/lib/kitchen/terraform/client/validate.rb +0 -35
  54. data/lib/kitchen/terraform/client/version.rb +0 -48
  55. data/lib/kitchen/terraform/define_config_attribute.rb +0 -39
  56. data/lib/kitchen/terraform/define_integer_config_attribute.rb +0 -43
  57. data/lib/kitchen/terraform/define_string_config_attribute.rb +0 -43
  58. data/lib/terraform/configurable.rb +0 -42
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "dry/monads"
18
- require "kitchen/driver/terraform"
19
- require "kitchen/terraform/client/apply"
20
- require "kitchen/terraform/client/get"
21
- require "kitchen/terraform/client/validate"
22
- require "kitchen/terraform/create_directories"
23
-
24
- # Creates the directories to contain the root Terraform module, the Terraform execution plan, and the Terraform state,
25
- # then validates the Terraform configuration, updates any Terraform dependencies, and applies a constructive or
26
- # destructive Terraform execution plan to the Terraform state.
27
- module ::Kitchen::Driver::Terraform::Workflow
28
- extend ::Dry::Monads::Either::Mixin
29
-
30
- # Invokes the function.
31
- #
32
- # @param config [::Kitchen::Config] the configuration of the kitchen-terraform driver.
33
- # @param destroy [::TrueClass, ::FalseClass] the flag that controls constructive or destructive planning.
34
- # @param logger [#<<] a logger to receive the execution output of the Terraform Client functions.
35
- # @return [::Dry::Monads::Either] the result of the function.
36
- # @see ::Kitchen::Terraform::Client::Apply
37
- # @see ::Kitchen::Terraform::Client::Get
38
- # @see ::Kitchen::Terraform::Client::Plan
39
- # @see ::Kitchen::Terraform::Client::Validate
40
- # @see ::Kitchen::Terraform::CreateDirectories
41
- def self.call(config:, destroy: false, logger:)
42
- ::Kitchen::Terraform::CreateDirectories.call(
43
- directories: [
44
- config.fetch(:directory),
45
- ::File.dirname(config.fetch(:plan)),
46
- ::File.dirname(config.fetch(:state))
47
- ]
48
- ).fmap do |created_directories|
49
- logger.debug created_directories
50
- end.bind do
51
- ::Kitchen::Terraform::Client::Validate.call cli: config.fetch(:cli),
52
- directory: config.fetch(:directory),
53
- logger: logger,
54
- timeout: config.fetch(:command_timeout)
55
- end.bind do
56
- ::Kitchen::Terraform::Client::Get.call cli: config.fetch(:cli),
57
- logger: logger,
58
- root_module: config.fetch(:directory),
59
- timeout: config.fetch(:command_timeout)
60
- end.bind do
61
- ::Kitchen::Terraform::Client::Plan.call cli: config.fetch(:cli),
62
- logger: logger,
63
- options: {
64
- color: config.fetch(:color),
65
- destroy: destroy,
66
- out: config.fetch(:plan),
67
- parallelism: config.fetch(:parallelism),
68
- state: config.fetch(:state),
69
- var: config.fetch(:variables),
70
- var_file: config.fetch(:variable_files)
71
- },
72
- root_module: config.fetch(:directory),
73
- timeout: config.fetch(:command_timeout)
74
- end.bind do
75
- ::Kitchen::Terraform::Client::Apply.call cli: config.fetch(:cli),
76
- logger: logger,
77
- options: {
78
- color: config.fetch(:color),
79
- parallelism: config.fetch(:parallelism),
80
- state_out: config.fetch(:state)
81
- },
82
- plan: config.fetch(:plan),
83
- timeout: config.fetch(:command_timeout)
84
- end.fmap do
85
- "driver workflow was a success"
86
- end.or do |error|
87
- Left "driver workflow was a failure\n#{error}"
88
- end
89
- end
90
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "kitchen/terraform/client"
18
- require "kitchen/terraform/client/execute_command"
19
-
20
- # Applies the the pre-determined set of actions generated by a Terraform execution plan.
21
- #
22
- # @see https://www.terraform.io/docs/commands/apply.html Terraform apply command
23
- # @see https://www.terraform.io/docs/commands/plan.html Terraform plan command
24
- module ::Kitchen::Terraform::Client::Apply
25
- # Invokes the function.
26
- #
27
- # @param cli [::String] the path of the Terraform CLI to use to execute the apply command.
28
- # @param logger [#<<] a logger to receive the stdout and stderr of the apply command.
29
- # @param options [::Hash] the options for the apply command.
30
- # @param plan [::String] the path of the Terraform execution plan to apply.
31
- # @param timeout [::Integer] the maximum execution time in seconds for the apply command.
32
- # @return [::Dry::Monads::Either] the result of the function.
33
- def self.call(cli:, logger:, options:, plan:, timeout:)
34
- ::Kitchen::Terraform::Client::ExecuteCommand.call cli: cli, command: "apply", logger: logger,
35
- options: options.merge(input: false), target: plan,
36
- timeout: timeout
37
- end
38
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "dry/monads"
18
- require "kitchen/terraform/client"
19
- require "kitchen/terraform/client/process_options"
20
- require "mixlib/shellout"
21
-
22
- # Executes Terraform commands.
23
- #
24
- # @see https://www.terraform.io/docs/commands/index.html Terraform commands
25
- module ::Kitchen::Terraform::Client::ExecuteCommand
26
- extend ::Dry::Monads::Either::Mixin
27
-
28
- extend ::Dry::Monads::Try::Mixin
29
-
30
- # Invokes the function.
31
- #
32
- # @param cli [::String] the path of the Terraform CLI to use for command execution.
33
- # @param command [::String] the name of the command to execute.
34
- # @param logger [#<<] a logger to receive the stdout and stderr of the command.
35
- # @param options [::Hash] the options for the command.
36
- # @param target [::String] the target of the command.
37
- # @param timeout [::Integer] the maximum execution time in seconds for the command.
38
- # @return [::Dry::Monads::Either] the result of the function.
39
- def self.call(cli:, command:, logger:, options: {}, target: "", timeout:)
40
- ::Kitchen::Terraform::Client::ProcessOptions.call(unprocessed_options: options).fmap do |processed_options|
41
- ::Mixlib::ShellOut.new [cli, command, *processed_options, target].join(" ").strip,
42
- live_stream: logger, timeout: timeout
43
- end.bind do |shell_out|
44
- Try ::Errno::EACCES, ::Errno::ENOENT, ::Mixlib::ShellOut::CommandTimeout do
45
- shell_out.run_command
46
- end
47
- end.bind do |shell_out|
48
- Try ::Mixlib::ShellOut::ShellCommandFailed do
49
- shell_out.error!
50
- shell_out
51
- end
52
- end.to_either.fmap(&:stdout).or do |error|
53
- Left "`#{cli} #{command} #{target}` failed: '#{error}'"
54
- end
55
- end
56
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "kitchen/terraform/client"
18
- require "kitchen/terraform/client/execute_command"
19
-
20
- # Downloads and updates modules mentioned in the root Terraform module.
21
- #
22
- # @see https://www.terraform.io/docs/commands/get.html Terraform get command
23
- module ::Kitchen::Terraform::Client::Get
24
- # Invokes the function.
25
- #
26
- # @param cli [::String] the path of the Terraform CLI to use to execute the get command.
27
- # @param logger [#<<] a logger to receive the stdour and stderr of the get command.
28
- # @param root_module [::String] the path of the root module.
29
- # @param timeout [::Integer] the maximum execution time in seconds for the get command.
30
- # @return [::Dry::Monads::Either] the result of the function.
31
- def self.call(cli:, logger:, root_module:, timeout:)
32
- ::Kitchen::Terraform::Client::ExecuteCommand.call cli: cli, command: "get", logger: logger, options: {update: true},
33
- target: root_module, timeout: timeout
34
- end
35
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "dry/monads"
18
- require "json"
19
- require "kitchen/terraform/client"
20
- require "kitchen/terraform/client/execute_command"
21
-
22
- # Extracts the values of Terraform output variables from a Terraform state.
23
- #
24
- # @see https://www.terraform.io/docs/commands/output.html Terraform output command
25
- # @see https://www.terraform.io/docs/configuration/outputs.html Terraform output variables
26
- # @see https://www.terraform.io/docs/state/index.html Terraform state
27
- module ::Kitchen::Terraform::Client::Output
28
- extend ::Dry::Monads::Either::Mixin
29
-
30
- extend ::Dry::Monads::Try::Mixin
31
-
32
- # Invokes the function.
33
- #
34
- # @param cli [::String] the path of the Terraform CLI to use to execute the output command.
35
- # @param logger [#<<] a logger to receive the stdout and stderr of the output command.
36
- # @param options [::Hash] the options for the output command.
37
- # @param timeout [::Integer] the maximum execution time in seconds for the output command.
38
- # @return [::Dry::Monads::Either] the result of the function.
39
- def self.call(cli:, logger:, options:, timeout:)
40
- ::Kitchen::Terraform::Client::ExecuteCommand
41
- .call(cli: cli, command: "output", logger: logger, options: options.merge(json: true), timeout: timeout)
42
- .bind do |output|
43
- Try ::JSON::ParserError do
44
- ::JSON.parse output
45
- end
46
- end.to_either.or do |error|
47
- Left "parsing Terraform client output as JSON failed\n#{error}"
48
- end
49
- end
50
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "kitchen/terraform/client"
18
- require "kitchen/terraform/client/execute_command"
19
-
20
- # Creates a Terraform execution plan.
21
- #
22
- # @see https://www.terraform.io/docs/commands/plan.html Terraform plan command
23
- module ::Kitchen::Terraform::Client::Plan
24
- # Invokes the function.
25
- #
26
- # @param cli [::String] the path of the Terraform CLI to use to execute the plan command.
27
- # @param logger [#<<] a logger to receive the stdout and stderr of the plan command.
28
- # @param options [::Hash] the options for the plan command.
29
- # @param root_module [::String] the path of the root Terraform module.
30
- # @param timeout [::Integer] the maximum execution time in seconds for the plan command.
31
- # @return [::Dry::Monads::Either] the result of the function.
32
- def self.call(cli:, logger:, options:, root_module:, timeout:)
33
- ::Kitchen::Terraform::Client::ExecuteCommand.call cli: cli,
34
- command: "plan",
35
- logger: logger,
36
- options: options.merge(
37
- input: false
38
- ),
39
- target: root_module,
40
- timeout: timeout
41
- end
42
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "dry/monads"
18
- require "kitchen/terraform/client"
19
-
20
- # Processes Terraform Client function options in to Terraform Command-Line Interface (CLI) flags.
21
- #
22
- # @see https://www.terraform.io/docs/commands/index.html Terraform commands
23
- module ::Kitchen::Terraform::Client::ProcessOptions
24
- extend ::Dry::Monads::Either::Mixin
25
- extend ::Dry::Monads::Maybe::Mixin
26
- extend ::Dry::Monads::List::Mixin
27
- extend ::Dry::Monads::Try::Mixin
28
-
29
- OPTIONS_FLAGS = {
30
- color: lambda do |value:|
31
- "-no-color" if not value
32
- end,
33
- destroy: lambda do |value:|
34
- "-destroy" if value
35
- end,
36
- input: lambda do |value:|
37
- "-input=#{value}"
38
- end,
39
- json: lambda do |value:|
40
- "-json" if value
41
- end,
42
- out: lambda do |value:|
43
- "-out=#{value}"
44
- end,
45
- parallelism: lambda do |value:|
46
- "-parallelism=#{value}"
47
- end,
48
- state: lambda do |value:|
49
- "-state=#{value}"
50
- end,
51
- state_out: lambda do |value:|
52
- "-state-out=#{value}"
53
- end,
54
- update: lambda do |value:|
55
- "-update" if value
56
- end,
57
- var: lambda do |value:|
58
- value.map do |variable_name, variable_value|
59
- "-var='#{variable_name}=#{variable_value}'"
60
- end
61
- end,
62
- var_file: lambda do |value:|
63
- value.map do |file|
64
- "-var-file=#{file}"
65
- end
66
- end
67
- }.freeze
68
-
69
- # Invokes the function.
70
- #
71
- # @param unprocessed_options [::Hash{::Symbol => TrueClass, FalseClass, #to_s, #map}] underscore delimited option keys
72
- # associated with their values.
73
- # @return [::Dry::Monads::Either] the result of the function.
74
- def self.call(unprocessed_options:)
75
- List(unprocessed_options.to_a).fmap(&method(:Right)).typed(::Dry::Monads::Either).traverse do |member|
76
- member.bind do |key, value|
77
- Maybe(::Kitchen::Terraform::Client::ProcessOptions::OPTIONS_FLAGS[key]).bind do |processor|
78
- Right processor.call value: value
79
- end.or do
80
- Left ":#{key} is not a supported Terraform Client option"
81
- end
82
- end
83
- end.fmap do |options|
84
- options.value.flatten.compact.sort
85
- end
86
- end
87
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "kitchen/terraform/client"
18
- require "kitchen/terraform/client/execute_command"
19
-
20
- # Validates the syntax of Terraform configuration files.
21
- #
22
- # @see https://www.terraform.io/docs/commands/validate.html Terraform validate command
23
- module ::Kitchen::Terraform::Client::Validate
24
- # Invokes the function.
25
- #
26
- # @param cli [::String] the path of the Terraform CLI to use to execute the validate command.
27
- # @param directory [::String] the directory containing files to validate.
28
- # @param logger [#<<] a logger to receive the stdout and stderr of the validate command.
29
- # @param timeout [::Integer] the maximum execution time in seconds for the validate command.
30
- # @return [::Dry::Monads::Either] the result of the function.
31
- def self.call(cli:, directory:, logger:, timeout:)
32
- ::Kitchen::Terraform::Client::ExecuteCommand.call cli: cli, command: "validate", logger: logger, target: directory,
33
- timeout: timeout
34
- end
35
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2016 New Context Services, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "dry/monads"
18
- require "kitchen/terraform/client"
19
- require "kitchen/terraform/client/execute_command"
20
-
21
- # Retrieves the version of the Terraform Command-Line Interface (CLI).
22
- #
23
- # @see https://www.terraform.io/docs/commands/index.html Terraform commands
24
- module ::Kitchen::Terraform::Client::Version
25
- extend ::Dry::Monads::Either::Mixin
26
-
27
- extend ::Dry::Monads::Maybe::Mixin
28
-
29
- # Invokes the function.
30
- #
31
- # @param cli [::String] the path of the Terraform CLI to use to execute the version command.
32
- # @param logger [#<<] a logger to receive the stdout and stderr of the version command.
33
- # @param timeout [::Integer] the time in seconds to wait for the version command to finish.
34
- # @return [::Dry::Monads::Either] the result of the function.
35
- def self.call(cli:, logger:, timeout:)
36
- ::Kitchen::Terraform::Client::ExecuteCommand
37
- .call(cli: cli, command: "version", logger: logger, timeout: timeout)
38
- .bind do |output|
39
- Maybe output.slice /v(\d+\.\d+)/, 1
40
- end.bind do |major_minor_versions|
41
- Right Float major_minor_versions
42
- end.or do |error|
43
- error.nil? and Left "Terraform client version output did not match 'vX.Y'" or Left error
44
- end.or do |error|
45
- Left "Unable to parse Terraform client version output\n#{error}"
46
- end
47
- end
48
- end