kitchen-terraform 5.1.1 → 5.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +37 -173
- data/lib/kitchen/driver/terraform.rb +196 -514
- data/lib/kitchen/provisioner/terraform.rb +88 -86
- data/lib/kitchen/terraform.rb +5 -6
- data/lib/kitchen/terraform/breaking.rb +7 -5
- data/lib/kitchen/terraform/command.rb +7 -5
- data/lib/kitchen/terraform/command/apply.rb +87 -0
- data/lib/kitchen/terraform/command/destroy.rb +88 -0
- data/lib/kitchen/terraform/command/get.rb +32 -0
- data/lib/kitchen/terraform/command/init.rb +102 -0
- data/lib/kitchen/terraform/command/output.rb +11 -50
- data/lib/kitchen/terraform/command/validate.rb +63 -0
- data/lib/kitchen/terraform/command/version.rb +5 -42
- data/lib/kitchen/terraform/command/workspace_delete.rb +41 -0
- data/lib/kitchen/terraform/command/workspace_new.rb +43 -0
- data/lib/kitchen/terraform/command/workspace_select.rb +43 -0
- data/lib/kitchen/terraform/command_executor.rb +60 -0
- data/lib/kitchen/terraform/command_flag.rb +23 -0
- data/lib/kitchen/terraform/command_flag/backend_config.rb +43 -0
- data/lib/kitchen/terraform/command_flag/color.rb +45 -0
- data/lib/kitchen/terraform/command_flag/lock_timeout.rb +42 -0
- data/lib/kitchen/terraform/command_flag/plugin_dir.rb +47 -0
- data/lib/kitchen/terraform/command_flag/upgrade.rb +45 -0
- data/lib/kitchen/terraform/command_flag/var.rb +43 -0
- data/lib/kitchen/terraform/command_flag/var_file.rb +45 -0
- data/lib/kitchen/terraform/config_attribute.rb +58 -55
- data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/client.rb +10 -3
- data/lib/kitchen/terraform/config_attribute/color.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/command_timeout.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/fail_fast.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/lock.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/parallelism.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +3 -3
- data/lib/kitchen/terraform/config_attribute/root_module_directory.rb +4 -4
- data/lib/kitchen/terraform/config_attribute/systems.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/variable_files.rb +4 -4
- data/lib/kitchen/terraform/config_attribute/variables.rb +1 -1
- data/lib/kitchen/terraform/config_attribute/verify_version.rb +2 -2
- data/lib/kitchen/terraform/config_attribute_cacher.rb +27 -25
- data/lib/kitchen/terraform/config_attribute_definer.rb +37 -43
- data/lib/kitchen/terraform/config_attribute_type.rb +7 -5
- data/lib/kitchen/terraform/config_attribute_type/hash_of_symbols_and_strings.rb +32 -27
- data/lib/kitchen/terraform/config_attribute_type/integer.rb +4 -4
- data/lib/kitchen/terraform/config_predicates.rb +7 -5
- data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +6 -6
- data/lib/kitchen/terraform/config_schemas.rb +7 -5
- data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +20 -13
- data/lib/kitchen/terraform/config_schemas/boolean.rb +16 -9
- data/lib/kitchen/terraform/config_schemas/optional_string.rb +20 -13
- data/lib/kitchen/terraform/config_schemas/string.rb +13 -7
- data/lib/kitchen/terraform/config_schemas/system.rb +38 -16
- data/lib/kitchen/terraform/config_schemas/systems.rb +5 -2
- data/lib/kitchen/terraform/configurable.rb +41 -21
- data/lib/kitchen/terraform/debug_logger.rb +1 -1
- data/lib/kitchen/terraform/deprecating.rb +7 -5
- data/lib/kitchen/terraform/driver.rb +23 -0
- data/lib/kitchen/terraform/driver/create.rb +120 -0
- data/lib/kitchen/terraform/driver/destroy.rb +169 -0
- data/lib/kitchen/terraform/error.rb +7 -5
- data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +30 -27
- data/lib/kitchen/terraform/inspec.rb +3 -57
- data/lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb +59 -0
- data/lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb +69 -0
- data/lib/kitchen/terraform/inspec/without_hosts.rb +52 -0
- data/lib/kitchen/terraform/inspec_factory.rb +68 -0
- data/lib/kitchen/terraform/inspec_options_factory.rb +86 -0
- data/lib/kitchen/terraform/inspec_runner.rb +88 -0
- data/lib/kitchen/terraform/outputs_manager.rb +64 -0
- data/lib/kitchen/terraform/outputs_parser.rb +39 -0
- data/lib/kitchen/terraform/outputs_reader.rb +63 -0
- data/lib/kitchen/terraform/provisioner.rb +23 -0
- data/lib/kitchen/terraform/provisioner/converge.rb +206 -0
- data/lib/kitchen/terraform/raise.rb +23 -0
- data/lib/kitchen/terraform/raise/action_failed.rb +49 -0
- data/lib/kitchen/terraform/raise/client_error.rb +49 -0
- data/lib/kitchen/terraform/shell_out.rb +90 -59
- data/lib/kitchen/terraform/system.rb +63 -93
- data/lib/kitchen/terraform/system_attrs_inputs_resolver.rb +49 -0
- data/lib/kitchen/terraform/system_attrs_outputs_resolver.rb +80 -0
- data/lib/kitchen/terraform/system_bastion_host_resolver.rb +72 -0
- data/lib/kitchen/terraform/system_hosts_resolver.rb +39 -17
- data/lib/kitchen/terraform/system_inspec_map.rb +49 -0
- data/lib/kitchen/terraform/systems_verifier.rb +23 -0
- data/lib/kitchen/terraform/systems_verifier/fail_fast.rb +52 -0
- data/lib/kitchen/terraform/systems_verifier/fail_slow.rb +62 -0
- data/lib/kitchen/terraform/systems_verifier_factory.rb +50 -0
- data/lib/kitchen/terraform/unsupported_client_version_error.rb +26 -0
- data/lib/kitchen/terraform/variables_manager.rb +64 -0
- data/lib/kitchen/terraform/verify_version.rb +63 -20
- data/lib/kitchen/terraform/verify_version_rescue_strategy.rb +23 -0
- data/lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb +50 -0
- data/lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb +47 -0
- data/lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb +51 -0
- data/lib/kitchen/terraform/version.rb +59 -58
- data/lib/kitchen/terraform/version_verifier.rb +50 -0
- data/lib/kitchen/terraform/version_verifier_strategy.rb +25 -0
- data/lib/kitchen/terraform/version_verifier_strategy/supported.rb +33 -0
- data/lib/kitchen/terraform/version_verifier_strategy/unsupported.rb +34 -0
- data/lib/kitchen/terraform/version_verifier_strategy_factory.rb +50 -0
- data/lib/kitchen/verifier/terraform.rb +71 -62
- metadata +143 -80
- metadata.gz.sig +0 -0
- data/lib/kitchen/terraform/inspec_options_mapper.rb +0 -73
- data/lib/kitchen/terraform/inspec_with_hosts.rb +0 -50
- data/lib/kitchen/terraform/inspec_without_hosts.rb +0 -45
- data/lib/kitchen/terraform/system_attrs_resolver.rb +0 -60
@@ -0,0 +1,39 @@
|
|
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 "json"
|
18
|
+
require "kitchen"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
# OutputsParser parses Terraform output variables as JSON.
|
23
|
+
class OutputsParser
|
24
|
+
# #parse parses the outputs.
|
25
|
+
#
|
26
|
+
# @param json_outputs [String] the output variables as a string of JSON.
|
27
|
+
# @raise [Kitchen::TransientFailure] if parsing the output variables fails.
|
28
|
+
# @yieldparam parsed_outputs [Hash] the output variables as a hash.
|
29
|
+
# @return [self]
|
30
|
+
def parse(json_outputs:)
|
31
|
+
yield parsed_outputs: ::JSON.parse(json_outputs)
|
32
|
+
|
33
|
+
self
|
34
|
+
rescue ::JSON::ParserError
|
35
|
+
raise ::Kitchen::TransientFailure, "Parsing the Terraform output variables as JSON failed."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "kitchen"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
# OutputsReader is the class of objects which read Terraform output variables.
|
22
|
+
class OutputsReader
|
23
|
+
# #read reads the output variables.
|
24
|
+
#
|
25
|
+
# @param command [Kitchen::Terraform::Command::Output] the output command.
|
26
|
+
# @raise [Kitchen::TransientFailure] if running the output command fails.
|
27
|
+
# @yieldparam json_outputs [String] the output variables as a string of JSON.
|
28
|
+
# @return [self]
|
29
|
+
def read(command:, options:)
|
30
|
+
run command: command, options: options do |json_outputs:|
|
31
|
+
yield json_outputs: json_outputs
|
32
|
+
end
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# #initialize prepares a new instance of the class.
|
38
|
+
#
|
39
|
+
# @param command_executor [Kitchen::Terraform::CommandExecutor] an executor to run the output command.
|
40
|
+
# @return [Kitchen::Terraform::OutputsReader]
|
41
|
+
def initialize(command_executor:)
|
42
|
+
self.command_executor = command_executor
|
43
|
+
self.no_outputs_defined = /no\\ outputs\\ defined/
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_accessor :command_executor, :no_outputs_defined
|
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
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# Provisioner is the namespace for provisioner strategies.
|
20
|
+
module Provisioner
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "kitchen"
|
18
|
+
require "kitchen/terraform/command_executor"
|
19
|
+
require "kitchen/terraform/command/apply"
|
20
|
+
require "kitchen/terraform/command/get"
|
21
|
+
require "kitchen/terraform/command/output"
|
22
|
+
require "kitchen/terraform/command/validate"
|
23
|
+
require "kitchen/terraform/command/workspace_select"
|
24
|
+
require "kitchen/terraform/debug_logger"
|
25
|
+
require "kitchen/terraform/outputs_manager"
|
26
|
+
require "kitchen/terraform/outputs_parser"
|
27
|
+
require "kitchen/terraform/outputs_reader"
|
28
|
+
require "kitchen/terraform/variables_manager"
|
29
|
+
require "kitchen/terraform/verify_version"
|
30
|
+
require "kitchen/terraform/version"
|
31
|
+
|
32
|
+
module Kitchen
|
33
|
+
module Terraform
|
34
|
+
module Provisioner
|
35
|
+
# A Test Kitchen instance is converged through the following steps.
|
36
|
+
#
|
37
|
+
# ===== Selecting the Test Terraform Workspace
|
38
|
+
#
|
39
|
+
# {include:Kitchen::Terraform::Command::WorkspaceSelect}
|
40
|
+
#
|
41
|
+
# ===== Updating the Terraform Dependency Modules
|
42
|
+
#
|
43
|
+
# {include:Kitchen::Terraform::Command::Get}
|
44
|
+
#
|
45
|
+
# ===== Validating the Terraform Root Module
|
46
|
+
#
|
47
|
+
# {include:Kitchen::Terraform::Command::Validate}
|
48
|
+
#
|
49
|
+
# ===== Applying the Terraform State Changes
|
50
|
+
#
|
51
|
+
# {include:Kitchen::Terraform::Command::Apply}
|
52
|
+
#
|
53
|
+
# ===== Retrieving the Terraform Output
|
54
|
+
#
|
55
|
+
# {include:Kitchen::Terraform::Command::Output}
|
56
|
+
class Converge
|
57
|
+
# #call executes the action.
|
58
|
+
#
|
59
|
+
# @param state [Hash] the Kitchen instance state.
|
60
|
+
# @raise [Kitchen::TransientFailure] if a command fails.
|
61
|
+
# @return [self]
|
62
|
+
def call(state:)
|
63
|
+
verify_version.call command: version, options: options
|
64
|
+
execute_workflow
|
65
|
+
save_variables_and_outputs state: state
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
# #initialize prepares a new instance of the class.
|
71
|
+
#
|
72
|
+
# @param config [Hash] the configuration of the driver.
|
73
|
+
# @param logger [Kitchen::Logger] a logger for logging messages.
|
74
|
+
# @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
|
75
|
+
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
76
|
+
# @return [Kitchen::Terraform::Driver::Converge]
|
77
|
+
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
78
|
+
client = config.fetch :client
|
79
|
+
hash_config = config.to_hash.merge workspace_name: workspace_name
|
80
|
+
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
81
|
+
client: client,
|
82
|
+
logger: logger,
|
83
|
+
)
|
84
|
+
self.logger = logger
|
85
|
+
self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
|
86
|
+
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
|
90
|
+
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
|
94
|
+
self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
|
95
|
+
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
96
|
+
command_executor: command_executor,
|
97
|
+
config: config,
|
98
|
+
logger: logger,
|
99
|
+
version_requirement: version_requirement,
|
100
|
+
)
|
101
|
+
self.version = ::Kitchen::Terraform::Command::Version.new
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
attr_accessor(
|
107
|
+
:command_executor,
|
108
|
+
:apply,
|
109
|
+
:get,
|
110
|
+
:output,
|
111
|
+
:validate,
|
112
|
+
:workspace_select,
|
113
|
+
:logger,
|
114
|
+
:options,
|
115
|
+
:outputs_manager,
|
116
|
+
:outputs_parser,
|
117
|
+
:outputs_reader,
|
118
|
+
:variables,
|
119
|
+
:variables_manager,
|
120
|
+
:verify_version,
|
121
|
+
:version,
|
122
|
+
:workspace_name,
|
123
|
+
)
|
124
|
+
|
125
|
+
def build_infrastructure
|
126
|
+
logger.warn "Building the infrastructure based on the Terraform configuration..."
|
127
|
+
command_executor.run command: apply, options: options do |standard_output:|
|
128
|
+
end
|
129
|
+
logger.warn "Finished building the infrastructure based on the Terraform configuration."
|
130
|
+
end
|
131
|
+
|
132
|
+
def download_modules
|
133
|
+
logger.warn "Downloading the modules needed for the Terraform configuration..."
|
134
|
+
command_executor.run command: get, options: options do |standard_output:|
|
135
|
+
end
|
136
|
+
logger.warn "Finished downloading the modules needed for the Terraform configuration."
|
137
|
+
end
|
138
|
+
|
139
|
+
def execute_workflow
|
140
|
+
select_workspace
|
141
|
+
download_modules
|
142
|
+
validate_files
|
143
|
+
build_infrastructure
|
144
|
+
end
|
145
|
+
|
146
|
+
def initialize_outputs_handlers(client:, logger:)
|
147
|
+
self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
|
148
|
+
self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
|
149
|
+
self.outputs_reader = ::Kitchen::Terraform::OutputsReader.new(
|
150
|
+
command_executor: ::Kitchen::Terraform::CommandExecutor.new(
|
151
|
+
client: client,
|
152
|
+
logger: ::Kitchen::Terraform::DebugLogger.new(logger),
|
153
|
+
),
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
def parse_outputs(json_outputs:)
|
158
|
+
logger.warn "Parsing the Terraform output variables as JSON..."
|
159
|
+
outputs_parser.parse json_outputs: json_outputs do |parsed_outputs:|
|
160
|
+
logger.warn "Finished parsing the Terraform output variables as JSON."
|
161
|
+
|
162
|
+
yield parsed_outputs: parsed_outputs
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def read_and_parse_outputs(&block)
|
167
|
+
logger.warn "Reading the output variables from the Terraform state..."
|
168
|
+
outputs_reader.read command: output, options: options do |json_outputs:|
|
169
|
+
logger.warn "Finished reading the output variables from the Terraform state."
|
170
|
+
|
171
|
+
parse_outputs json_outputs: json_outputs, &block
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def save_outputs(parsed_outputs:, state:)
|
176
|
+
logger.warn "Writing the output variables to the Kitchen instance state..."
|
177
|
+
outputs_manager.save outputs: parsed_outputs, state: state
|
178
|
+
logger.warn "Finished writing the output variables to the Kitchen instance state."
|
179
|
+
end
|
180
|
+
|
181
|
+
def save_variables_and_outputs(state:)
|
182
|
+
read_and_parse_outputs do |parsed_outputs:|
|
183
|
+
save_outputs parsed_outputs: parsed_outputs, state: state
|
184
|
+
end
|
185
|
+
logger.warn "Writing the input variables to the Kitchen instance state..."
|
186
|
+
variables_manager.save variables: variables, state: state
|
187
|
+
logger.warn "Finished writing the input variables to the Kitchen instance state."
|
188
|
+
end
|
189
|
+
|
190
|
+
def select_workspace
|
191
|
+
logger.warn "Selecting the #{workspace_name} Terraform workspace..."
|
192
|
+
command_executor.run command: workspace_select, options: options do |standard_output:|
|
193
|
+
end
|
194
|
+
logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
|
195
|
+
end
|
196
|
+
|
197
|
+
def validate_files
|
198
|
+
logger.warn "Validating the Terraform configuration files..."
|
199
|
+
command_executor.run command: validate, options: options do |standard_output:|
|
200
|
+
end
|
201
|
+
logger.warn "Finished validating the Terraform configuration files."
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# Raise is the namespace for objects which raise errors.
|
20
|
+
module Raise
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "kitchen"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module Raise
|
22
|
+
# ActionFailed is the class of objects which handle errors resulting in failed actions.
|
23
|
+
class ActionFailed
|
24
|
+
# #call logs an error message and raises an error with the message.
|
25
|
+
#
|
26
|
+
# @param message [String] the error message.
|
27
|
+
# @raise [Kitchen::ActionFailed]
|
28
|
+
# @return [void]
|
29
|
+
def call(message:)
|
30
|
+
logger.error message
|
31
|
+
|
32
|
+
raise ::Kitchen::ActionFailed, message
|
33
|
+
end
|
34
|
+
|
35
|
+
# #initialize prepares a new instance of the class.
|
36
|
+
#
|
37
|
+
# @param logger [Kitchen::Logger] a logger to log messages.
|
38
|
+
# @return [Kitchen::Terraform::ActionFailed]
|
39
|
+
def initialize(logger:)
|
40
|
+
self.logger = logger
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_accessor :logger
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016-2019 New Context, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "kitchen"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module Raise
|
22
|
+
# ClientError is the class of objects which handle errors that are caused by incorrect use of an API.
|
23
|
+
class ClientError
|
24
|
+
# #call logs an error message and raises an error with the message.
|
25
|
+
#
|
26
|
+
# @param message [String] the error message.
|
27
|
+
# @raise [Kitchen::ClientError]
|
28
|
+
# @return [void]
|
29
|
+
def call(message:)
|
30
|
+
logger.error message
|
31
|
+
|
32
|
+
raise ::Kitchen::ClientError, message
|
33
|
+
end
|
34
|
+
|
35
|
+
# #initialize prepares a new instance of the class.
|
36
|
+
#
|
37
|
+
# @param logger [Kitchen::Logger] a logger to log messages.
|
38
|
+
# @return [Kitchen::Terraform::ClientError]
|
39
|
+
def initialize(logger:)
|
40
|
+
self.logger = logger
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_accessor :logger
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|