kitchen-terraform 6.0.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kitchen-terraform might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +50 -36
- data/lib/kitchen/driver/terraform.rb +71 -31
- data/lib/kitchen/provisioner/terraform.rb +10 -23
- data/lib/kitchen/terraform/config_attribute/client.rb +18 -0
- data/lib/kitchen/terraform/config_attribute/systems.rb +14 -0
- data/lib/kitchen/terraform/config_attribute_type/hash_of_symbols_and_strings.rb +1 -1
- data/lib/kitchen/terraform/config_attribute_type/integer.rb +1 -1
- data/lib/kitchen/terraform/configurable.rb +1 -2
- data/lib/kitchen/terraform/driver/create.rb +12 -27
- data/lib/kitchen/terraform/driver/destroy.rb +15 -41
- data/lib/kitchen/terraform/outputs_reader.rb +13 -19
- data/lib/kitchen/terraform/provisioner/converge.rb +18 -39
- data/lib/kitchen/terraform/transport/connection.rb +74 -0
- data/lib/kitchen/terraform/transport.rb +23 -0
- data/lib/kitchen/terraform/verifier.rb +23 -0
- data/lib/kitchen/terraform/version.rb +1 -1
- data/lib/kitchen/transport/terraform.rb +137 -0
- data/lib/kitchen/verifier/terraform.rb +11 -3
- data.tar.gz.sig +0 -0
- metadata +39 -75
- metadata.gz.sig +0 -0
- data/lib/kitchen/terraform/command_executor.rb +0 -58
- data/lib/kitchen/terraform/shell_out.rb +0 -114
@@ -15,7 +15,7 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
17
|
require "kitchen"
|
18
|
-
require "kitchen/
|
18
|
+
require "kitchen/shell_out"
|
19
19
|
require "kitchen/terraform/command/destroy"
|
20
20
|
require "kitchen/terraform/command/init_factory"
|
21
21
|
require "kitchen/terraform/command/version"
|
@@ -60,7 +60,7 @@ module Kitchen
|
|
60
60
|
class Destroy
|
61
61
|
# #call executes the action.
|
62
62
|
#
|
63
|
-
# @raise [Kitchen::
|
63
|
+
# @raise [Kitchen::StandardError] if a command fails.
|
64
64
|
# @return [self]
|
65
65
|
def call
|
66
66
|
read_client_version
|
@@ -73,19 +73,16 @@ module Kitchen
|
|
73
73
|
# #initialize prepares a new instance of the class.
|
74
74
|
#
|
75
75
|
# @param config [Hash] the configuration of the driver.
|
76
|
+
# @param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
|
76
77
|
# @param logger [Kitchen::Logger] a logger for logging messages.
|
77
78
|
# @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
|
78
79
|
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
79
80
|
# @return [Kitchen::Terraform::Driver::Destroy]
|
80
|
-
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
81
|
+
def initialize(config:, connection:, logger:, version_requirement:, workspace_name:)
|
81
82
|
self.complete_config = config.to_hash.merge upgrade_during_init: false, workspace_name: workspace_name
|
83
|
+
self.connection = connection
|
82
84
|
self.client_version = ::Gem::Version.new "0.0.0"
|
83
|
-
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
84
|
-
client: complete_config.fetch(:client),
|
85
|
-
logger: logger,
|
86
|
-
)
|
87
85
|
self.logger = logger
|
88
|
-
define_options
|
89
86
|
self.workspace_name = workspace_name
|
90
87
|
self.destroy = ::Kitchen::Terraform::Command::Destroy.new config: complete_config
|
91
88
|
self.workspace_delete_test = ::Kitchen::Terraform::Command::WorkspaceDelete.new config: complete_config
|
@@ -106,13 +103,11 @@ module Kitchen
|
|
106
103
|
|
107
104
|
attr_accessor(
|
108
105
|
:client_version,
|
109
|
-
:command_executor,
|
110
106
|
:complete_config,
|
111
|
-
:
|
107
|
+
:connection,
|
112
108
|
:destroy,
|
113
109
|
:init,
|
114
110
|
:logger,
|
115
|
-
:options,
|
116
111
|
:verify_version,
|
117
112
|
:version,
|
118
113
|
:workspace_delete_test,
|
@@ -124,32 +119,19 @@ module Kitchen
|
|
124
119
|
|
125
120
|
def create_test_workspace
|
126
121
|
logger.warn "Creating the #{workspace_name} Terraform workspace..."
|
127
|
-
|
128
|
-
end
|
122
|
+
connection.execute workspace_new_test
|
129
123
|
logger.warn "Finished creating the #{workspace_name} Terraform workspace."
|
130
124
|
end
|
131
125
|
|
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
|
-
|
142
126
|
def destroy_infrastructure
|
143
127
|
logger.warn "Destroying the Terraform-managed infrastructure..."
|
144
|
-
|
145
|
-
end
|
128
|
+
connection.execute destroy
|
146
129
|
logger.warn "Finished destroying the Terraform-managed infrastructure."
|
147
130
|
end
|
148
131
|
|
149
132
|
def delete_test_workspace
|
150
133
|
logger.warn "Deleting the #{workspace_name} Terraform workspace..."
|
151
|
-
|
152
|
-
end
|
134
|
+
connection.execute workspace_delete_test
|
153
135
|
logger.warn "Finished deleting the #{workspace_name} Terraform workspace."
|
154
136
|
end
|
155
137
|
|
@@ -163,36 +145,28 @@ module Kitchen
|
|
163
145
|
|
164
146
|
def initialize_directory
|
165
147
|
logger.warn "Initializing the Terraform working directory..."
|
166
|
-
|
167
|
-
|
168
|
-
.build(config: complete_config),
|
169
|
-
options: options,
|
170
|
-
) do |standard_output|
|
171
|
-
end
|
148
|
+
connection.execute ::Kitchen::Terraform::Command::InitFactory.new(version: client_version)
|
149
|
+
.build(config: complete_config)
|
172
150
|
logger.warn "Finished initializing the Terraform working directory."
|
173
151
|
end
|
174
152
|
|
175
153
|
def read_client_version
|
176
154
|
logger.warn "Reading the Terraform client version..."
|
177
|
-
|
178
|
-
self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
179
|
-
end
|
155
|
+
self.client_version = ::Gem::Version.new connection.execute(version).slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
180
156
|
logger.warn "Finished reading the Terraform client version."
|
181
157
|
end
|
182
158
|
|
183
159
|
def select_default_workspace
|
184
160
|
logger.warn "Selecting the default Terraform workspace..."
|
185
|
-
|
186
|
-
end
|
161
|
+
connection.execute workspace_select_default
|
187
162
|
logger.warn "Finished selecting the default Terraform workspace."
|
188
163
|
end
|
189
164
|
|
190
165
|
def select_or_create_test_workspace
|
191
166
|
logger.warn "Selecting the #{workspace_name} Terraform workspace..."
|
192
|
-
|
193
|
-
end
|
167
|
+
connection.execute workspace_select_test
|
194
168
|
logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
|
195
|
-
rescue ::Kitchen::
|
169
|
+
rescue ::Kitchen::ShellOut::ShellCommandFailed
|
196
170
|
create_test_workspace
|
197
171
|
end
|
198
172
|
end
|
@@ -26,38 +26,32 @@ module Kitchen
|
|
26
26
|
# @raise [Kitchen::TransientFailure] if running the output command fails.
|
27
27
|
# @yieldparam json_outputs [String] the output variables as a string of JSON.
|
28
28
|
# @return [self]
|
29
|
-
def read(command
|
30
|
-
|
31
|
-
|
29
|
+
def read(command:)
|
30
|
+
json_outputs = "{}"
|
31
|
+
|
32
|
+
begin
|
33
|
+
json_outputs = connection.execute command
|
34
|
+
rescue ::Kitchen::StandardError => error
|
35
|
+
no_outputs_defined.match ::Regexp.escape error.original.to_s or raise ::Kitchen::TransientFailure, error.message
|
32
36
|
end
|
33
37
|
|
38
|
+
yield json_outputs: json_outputs
|
39
|
+
|
34
40
|
self
|
35
41
|
end
|
36
42
|
|
37
43
|
# #initialize prepares a new instance of the class.
|
38
44
|
#
|
39
|
-
# @param
|
45
|
+
# @param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
|
40
46
|
# @return [Kitchen::Terraform::OutputsReader]
|
41
|
-
def initialize(
|
42
|
-
self.
|
47
|
+
def initialize(connection:)
|
48
|
+
self.connection = connection
|
43
49
|
self.no_outputs_defined = /no\\ outputs\\ defined/
|
44
50
|
end
|
45
51
|
|
46
52
|
private
|
47
53
|
|
48
|
-
attr_accessor :
|
49
|
-
|
50
|
-
def run(command:, options:)
|
51
|
-
command_executor.run command: command, options: options do |standard_output|
|
52
|
-
yield json_outputs: standard_output
|
53
|
-
end
|
54
|
-
rescue ::Kitchen::TransientFailure => error
|
55
|
-
if no_outputs_defined.match ::Regexp.escape error.original.to_s
|
56
|
-
yield json_outputs: "{}"
|
57
|
-
else
|
58
|
-
raise error
|
59
|
-
end
|
60
|
-
end
|
54
|
+
attr_accessor :connection, :no_outputs_defined
|
61
55
|
end
|
62
56
|
end
|
63
57
|
end
|
@@ -15,7 +15,6 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
17
|
require "kitchen"
|
18
|
-
require "kitchen/terraform/command_executor"
|
19
18
|
require "kitchen/terraform/command/apply"
|
20
19
|
require "kitchen/terraform/command/get"
|
21
20
|
require "kitchen/terraform/command/output"
|
@@ -78,26 +77,22 @@ module Kitchen
|
|
78
77
|
# #initialize prepares a new instance of the class.
|
79
78
|
#
|
80
79
|
# @param config [Hash] the configuration of the driver.
|
80
|
+
# @param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
|
81
|
+
# @param debug_connection [Kitchen::Terraform::Transport::Connection] a Terraform connection that logs at the
|
82
|
+
# debug level.
|
81
83
|
# @param logger [Kitchen::Logger] a logger for logging messages.
|
82
84
|
# @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
|
83
85
|
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
84
86
|
# @return [Kitchen::Terraform::Driver::Converge]
|
85
|
-
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
87
|
+
def initialize(config:, connection:, debug_connection:, logger:, version_requirement:, workspace_name:)
|
86
88
|
self.complete_config = config.to_hash.merge workspace_name: workspace_name
|
87
|
-
client = complete_config.fetch :client
|
88
89
|
self.client_version = ::Gem::Version.new "0.0.0"
|
89
|
-
self.
|
90
|
-
|
91
|
-
logger: logger,
|
92
|
-
)
|
90
|
+
self.connection = connection
|
91
|
+
self.debug_connection = debug_connection
|
93
92
|
self.logger = logger
|
94
|
-
self.options = {
|
95
|
-
cwd: complete_config.fetch(:root_module_directory),
|
96
|
-
timeout: complete_config.fetch(:command_timeout),
|
97
|
-
}
|
98
93
|
self.workspace_name = workspace_name
|
99
94
|
initialize_commands
|
100
|
-
initialize_outputs_handlers
|
95
|
+
initialize_outputs_handlers
|
101
96
|
self.variables = complete_config.fetch :variables
|
102
97
|
self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
|
103
98
|
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
@@ -110,13 +105,12 @@ module Kitchen
|
|
110
105
|
private
|
111
106
|
|
112
107
|
attr_accessor(
|
113
|
-
:apply,
|
114
108
|
:client_version,
|
115
|
-
:command_executor,
|
116
109
|
:complete_config,
|
110
|
+
:connection,
|
111
|
+
:debug_connection,
|
117
112
|
:get,
|
118
113
|
:logger,
|
119
|
-
:options,
|
120
114
|
:output,
|
121
115
|
:outputs_manager,
|
122
116
|
:outputs_parser,
|
@@ -131,15 +125,13 @@ module Kitchen
|
|
131
125
|
|
132
126
|
def build_infrastructure
|
133
127
|
logger.warn "Building the infrastructure based on the Terraform configuration..."
|
134
|
-
|
135
|
-
end
|
128
|
+
connection.execute ::Kitchen::Terraform::Command::Apply.new config: complete_config
|
136
129
|
logger.warn "Finished building the infrastructure based on the Terraform configuration."
|
137
130
|
end
|
138
131
|
|
139
132
|
def download_modules
|
140
133
|
logger.warn "Downloading the modules needed for the Terraform configuration..."
|
141
|
-
|
142
|
-
end
|
134
|
+
connection.execute get
|
143
135
|
logger.warn "Finished downloading the modules needed for the Terraform configuration."
|
144
136
|
end
|
145
137
|
|
@@ -151,22 +143,16 @@ module Kitchen
|
|
151
143
|
end
|
152
144
|
|
153
145
|
def initialize_commands
|
154
|
-
self.apply = ::Kitchen::Terraform::Command::Apply.new config: complete_config
|
155
146
|
self.get = ::Kitchen::Terraform::Command::Get.new
|
156
147
|
self.output = ::Kitchen::Terraform::Command::Output.new
|
157
148
|
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
|
158
149
|
self.version = ::Kitchen::Terraform::Command::Version.new
|
159
150
|
end
|
160
151
|
|
161
|
-
def initialize_outputs_handlers
|
152
|
+
def initialize_outputs_handlers
|
162
153
|
self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
|
163
154
|
self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
|
164
|
-
self.outputs_reader = ::Kitchen::Terraform::OutputsReader.new
|
165
|
-
command_executor: ::Kitchen::Terraform::CommandExecutor.new(
|
166
|
-
client: client,
|
167
|
-
logger: ::Kitchen::Terraform::DebugLogger.new(logger),
|
168
|
-
),
|
169
|
-
)
|
155
|
+
self.outputs_reader = ::Kitchen::Terraform::OutputsReader.new connection: debug_connection
|
170
156
|
end
|
171
157
|
|
172
158
|
def parse_outputs(json_outputs:)
|
@@ -180,7 +166,7 @@ module Kitchen
|
|
180
166
|
|
181
167
|
def read_and_parse_outputs(&block)
|
182
168
|
logger.warn "Reading the output variables from the Terraform state..."
|
183
|
-
outputs_reader.read command: output
|
169
|
+
outputs_reader.read command: output do |json_outputs:|
|
184
170
|
logger.warn "Finished reading the output variables from the Terraform state."
|
185
171
|
|
186
172
|
parse_outputs json_outputs: json_outputs, &block
|
@@ -189,9 +175,7 @@ module Kitchen
|
|
189
175
|
|
190
176
|
def read_client_version
|
191
177
|
logger.warn "Reading the Terraform client version..."
|
192
|
-
|
193
|
-
self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
194
|
-
end
|
178
|
+
self.client_version = ::Gem::Version.new connection.execute(version).slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
195
179
|
logger.warn "Finished reading the Terraform client version."
|
196
180
|
end
|
197
181
|
|
@@ -212,19 +196,14 @@ module Kitchen
|
|
212
196
|
|
213
197
|
def select_workspace
|
214
198
|
logger.warn "Selecting the #{workspace_name} Terraform workspace..."
|
215
|
-
|
216
|
-
end
|
199
|
+
connection.execute workspace_select
|
217
200
|
logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
|
218
201
|
end
|
219
202
|
|
220
203
|
def validate_files
|
221
204
|
logger.warn "Validating the Terraform configuration files..."
|
222
|
-
|
223
|
-
|
224
|
-
.build(config: complete_config),
|
225
|
-
options: options,
|
226
|
-
) do |standard_output|
|
227
|
-
end
|
205
|
+
connection.execute ::Kitchen::Terraform::Command::ValidateFactory.new(version: client_version)
|
206
|
+
.build(config: complete_config)
|
228
207
|
logger.warn "Finished validating the Terraform configuration files."
|
229
208
|
end
|
230
209
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2021 Copado NCS LLC
|
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/transport/exec"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module Transport
|
22
|
+
# Terraform commands are run by shelling out and using the
|
23
|
+
# {https://www.terraform.io/docs/commands/index.html command-line interface}.
|
24
|
+
#
|
25
|
+
# The shell out environment includes the TF_IN_AUTOMATION environment variable as specified by the
|
26
|
+
# {https://www.terraform.io/guides/running-terraform-in-automation.html#controlling-terraform-output-in-automation Running Terraform in Automation guide}.
|
27
|
+
class Connection < ::Kitchen::Transport::Exec::Connection
|
28
|
+
# #execute executes a Terraform CLI command on the local host.
|
29
|
+
#
|
30
|
+
# @param command [String] the Terraform command to be executed locally.
|
31
|
+
# @return [String] the standard output of the command.
|
32
|
+
# @raise [Kitchen::Transport::TransportFailed] if the command does not exit successfully.
|
33
|
+
def execute(command)
|
34
|
+
super "#{client} #{command}"
|
35
|
+
|
36
|
+
stdout
|
37
|
+
end
|
38
|
+
|
39
|
+
# #run_command executes a command in a subshell on the local running system.
|
40
|
+
#
|
41
|
+
# @param command [String] the command to be executed locally.
|
42
|
+
# @param options [Hash] additional configuration of the command.
|
43
|
+
# @return [String] the standard output of the command.
|
44
|
+
# @raise [Kitchen::ShellOut::ShellCommandFailed] if the command fails.
|
45
|
+
# @raise [Kitchen::StandardError] for all other unexpected exceptions.
|
46
|
+
def run_command(command, options = {})
|
47
|
+
self.stdout = super command, options.merge(
|
48
|
+
cwd: root_module_directory,
|
49
|
+
environment: environment.merge("LC_ALL" => nil, "TF_IN_AUTOMATION" => "true"),
|
50
|
+
timeout: command_timeout,
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_accessor :client, :command_timeout, :environment, :options, :root_module_directory, :stdout
|
57
|
+
|
58
|
+
# #init_options initializes incoming options for use by the object.
|
59
|
+
#
|
60
|
+
# @param options [Hash] configuration options.
|
61
|
+
# @return [void]
|
62
|
+
# @api private
|
63
|
+
def init_options(options)
|
64
|
+
super
|
65
|
+
|
66
|
+
self.client = options.delete :client
|
67
|
+
self.command_timeout = options.delete :command_timeout
|
68
|
+
self.environment = options.delete(:environment) || {}
|
69
|
+
self.root_module_directory = options.delete :root_module_directory
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2021 Copado NCS LLC
|
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
|
+
# Transport is the namespace for transport strategies.
|
20
|
+
module Transport
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2021 Copado NCS LLC
|
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
|
+
# Verifier is the namespace for verifier strategies.
|
20
|
+
module Verifier
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2021 Copado NCS LLC
|
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/config_attribute/client"
|
18
|
+
require "kitchen/terraform/config_attribute/command_timeout"
|
19
|
+
require "kitchen/terraform/config_attribute/root_module_directory"
|
20
|
+
require "kitchen/terraform/configurable"
|
21
|
+
require "kitchen/terraform/transport/connection"
|
22
|
+
require "kitchen/transport/exec"
|
23
|
+
|
24
|
+
module Kitchen
|
25
|
+
# This namespace is defined by Kitchen.
|
26
|
+
#
|
27
|
+
# @see http://www.rubydoc.info/gems/test-kitchen/Kitchen/Transport
|
28
|
+
module Transport
|
29
|
+
# The Terraform transport is responsible for the integration with the
|
30
|
+
# {https://developer.hashicorp.com/terraform/cli/commands Terraform CLI}.
|
31
|
+
#
|
32
|
+
# === Configuration Attributes
|
33
|
+
#
|
34
|
+
# The configuration attributes of the transport control the behaviour of the Terraform commands that are run.
|
35
|
+
# Within the
|
36
|
+
# {http://kitchen.ci/docs/getting-started/kitchen-yml Test Kitchen configuration file}, these attributes must be
|
37
|
+
# declared in the +transport+ mapping along with the plugin name.
|
38
|
+
#
|
39
|
+
# transport:
|
40
|
+
# name: terraform
|
41
|
+
# a_configuration_attribute: some value
|
42
|
+
#
|
43
|
+
# ==== client
|
44
|
+
#
|
45
|
+
# {include:Kitchen::Terraform::ConfigAttribute::Client}
|
46
|
+
#
|
47
|
+
# ==== command_timeout
|
48
|
+
#
|
49
|
+
# {include:Kitchen::Terraform::ConfigAttribute::CommandTimeout}
|
50
|
+
#
|
51
|
+
# ==== root_module_directory
|
52
|
+
#
|
53
|
+
# {include:Kitchen::Terraform::ConfigAttribute::RootModuleDirectory}
|
54
|
+
#
|
55
|
+
# === Ruby Interface
|
56
|
+
#
|
57
|
+
# This class implements the interface of Kitchen::Configurable which requires the following Reek suppressions:
|
58
|
+
# :reek:MissingSafeMethod { exclude: [ finalize_config! ] }
|
59
|
+
#
|
60
|
+
# @version 2
|
61
|
+
class Terraform < ::Kitchen::Transport::Exec
|
62
|
+
kitchen_transport_api_version 2
|
63
|
+
|
64
|
+
include ::Kitchen::Terraform::ConfigAttribute::Client
|
65
|
+
|
66
|
+
include ::Kitchen::Terraform::ConfigAttribute::CommandTimeout
|
67
|
+
|
68
|
+
include ::Kitchen::Terraform::ConfigAttribute::RootModuleDirectory
|
69
|
+
|
70
|
+
include ::Kitchen::Terraform::Configurable
|
71
|
+
|
72
|
+
# #connection creates a new Connection, configured by a merging of configuration
|
73
|
+
# and state data.
|
74
|
+
#
|
75
|
+
# @param state [Hash] mutable instance state.
|
76
|
+
# @return [Kitchen::Terraform::Transport::Connection] a connection for this transport.
|
77
|
+
# @raise [Kitchen::Transport::TransportFailed] if a connection could not be returned.
|
78
|
+
def connection(state, &block)
|
79
|
+
options = connection_options config.to_hash.merge state
|
80
|
+
|
81
|
+
::Kitchen::Terraform::Transport::Connection.new options, &block
|
82
|
+
end
|
83
|
+
|
84
|
+
# doctor checks the system and configuration for common errors.
|
85
|
+
#
|
86
|
+
# @param _state [Hash] the mutable Kitchen instance state.
|
87
|
+
# @return [Boolean] +true+ if any errors are found; +false+ if no errors are found.
|
88
|
+
def doctor(_state)
|
89
|
+
errors = false
|
90
|
+
|
91
|
+
methods.each do |method|
|
92
|
+
next if !method.match? /doctor_config_.*/
|
93
|
+
|
94
|
+
error = send method
|
95
|
+
errors = errors || error
|
96
|
+
end
|
97
|
+
|
98
|
+
errors
|
99
|
+
end
|
100
|
+
|
101
|
+
# #finalize_config! invokes the super implementation and then initializes the strategies.
|
102
|
+
#
|
103
|
+
# @param instance [Kitchen::Instance] an associated instance.
|
104
|
+
# @raise [Kitchen::ClientError] if the instance is nil.
|
105
|
+
# @return [self]
|
106
|
+
def finalize_config!(instance)
|
107
|
+
super instance
|
108
|
+
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
# #initialize prepares a new instance of the class.
|
113
|
+
#
|
114
|
+
# @param config [Hash] the transport configuration.
|
115
|
+
# @return [Kitchen::Transport::Terraform]
|
116
|
+
def initialize(config = {})
|
117
|
+
super config
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
# #connection_options builds the hash of options needed by the Connection object on construction.
|
123
|
+
#
|
124
|
+
# @param data [Hash] merged configuration and mutable state data.
|
125
|
+
# @return [Hash] hash of connection options.
|
126
|
+
# @api private
|
127
|
+
def connection_options(data)
|
128
|
+
opts = super
|
129
|
+
|
130
|
+
opts.merge! data
|
131
|
+
opts.merge! logger: logger
|
132
|
+
|
133
|
+
opts
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -30,7 +30,7 @@ module Kitchen
|
|
30
30
|
#
|
31
31
|
# @see https://www.rubydoc.info/gems/test-kitchen/Kitchen/Verifier
|
32
32
|
module Verifier
|
33
|
-
# The verifier utilizes
|
33
|
+
# The Terraform verifier utilizes {https://community.chef.io/tools/chef-inspec InSpec} to verify the
|
34
34
|
# behaviour and state of resources in the Terraform state.
|
35
35
|
#
|
36
36
|
# === Commands
|
@@ -118,9 +118,17 @@ module Kitchen
|
|
118
118
|
#
|
119
119
|
# @param _state [Hash] the mutable Kitchen instance state.
|
120
120
|
# @return [Boolean] +true+ if any errors are found; +false+ if no errors are found.
|
121
|
-
# @see https://github.com/test-kitchen/test-kitchen/blob/v1.21.2/lib/kitchen/verifier/base.rb#L85-L91
|
122
121
|
def doctor(_state)
|
123
|
-
false
|
122
|
+
errors = false
|
123
|
+
|
124
|
+
methods.each do |method|
|
125
|
+
next if !method.match? /doctor_config_.*/
|
126
|
+
|
127
|
+
error = send method
|
128
|
+
errors = errors || error
|
129
|
+
end
|
130
|
+
|
131
|
+
errors
|
124
132
|
end
|
125
133
|
|
126
134
|
# #initialize prepares a new instance of the class.
|
data.tar.gz.sig
CHANGED
Binary file
|