kitchen-terraform 5.1.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +48 -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 +139 -62
  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.
@@ -15,96 +15,98 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require "kitchen"
18
+ require "kitchen/terraform/raise/action_failed"
18
19
  require "kitchen/terraform/configurable"
19
- require "kitchen/terraform/error"
20
+ require "kitchen/terraform/provisioner/converge"
20
21
 
21
- # This namespace is defined by Kitchen.
22
- #
23
- # @see http://www.rubydoc.info/gems/test-kitchen/Kitchen/Provisioner
24
- module ::Kitchen::Provisioner
25
- end
22
+ module Kitchen
23
+ # This namespace is defined by Kitchen.
24
+ #
25
+ # @see http://www.rubydoc.info/gems/test-kitchen/Kitchen/Provisioner
26
+ module Provisioner
27
+ # The provisioner applies changes to the Terraform state based on the configuration of the root module.
28
+ #
29
+ # === Commands
30
+ #
31
+ # The following command-line actions are provided by the provisioner.
32
+ #
33
+ # ==== kitchen converge
34
+ #
35
+ # {include:Kitchen::Terraform::Provisioner::Converge}
36
+ #
37
+ # === Configuration Attributes
38
+ #
39
+ # The provisioner has no configuration attributes, but the +provisioner+ mapping must be declared with the plugin name
40
+ # within the {http://kitchen.ci/docs/getting-started/kitchen-yml Test Kitchen configuration file}.
41
+ #
42
+ # provisioner:
43
+ # name: terraform
44
+ #
45
+ # === Ruby Interface
46
+ #
47
+ # This class implements the interface of Kitchen::Configurable which requires the following Reek suppressions:
48
+ # :reek:MissingSafeMethod { exclude: [ finalize_config! ] }
49
+ #
50
+ # @example Describe the converge command
51
+ # kitchen help converge
52
+ # @example Converge a Test Kitchen instance
53
+ # kitchen converge default-ubuntu
54
+ # @version 2
55
+ class Terraform < ::Kitchen::Provisioner::Base
56
+ # UNSUPPORTED_BASE_ATTRIBUTES is the list of attributes inherited from
57
+ # Kitchen::Provisioner::Base which are not supported by Kitchen::Provisioner::Terraform.
58
+ UNSUPPORTED_BASE_ATTRIBUTES = [
59
+ :command_prefix,
60
+ :downloads,
61
+ :http_proxy,
62
+ :https_proxy,
63
+ :ftp_proxy,
64
+ :max_retries,
65
+ :root_path,
66
+ :retry_on_exit_code,
67
+ :sudo,
68
+ :sudo_command,
69
+ :wait_for_retry,
70
+ ]
71
+ defaults.delete_if do |key|
72
+ UNSUPPORTED_BASE_ATTRIBUTES.include? key
73
+ end
74
+ kitchen_provisioner_api_version 2
26
75
 
27
- # The provisioner utilizes the driver to apply changes to the Terraform state in order to reach the desired
28
- # configuration of the root module.
29
- #
30
- # === Commands
31
- #
32
- # The following command-line actions are provided by the provisioner.
33
- #
34
- # ==== kitchen converge
35
- #
36
- # A Test Kitchen instance is converged through the following steps.
37
- #
38
- # ===== Selecting the Test Terraform Workspace
39
- #
40
- # terraform workspace select kitchen-terraform-<instance>
41
- #
42
- # ===== Updating the Terraform Dependency Modules
43
- #
44
- # terraform get -update <directory>
45
- #
46
- # ===== Validating the Terraform Root Module
47
- #
48
- # terraform validate \
76
+ include ::Kitchen::Terraform::Configurable
49
77
 
