kitchen-terraform 5.7.1 → 6.1.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 (117) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +21 -19
  4. data/lib/kitchen/driver/terraform.rb +1 -1
  5. data/lib/kitchen/provisioner/terraform.rb +1 -1
  6. data/lib/kitchen/terraform/breaking.rb +1 -1
  7. data/lib/kitchen/terraform/command/apply.rb +1 -1
  8. data/lib/kitchen/terraform/command/destroy.rb +1 -1
  9. data/lib/kitchen/terraform/command/get.rb +1 -1
  10. data/lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb +89 -0
  11. data/lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb +101 -0
  12. data/lib/kitchen/terraform/command/init.rb +3 -80
  13. data/lib/kitchen/terraform/command/init_factory.rb +52 -0
  14. data/lib/kitchen/terraform/command/output.rb +1 -1
  15. data/lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb +51 -0
  16. data/lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb +65 -0
  17. data/lib/kitchen/terraform/command/validate.rb +3 -41
  18. data/lib/kitchen/terraform/command/validate_factory.rb +54 -0
  19. data/lib/kitchen/terraform/command/version.rb +1 -1
  20. data/lib/kitchen/terraform/command/workspace_delete.rb +1 -1
  21. data/lib/kitchen/terraform/command/workspace_new.rb +1 -1
  22. data/lib/kitchen/terraform/command/workspace_select.rb +1 -1
  23. data/lib/kitchen/terraform/command.rb +1 -1
  24. data/lib/kitchen/terraform/command_executor.rb +3 -5
  25. data/lib/kitchen/terraform/command_flag/backend_config.rb +1 -1
  26. data/lib/kitchen/terraform/command_flag/color.rb +1 -1
  27. data/lib/kitchen/terraform/command_flag/lock_timeout.rb +1 -1
  28. data/lib/kitchen/terraform/command_flag/plugin_dir.rb +1 -1
  29. data/lib/kitchen/terraform/command_flag/upgrade.rb +2 -2
  30. data/lib/kitchen/terraform/command_flag/var.rb +1 -1
  31. data/lib/kitchen/terraform/command_flag/var_file.rb +1 -1
  32. data/lib/kitchen/terraform/command_flag.rb +1 -1
  33. data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +1 -1
  34. data/lib/kitchen/terraform/config_attribute/client.rb +3 -3
  35. data/lib/kitchen/terraform/config_attribute/color.rb +3 -3
  36. data/lib/kitchen/terraform/config_attribute/command_timeout.rb +1 -1
  37. data/lib/kitchen/terraform/config_attribute/fail_fast.rb +3 -3
  38. data/lib/kitchen/terraform/config_attribute/lock.rb +3 -3
  39. data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +1 -1
  40. data/lib/kitchen/terraform/config_attribute/parallelism.rb +1 -1
  41. data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +3 -3
  42. data/lib/kitchen/terraform/config_attribute/root_module_directory.rb +3 -3
  43. data/lib/kitchen/terraform/config_attribute/systems.rb +552 -4
  44. data/lib/kitchen/terraform/config_attribute/variable_files.rb +3 -3
  45. data/lib/kitchen/terraform/config_attribute/variables.rb +1 -1
  46. data/lib/kitchen/terraform/config_attribute/verify_version.rb +3 -3
  47. data/lib/kitchen/terraform/config_attribute.rb +1 -1
  48. data/lib/kitchen/terraform/config_attribute_cacher.rb +1 -1
  49. data/lib/kitchen/terraform/config_attribute_contract/array_of_strings.rb +30 -0
  50. data/lib/kitchen/terraform/{config_schemas → config_attribute_contract}/boolean.rb +7 -11
  51. data/lib/kitchen/terraform/config_attribute_contract/hash_of_symbols_and_strings.rb +41 -0
  52. data/lib/kitchen/terraform/{config_schemas.rb → config_attribute_contract/integer.rb} +10 -3
  53. data/lib/kitchen/terraform/config_attribute_contract/optional_string.rb +30 -0
  54. data/lib/kitchen/terraform/{config_schemas → config_attribute_contract}/string.rb +7 -9
  55. data/lib/kitchen/terraform/config_attribute_contract/systems.rb +63 -0
  56. data/lib/kitchen/terraform/{config_predicates.rb → config_attribute_contract.rb} +3 -3
  57. data/lib/kitchen/terraform/config_attribute_definer.rb +2 -2
  58. data/lib/kitchen/terraform/config_attribute_type/hash_of_symbols_and_strings.rb +9 -16
  59. data/lib/kitchen/terraform/config_attribute_type/integer.rb +27 -23
  60. data/lib/kitchen/terraform/config_attribute_type.rb +1 -1
  61. data/lib/kitchen/terraform/configurable.rb +2 -2
  62. data/lib/kitchen/terraform/debug_logger.rb +1 -1
  63. data/lib/kitchen/terraform/deprecating.rb +1 -1
  64. data/lib/kitchen/terraform/driver/create.rb +39 -16
  65. data/lib/kitchen/terraform/driver/destroy.rb +53 -21
  66. data/lib/kitchen/terraform/driver.rb +1 -1
  67. data/lib/kitchen/terraform/error.rb +1 -1
  68. data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +1 -1
  69. data/lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb +1 -1
  70. data/lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb +1 -1
  71. data/lib/kitchen/terraform/inspec/without_hosts.rb +1 -1
  72. data/lib/kitchen/terraform/inspec.rb +1 -1
  73. data/lib/kitchen/terraform/inspec_factory.rb +1 -1
  74. data/lib/kitchen/terraform/inspec_options_factory.rb +1 -1
  75. data/lib/kitchen/terraform/inspec_runner.rb +5 -4
  76. data/lib/kitchen/terraform/outputs_manager.rb +1 -1
  77. data/lib/kitchen/terraform/outputs_parser.rb +1 -1
  78. data/lib/kitchen/terraform/outputs_reader.rb +2 -2
  79. data/lib/kitchen/terraform/provisioner/converge.rb +52 -25
  80. data/lib/kitchen/terraform/provisioner.rb +1 -1
  81. data/lib/kitchen/terraform/raise/action_failed.rb +1 -1
  82. data/lib/kitchen/terraform/raise/client_error.rb +1 -1
  83. data/lib/kitchen/terraform/raise.rb +1 -1
  84. data/lib/kitchen/terraform/shell_out.rb +6 -5
  85. data/lib/kitchen/terraform/system.rb +1 -1
  86. data/lib/kitchen/terraform/system_attrs_inputs_resolver.rb +1 -1
  87. data/lib/kitchen/terraform/system_attrs_outputs_resolver.rb +1 -1
  88. data/lib/kitchen/terraform/system_bastion_host_resolver.rb +1 -1
  89. data/lib/kitchen/terraform/system_hosts_resolver.rb +1 -1
  90. data/lib/kitchen/terraform/system_inspec_map.rb +1 -1
  91. data/lib/kitchen/terraform/systems_verifier/fail_fast.rb +1 -1
  92. data/lib/kitchen/terraform/systems_verifier/fail_slow.rb +1 -1
  93. data/lib/kitchen/terraform/systems_verifier.rb +1 -1
  94. data/lib/kitchen/terraform/systems_verifier_factory.rb +1 -1
  95. data/lib/kitchen/terraform/unsupported_client_version_error.rb +1 -1
  96. data/lib/kitchen/terraform/variables_manager.rb +1 -1
  97. data/lib/kitchen/terraform/verify_version.rb +5 -17
  98. data/lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb +1 -1
  99. data/lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb +1 -1
  100. data/lib/kitchen/terraform/verify_version_rescue_strategy.rb +1 -1
  101. data/lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb +1 -1
  102. data/lib/kitchen/terraform/version.rb +2 -2
  103. data/lib/kitchen/terraform/version_verifier.rb +1 -1
  104. data/lib/kitchen/terraform/version_verifier_strategy/supported.rb +1 -1
  105. data/lib/kitchen/terraform/version_verifier_strategy/unsupported.rb +1 -1
  106. data/lib/kitchen/terraform/version_verifier_strategy.rb +1 -1
  107. data/lib/kitchen/terraform/version_verifier_strategy_factory.rb +1 -1
  108. data/lib/kitchen/terraform.rb +1 -1
  109. data/lib/kitchen/verifier/terraform.rb +1 -1
  110. data.tar.gz.sig +0 -0
  111. metadata +65 -62
  112. metadata.gz.sig +0 -0
  113. data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +0 -81
  114. data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +0 -38
  115. data/lib/kitchen/terraform/config_schemas/optional_string.rb +0 -38
  116. data/lib/kitchen/terraform/config_schemas/system.rb +0 -609
  117. data/lib/kitchen/terraform/config_schemas/systems.rb +0 -37
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -17,12 +17,13 @@
17
17
  require "kitchen"