50
- # [-no-color] \
51
- # [-var=<variables.first>...] \
52
- # [-var-file=<variable_files.first>...] \
53
- # <directory>
54
- #
55
- # ===== Applying the Terraform State Changes
56
- #
57
- # terraform apply\
58
- # -lock=<lock> \
59
- # -lock-timeout=<lock_timeout>s \
60
- # -input=false \
61
- # -auto-approve=true \
62
- # [-no-color] \
63
- # -parallelism=<parallelism> \
64
- # -refresh=true \
65
- # [-var=<variables.first>...] \
66
- # [-var-file=<variable_files.first>...] \
67
- # <directory>
68
- #
69
- # === Configuration Attributes
70
- #
71
- # The provisioner has no configuration attributes, but the +provisioner+ mapping must be declared with the plugin name
72
- # within the {http://kitchen.ci/docs/getting-started/kitchen-yml Test Kitchen configuration file}.
73
- #
74
- # provisioner:
75
- # name: terraform
76
- #
77
- # @example Describe the converge command
78
- # kitchen help converge
79
- # @example Converge a Test Kitchen instance
80
- # kitchen converge default-ubuntu
81
- # @version 2
82
- class ::Kitchen::Provisioner::Terraform < ::Kitchen::Provisioner::Base
83
- UNSUPPORTED_BASE_ATTRIBUTES = [
84
- :command_prefix,
85
- :downloads,
86
- :http_proxy,
87
- :https_proxy,
88
- :ftp_proxy,
89
- :max_retries,
90
- :root_path,
91
- :retry_on_exit_code,
92
- :sudo,
93
- :sudo_command,
94
- :wait_for_retry,
95
- ]
96
- defaults.delete_if do |key|
97
- UNSUPPORTED_BASE_ATTRIBUTES.include? key
98
- end
99
- kitchen_provisioner_api_version 2
78
+ # Converges a Test Kitchen instance.
79
+ #
80
+ # @param state [Hash] the mutable instance and provisioner state.
81
+ # @raise [Kitchen::ActionFailed] if the result of the action is a failure.
82
+ def call(state)
83
+ converge_strategy.call state: state
84
+ rescue => error
85
+ action_failed.call message: error.message
86
+ end
100
87
 
101
- include ::Kitchen::Terraform::Configurable
88
+ # #finalize_config! invokes the super implementation and then initializes the strategy.
89
+ #
90
+ # @param instance [Kitchen::Instance] an associated instance.
91
+ # @raise [Kitchen::ClientError] if the instance is nil.
92
+ # @return [self]
93
+ # @see Kitchen::Configurable#finalize_config!
94
+ def finalize_config!(instance)
95
+ super instance
96
+ self.action_failed = ::Kitchen::Terraform::Raise::ActionFailed.new logger: logger
97
+ self.converge_strategy = ::Kitchen::Terraform::Provisioner::Converge.new(
98
+ config: instance.driver.send(:config),
99
+ logger: logger,
100
+ version_requirement: version_requirement,
101
+ workspace_name: workspace_name,
102
+ )
102
103
 
103
- # Converges a Test Kitchen instance.
104
- #
105
- # @param _state [::Hash] the mutable instance and provisioner state.
106
- # @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
107
- def call(_state)
108
- instance.driver.apply
104
+ self
105
+ end
106
+
107
+ private
108
+
109
+ attr_accessor :action_failed, :converge_strategy
110
+ end
109
111
  end
110
112
  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,9 +15,8 @@
15
15
  # limitations under the License.
16
16
 
17
17
  # Dummy namespace for Test Kitchen to allow loading of Kitchen::Terraform::Version from gem specification.
18
- module ::Kitchen
19
- end
20
-
21
- # The namespace for kitchen-terraform.
22
- module ::Kitchen::Terraform
18
+ module Kitchen
19
+ # The namespace for Kitchen-Terraform.
20
+ module Terraform
21
+ end
23
22
  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.
@@ -14,8 +14,10 @@
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
-
19
- # The namespace for objects with breaking changes.
20
- module ::Kitchen::Terraform::Breaking
17
+ module Kitchen
18
+ module Terraform
19
+ # The namespace for objects with breaking changes.
20
+ module Breaking
21
+ end
22
+ end
21
23
  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.
@@ -14,8 +14,10 @@
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
-
19
- # The namespace for Terraform commands.
20
- module ::Kitchen::Terraform::Command
17
+ module Kitchen
18
+ module Terraform
19
+ # The namespace for Terraform commands.
20
+ module Command
21
+ end
22
+ end
21
23
  end