18
18
  require "kitchen/terraform/command_executor"
19
19
  require "kitchen/terraform/command/destroy"
20
- require "kitchen/terraform/command/init"
20
+ require "kitchen/terraform/command/init_factory"
21
21
  require "kitchen/terraform/command/version"
22
22
  require "kitchen/terraform/command/workspace_delete"
23
23
  require "kitchen/terraform/command/workspace_new"
24
24
  require "kitchen/terraform/command/workspace_select"
25
25
  require "kitchen/terraform/verify_version"
26
+ require "rubygems"
26
27
 
27
28
  module Kitchen
28
29
  module Terraform
@@ -31,7 +32,13 @@ module Kitchen
31
32
  #
32
33
  # ===== Initializing the Terraform Working Directory
33
34
  #
34
- # {include:Kitchen::Terraform::Command::Init}
35
+ # ====== Terraform >= 0.15.0
36
+ #
37
+ # {include:Kitchen::Terraform::Command::Init::PostZeroFifteenZero}
38
+ #
39
+ # ====== Terraform < 0.15.0
40
+ #
41
+ # {include:Kitchen::Terraform::Command::Init::PreZeroFifteenZero}
35
42
  #
36
43
  # ===== Selecting or Creating the Test Terraform Workspace
37
44
  #
@@ -56,7 +63,8 @@ module Kitchen
56
63
  # @raise [Kitchen::TransientFailure] if a command fails.
57
64
  # @return [self]
58
65
  def call
59
- verify_version.call command: version, options: options
66
+ read_client_version
67
+ verify_version.call version: client_version
60
68
  execute_workflow
61
69
 
62
70
  self
@@ -70,25 +78,24 @@ module Kitchen
70
78
  # @param workspace_name [String] the name of the Terraform workspace to select or to create.
71
79
  # @return [Kitchen::Terraform::Driver::Destroy]
72
80
  def initialize(config:, logger:, version_requirement:, workspace_name:)
73
- hash_config = config.to_hash.merge upgrade_during_init: false, workspace_name: workspace_name
81
+ self.complete_config = config.to_hash.merge upgrade_during_init: false, workspace_name: workspace_name
82
+ self.client_version = ::Gem::Version.new "0.0.0"
74
83
  self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
75
- client: config.fetch(:client),
84
+ client: complete_config.fetch(:client),
76
85
  logger: logger,
77
86
  )
78
87
  self.logger = logger
79
- self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
88
+ define_options
80
89
  self.workspace_name = workspace_name
81
- self.destroy = ::Kitchen::Terraform::Command::Destroy.new config: config
82
- self.init = ::Kitchen::Terraform::Command::Init.new config: hash_config
83
- self.workspace_delete_test = ::Kitchen::Terraform::Command::WorkspaceDelete.new config: hash_config
84
- self.workspace_new_test = ::Kitchen::Terraform::Command::WorkspaceNew.new config: hash_config
85
- self.workspace_select_test = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
90
+ self.destroy = ::Kitchen::Terraform::Command::Destroy.new config: complete_config
91
+ self.workspace_delete_test = ::Kitchen::Terraform::Command::WorkspaceDelete.new config: complete_config
92
+ self.workspace_new_test = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
93
+ self.workspace_select_test = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
86
94
  self.workspace_select_default = ::Kitchen::Terraform::Command::WorkspaceSelect.new(
87
- config: hash_config.merge(workspace_name: "default"),
95
+ config: complete_config.merge(workspace_name: "default"),
88
96
  )
89
97
  self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
90
- command_executor: command_executor,
91
- config: config,
98
+ config: complete_config,
92
99
  logger: logger,
93
100
  version_requirement: version_requirement,
94
101
  )
@@ -98,7 +105,10 @@ module Kitchen
98
105
  private
99
106
 