@@ -0,0 +1,87 @@
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/command_flag/color"
18
+ require "kitchen/terraform/command_flag/lock_timeout"
19
+ require "kitchen/terraform/command_flag/var_file"
20
+ require "kitchen/terraform/command_flag/var"
21
+ require "shellwords"
22
+
23
+ module Kitchen
24
+ module Terraform
25
+ module Command
26
+ # The state changes are applied by running a command like the following example:
27
+ # terraform apply\
28
+ # -lock=<lock> \
29
+ # -lock-timeout=<lock_timeout>s \
30
+ # -input=false \
31
+ # -auto-approve=true \
32
+ # [-no-color] \
33
+ # -parallelism=<parallelism> \
34
+ # -refresh=true \
35
+ # [-var=<variables.first>...] \
36
+ # [-var-file=<variable_files.first>...] \
37
+ # <directory>
38
+ class Apply
39
+ # #initialize prepares a new instance of the class.
40
+ #
41
+ # @param config [Hash] the configuration of the driver.
42
+ # @option config [Boolean] :color a toggle of colored output from the Terraform client.
43
+ # @option config [Boolean] :lock a toggle of locking for the Terraform state file.
44
+ # @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock
45
+ # on the state to be obtained during operations.
46
+ # @option config [Integer] :parallelism the number of concurrent operations to use while Terraform walks the
47
+ # resource graph.
48
+ # @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate.
49
+ # @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate.
50
+ # @return [Kitchen::Terraform::Command::Apply]
51
+ def initialize(config:)
52
+ self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
53
+ self.lock = config.fetch :lock
54
+ self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout)
55
+ self.parallelism = config.fetch :parallelism
56
+ self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files)
57
+ self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables)
58
+ end
59
+
60
+ # @return [String] the command with flags.
61
+ def to_s
62
+ "apply " \
63
+ "-auto-approve " \
64
+ "-lock=#{lock} " \
65
+ "#{lock_timeout} " \
66
+ "-input=false " \
67
+ "#{color} " \
68
+ "-parallelism=#{parallelism} " \
69
+ "-refresh=true " \
70
+ "#{var} " \
71
+ "#{var_file}"
72
+ end
73
+
74
+ private
75
+
76
+ attr_accessor(
77
+ :color,
78
+ :lock,
79
+ :lock_timeout,
80
+ :parallelism,
81
+ :var_file,
82
+ :var,
83
+ )
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2016-2019 New Context, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "kitchen/terraform/command_flag/color"
18
+ require "kitchen/terraform/command_flag/lock_timeout"
19
+ require "kitchen/terraform/command_flag/var_file"
20
+ require "kitchen/terraform/command_flag/var"
21
+ require "shellwords"
22
+
23
+ module Kitchen
24
+ module Terraform
25
+ module Command
26
+ # The state is destroyed by running a command like the following example:
27
+ # terraform destroy \
28
+ # -auto-approve \
29
+ # -lock=<lock> \
30
+ # -lock-timeout=<lock_timeout>s \
31
+ # -input=false \
32
+ # [-no-color] \
33
+ # -parallelism=<parallelism> \
34
+ # -refresh=true \
35
+ # [-var=<variables.first>...] \
36
+ # [-var-file=<variable_files.first>...] \
37
+ # <root_module_directory>
38
+ class Destroy
39
+ # #initialize prepares a new instance of the class.
40
+ #
41
+ # @param config [Hash] the configuration of the driver.
42
+ # @option config [Boolean] :color a toggle of colored output from the Terraform client.
43
+ # @option config [Boolean] :lock a toggle of locking for the Terraform state file.
44
+ # @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock
45
+ # on the state to be obtained during operations.
46
+ # @option config [Integer] :parallelism the number of concurrent operations to use while Terraform walks the
47
+ # resource graph.
48
+ # @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate.
49
+ # @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate.
50
+ # @return [Kitchen::Terraform::Command::Destroy]
51
+ def initialize(config:)
52
+ self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
53
+ self.lock = config.fetch :lock
54
+ self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout)
55
+ self.parallelism = config.fetch :parallelism
56
+ self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files)
57
+ self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables)
58
+ end
59
+
60
+ # @return [String] the command with flags.
61
+ def to_s
62
+ "destroy " \
63
+ "-auto-approve " \
64
+ "-lock=#{lock} " \
65
+ "#{lock_timeout} " \
66
+ "-input=false " \
67
+ "#{color} " \
68
+ "-parallelism=#{parallelism} " \
69
+ "-refresh=true " \
70
+ "#{var} " \
71
+ "#{var_file}"
72
+ end
73
+
74
+ private
75
+
76
+ attr_accessor(
77
+ :color,
78
+ :lock,
79
+ :lock_timeout,
80
+ :options,
81
+ :parallelism,
82
+ :var_file,
83
+ :var,
84
+ )
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,32 @@
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 "shellwords"
18
+
19
+ module Kitchen
20
+ module Terraform
21
+ module Command
22
+ # The dependency modules are updated by running a command like the following example:
23
+ # terraform get -update <directory>
24
+ class Get
25
+ # @return [String] the command with flags.
26
+ def to_s
27
+ "get -update"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end