100
107
  attr_accessor(
108
+ :client_version,
101
109
  :command_executor,
110
+ :complete_config,
111
+ :destroy_options,
102
112
  :destroy,
103
113
  :init,
104
114
  :logger,
@@ -114,21 +124,31 @@ module Kitchen
114
124
 
115
125
  def create_test_workspace
116
126
  logger.warn "Creating the #{workspace_name} Terraform workspace..."
117
- command_executor.run command: workspace_new_test, options: options do |standard_output:|
127
+ command_executor.run command: workspace_new_test, options: options do |standard_output|
118
128
  end
119
129
  logger.warn "Finished creating the #{workspace_name} Terraform workspace."
120
130
  end
121
131
 
132
+ def define_options
133
+ self.options = {
134
+ cwd: complete_config.fetch(:root_module_directory),
135
+ timeout: complete_config.fetch(:command_timeout),
136
+ }
137
+ self.destroy_options = options.merge(
138
+ environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "true" },
139
+ )
140
+ end
141
+
122
142
  def destroy_infrastructure
123
143
  logger.warn "Destroying the Terraform-managed infrastructure..."
124
- command_executor.run command: destroy, options: options do |standard_output:|
144
+ command_executor.run command: destroy, options: destroy_options do |standard_output|
125
145
  end
126
146
  logger.warn "Finished destroying the Terraform-managed infrastructure."
127
147
  end
128
148
 
129
149
  def delete_test_workspace
130
150
  logger.warn "Deleting the #{workspace_name} Terraform workspace..."
131
- command_executor.run command: workspace_delete_test, options: options do |standard_output:|
151
+ command_executor.run command: workspace_delete_test, options: options do |standard_output|
132
152
  end
133
153
  logger.warn "Finished deleting the #{workspace_name} Terraform workspace."
134
154
  end
@@ -143,21 +163,33 @@ module Kitchen
143
163
 
144
164
  def initialize_directory
145
165
  logger.warn "Initializing the Terraform working directory..."
146
- command_executor.run command: init, options: options do |standard_output:|
166
+ command_executor.run(
167
+ command: ::Kitchen::Terraform::Command::InitFactory.new(version: client_version)
168
+ .build(config: complete_config),
169
+ options: options,
170
+ ) do |standard_output|
147
171
  end
148
172
  logger.warn "Finished initializing the Terraform working directory."
149
173
  end
150
174
 
175
+ def read_client_version
176
+ logger.warn "Reading the Terraform client version..."
177
+ command_executor.run command: version, options: options do |standard_output|
178
+ self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
179
+ end
180
+ logger.warn "Finished reading the Terraform client version."
181
+ end
182
+
151
183
  def select_default_workspace
152
184
  logger.warn "Selecting the default Terraform workspace..."
153
- command_executor.run command: workspace_select_default, options: options do |standard_output:|
185
+ command_executor.run command: workspace_select_default, options: options do |standard_output|
154
186
  end
155
187
  logger.warn "Finished selecting the default Terraform workspace."
156
188
  end
157
189
 
158
190
  def select_or_create_test_workspace
159
191
  logger.warn "Selecting the #{workspace_name} Terraform workspace..."
160
- command_executor.run command: workspace_select_test, options: options do |standard_output:|
192
+ command_executor.run command: workspace_select_test, options: options do |standard_output|
161
193
  end
162
194
  logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
163
195
  rescue ::Kitchen::TransientFailure
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -61,9 +61,10 @@ module Kitchen
61
61
  ""
62
62
  end
63
63
 
64
- v2_loader = ::Inspec::Plugin::V2::Loader.new
65
- v2_loader.load_all
66
- v2_loader.exit_on_load_error
64
+ ::Inspec::Plugin::V2::Loader.new.tap do |loader|
65
+ loader.load_all
66
+ loader.exit_on_load_error
67
+ end
67
68
 
68
69
  self.runner = ::Inspec::Runner.new options.merge logger: ::Inspec::Log.logger
69
70
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -48,7 +48,7 @@ module Kitchen
48
48
  attr_accessor :command_executor, :no_outputs_defined
49
49
 
50
50
  def run(command:, options:)
51
- command_executor.run command: command, options: options do |standard_output:|
51
+ command_executor.run command: command, options: options do |standard_output|
52
52
  yield json_outputs: standard_output
53
53
  end
54
54
  rescue ::Kitchen::TransientFailure => error
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -19,7 +19,7 @@ require "kitchen/terraform/command_executor"
19
19
  require "kitchen/terraform/command/apply"
20
20
  require "kitchen/terraform/command/get"
21
21
  require "kitchen/terraform/command/output"
22
- require "kitchen/terraform/command/validate"
22
+ require "kitchen/terraform/command/validate_factory"
23
23
  require "kitchen/terraform/command/workspace_select"
24
24
  require "kitchen/terraform/debug_logger"
25
25
  require "kitchen/terraform/outputs_manager"
@@ -28,6 +28,7 @@ require "kitchen/terraform/outputs_reader"
28
28
  require "kitchen/terraform/variables_manager"
29
29
  require "kitchen/terraform/verify_version"
30
30
  require "kitchen/terraform/version"
31
+ require "rubygems"
31
32
 
32
33
  module Kitchen
33
34
  module Terraform
@@ -44,7 +45,13 @@ module Kitchen
44
45
  #
45
46
  # ===== Validating the Terraform Root Module
46
47
  #
47
- # {include:Kitchen::Terraform::Command::Validate}
48
+ # ====== Terraform >= 0.15.0
49
+ #
50
+ # {include:Kitchen::Terraform::Command::Validate::PostZeroFifteenZero}
51
+ #
52
+ # ====== Terraform < 0.15.0
53
+ #
54
+ # {include:Kitchen::Terraform::Command::Validate::PreZeroFifteenZero}
48
55
  #
49
56
  # ===== Applying the Terraform State Changes
50
57
  #
@@ -60,7 +67,8 @@ module Kitchen
60
67
  # @raise [Kitchen::TransientFailure] if a command fails.
61
68
  # @return [self]
62
69
  def call(state:)
63
- verify_version.call command: version, options: options
70
+ read_client_version
71
+ verify_version.call version: client_version
64
72
  execute_workflow
65
73
  save_variables_and_outputs state: state
66
74
 
@@ -75,63 +83,62 @@ module Kitchen
75
83
  # @param workspace_name [String] the name of the Terraform workspace to select or to create.
76
84
  # @return [Kitchen::Terraform::Driver::Converge]
77
85
  def initialize(config:, logger:, version_requirement:, workspace_name:)
78
- client = config.fetch :client
79
- hash_config = config.to_hash.merge workspace_name: workspace_name
86
+ self.complete_config = config.to_hash.merge workspace_name: workspace_name
87
+ client = complete_config.fetch :client
88
+ self.client_version = ::Gem::Version.new "0.0.0"
80
89
  self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
81
90
  client: client,
82
91
  logger: logger,
83
92
  )
84
93
  self.logger = logger
85
- self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
94
+ self.options = {
95
+ cwd: complete_config.fetch(:root_module_directory),
96
+ timeout: complete_config.fetch(:command_timeout),
97
+ }
86
98
  self.workspace_name = workspace_name
87
- self.apply = ::Kitchen::Terraform::Command::Apply.new config: config
88
- self.get = ::Kitchen::Terraform::Command::Get.new
89
- self.output = ::Kitchen::Terraform::Command::Output.new
99
+ initialize_commands
90
100
  initialize_outputs_handlers client: client, logger: logger
91
- self.validate = ::Kitchen::Terraform::Command::Validate.new config: config
92
- self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
93
- self.variables = config.fetch :variables
101
+ self.variables = complete_config.fetch :variables
94
102
  self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
95
103
  self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
96
- command_executor: command_executor,
97
- config: config,
104
+ config: complete_config,
98
105
  logger: logger,
99
106
  version_requirement: version_requirement,
100
107
  )
101
- self.version = ::Kitchen::Terraform::Command::Version.new
102
108
  end
103
109
 
104
110
  private
105
111
 
106
112
  attr_accessor(
107
- :command_executor,
108
113
  :apply,
114
+ :client_version,
115
+ :command_executor,
116
+ :complete_config,
109
117
  :get,
110
- :output,
111
- :validate,
112
- :workspace_select,
113
118
  :logger,
114
119
  :options,
120
+ :output,
115
121
  :outputs_manager,
116
122
  :outputs_parser,
117
123
  :outputs_reader,
118
- :variables,
119
124
  :variables_manager,
125
+ :variables,
120
126
  :verify_version,
121
127
  :version,
122
128
  :workspace_name,
129
+ :workspace_select,
123
130
  )
124
131
 
125
132
  def build_infrastructure
126
133
  logger.warn "Building the infrastructure based on the Terraform configuration..."
127
- command_executor.run command: apply, options: options do |standard_output:|
134
+ command_executor.run command: apply, options: options do |standard_output|
128
135
  end
129
136
  logger.warn "Finished building the infrastructure based on the Terraform configuration."
130
137
  end
131
138
 
132
139
  def download_modules
133
140
  logger.warn "Downloading the modules needed for the Terraform configuration..."
134
- command_executor.run command: get, options: options do |standard_output:|
141
+ command_executor.run command: get, options: options do |standard_output|
135
142
  end
136
143
  logger.warn "Finished downloading the modules needed for the Terraform configuration."
137
144
  end
@@ -143,6 +150,14 @@ module Kitchen
143
150
  build_infrastructure
144
151
  end
145
152
 
153
+ def initialize_commands
154
+ self.apply = ::Kitchen::Terraform::Command::Apply.new config: complete_config
155
+ self.get = ::Kitchen::Terraform::Command::Get.new
156
+ self.output = ::Kitchen::Terraform::Command::Output.new
157
+ self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
158
+ self.version = ::Kitchen::Terraform::Command::Version.new
159
+ end
160
+
146
161
  def initialize_outputs_handlers(client:, logger:)
147
162
  self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
148
163
  self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
@@ -172,6 +187,14 @@ module Kitchen
172
187
  end
173
188
  end
174
189
 
190
+ def read_client_version
191
+ logger.warn "Reading the Terraform client version..."
192
+ command_executor.run command: version, options: options do |standard_output|
193
+ self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
194
+ end
195
+ logger.warn "Finished reading the Terraform client version."
196
+ end
197
+
175
198
  def save_outputs(parsed_outputs:, state:)
176
199
  logger.warn "Writing the output variables to the Kitchen instance state..."
177
200
  outputs_manager.save outputs: parsed_outputs, state: state
@@ -189,14 +212,18 @@ module Kitchen
189
212
 
190
213
  def select_workspace
191
214
  logger.warn "Selecting the #{workspace_name} Terraform workspace..."
192
- command_executor.run command: workspace_select, options: options do |standard_output:|
215
+ command_executor.run command: workspace_select, options: options do |standard_output|
193
216
  end
194
217
  logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
195
218
  end
196
219
 
197
220
  def validate_files
198
221
  logger.warn "Validating the Terraform configuration files..."
199
- command_executor.run command: validate, options: options do |standard_output:|
222
+ command_executor.run(
223
+ command: ::Kitchen::Terraform::Command::ValidateFactory.new(version: client_version)
224
+ .build(config: complete_config),
225
+ options: options,
226
+ ) do |standard_output|
200
227
  end
201
228
  logger.warn "Finished validating the Terraform configuration files."
202
229
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -29,16 +29,17 @@ module Kitchen
29
29
  #
30
30
  # @param command [String] the command to run.
31
31
  # @param logger [Kitchen::Logger] a logger for logging messages.
32
+ # @param options [Hash] options which adjust the execution of the command.
32
33
  # @return [Kitchen::Terraform::CommandExecutor]
33
34
  def initialize(command:, logger:, options:)
34
35
  self.command = command
35
36
  self.logger = logger
36
37
  self.shell_out = ::Mixlib::ShellOut.new(
37
38
  command,
38
- options.merge(
39
- environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "1" },
39
+ {
40
+ environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true" },
40
41
  live_stream: logger,
41
- )
42
+ }.merge(options)
42
43
  )
43
44
  end
44
45
 
@@ -50,7 +51,7 @@ module Kitchen
50
51
  def run
51
52
  execute_workflow
52
53
 
53
- yield standard_output: shell_out.stdout
54
+ yield shell_out.stdout
54
55
 
55
56
  self
56
57
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2019 New Context, Inc.
3
+ # Copyright 2016-2021 Copado NCS LLC
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.