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
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2016 New Context
|
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
|
-
|
18
|
-
|
19
|
-
# The namespace for objects with deprecating changes.
|
20
|
-
module
|
17
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# The namespace for objects with deprecating changes.
|
20
|
+
module Deprecating
|
21
|
+
end
|
22
|
+
end
|
21
23
|
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
|
+
# Driver is the namespace for driver strategies.
|
20
|
+
module Driver
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,120 @@
|
|
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/init"
|
19
|
+
require "kitchen/terraform/command/version"
|
20
|
+
require "kitchen/terraform/command/workspace_new"
|
21
|
+
require "kitchen/terraform/command/workspace_select"
|
22
|
+
require "kitchen/terraform/command_executor"
|
23
|
+
require "kitchen/terraform/verify_version"
|
24
|
+
|
25
|
+
module Kitchen
|
26
|
+
module Terraform
|
27
|
+
module Driver
|
28
|
+
# A Test Kitchen instance is created through the following steps.
|
29
|
+
#
|
30
|
+
# ===== Initializing the Terraform Working Directory
|
31
|
+
#
|
32
|
+
# {include:Kitchen::Terraform::Command::Init}
|
33
|
+
#
|
34
|
+
# ===== Creating or Selecting the Test Terraform Workspace
|
35
|
+
#
|
36
|
+
# {include:Kitchen::Terraform::Command::WorkspaceNew}
|
37
|
+
#
|
38
|
+
# {include:Kitchen::Terraform::Command::WorkspaceSelect}
|
39
|
+
class Create
|
40
|
+
# #call executes the action.
|
41
|
+
#
|
42
|
+
# @raise [Kitchen::TransientFailure] if a command fails.
|
43
|
+
# @return [self]
|
44
|
+
def call
|
45
|
+
verify_version.call command: version, options: options
|
46
|
+
initialize_directory
|
47
|
+
create_or_select_workspace
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
# #initialize prepares a new instance of the class.
|
53
|
+
#
|
54
|
+
# @param config [Hash] the configuration of the driver.
|
55
|
+
# @param logger [Kitchen::Logger] a logger for logging messages.
|
56
|
+
# @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
|
57
|
+
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
58
|
+
# @option config [String] :client the pathname of the Terraform client.
|
59
|
+
# @return [Kitchen::Terraform::Driver::Create]
|
60
|
+
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
61
|
+
hash_config = config.to_hash.merge upgrade_during_init: true, workspace_name: workspace_name
|
62
|
+
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
63
|
+
client: config.fetch(:client),
|
64
|
+
logger: logger,
|
65
|
+
)
|
66
|
+
self.init = ::Kitchen::Terraform::Command::Init.new config: hash_config
|
67
|
+
self.logger = logger
|
68
|
+
self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
|
69
|
+
self.workspace_name = workspace_name
|
70
|
+
self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config: hash_config
|
71
|
+
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
|
72
|
+
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
73
|
+
command_executor: command_executor,
|
74
|
+
config: config,
|
75
|
+
logger: logger,
|
76
|
+
version_requirement: version_requirement,
|
77
|
+
)
|
78
|
+
self.version = ::Kitchen::Terraform::Command::Version.new
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
attr_accessor(
|
84
|
+
:command_executor,
|
85
|
+
:init,
|
86
|
+
:logger,
|
87
|
+
:options,
|
88
|
+
:verify_version,
|
89
|
+
:version,
|
90
|
+
:workspace_name,
|
91
|
+
:workspace_new,
|
92
|
+
:workspace_select,
|
93
|
+
)
|
94
|
+
|
95
|
+
def create_or_select_workspace
|
96
|
+
logger.warn "Creating the #{workspace_name} Terraform workspace..."
|
97
|
+
command_executor.run command: workspace_new, options: options do |standard_output:|
|
98
|
+
end
|
99
|
+
logger.warn "Finished creating the #{workspace_name} Terraform workspace."
|
100
|
+
rescue ::Kitchen::TransientFailure
|
101
|
+
select_workspace
|
102
|
+
end
|
103
|
+
|
104
|
+
def initialize_directory
|
105
|
+
logger.warn "Initializing the Terraform working directory..."
|
106
|
+
command_executor.run command: init, options: options do |standard_output:|
|
107
|
+
end
|
108
|
+
logger.warn "Finished initializing the Terraform working directory."
|
109
|
+
end
|
110
|
+
|
111
|
+
def select_workspace
|
112
|
+
logger.warn "Selecting the #{workspace_name} Terraform workspace..."
|
113
|
+
command_executor.run command: workspace_select, options: options do |standard_output:|
|
114
|
+
end
|
115
|
+
logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,169 @@
|
|
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/destroy"
|
20
|
+
require "kitchen/terraform/command/init"
|
21
|
+
require "kitchen/terraform/command/version"
|
22
|
+
require "kitchen/terraform/command/workspace_delete"
|
23
|
+
require "kitchen/terraform/command/workspace_new"
|
24
|
+
require "kitchen/terraform/command/workspace_select"
|
25
|
+
require "kitchen/terraform/verify_version"
|
26
|
+
|
27
|
+
module Kitchen
|
28
|
+
module Terraform
|
29
|
+
module Driver
|
30
|
+
# A Test Kitchen instance is destroyed through the following steps.
|
31
|
+
#
|
32
|
+
# ===== Initializing the Terraform Working Directory
|
33
|
+
#
|
34
|
+
# {include:Kitchen::Terraform::Command::Init}
|
35
|
+
#
|
36
|
+
# ===== Selecting or Creating the Test Terraform Workspace
|
37
|
+
#
|
38
|
+
# {include:Kitchen::Terraform::Command::WorkspaceSelect}
|
39
|
+
#
|
40
|
+
# {include:Kitchen::Terraform::Command::WorkspaceNew}
|
41
|
+
#
|
42
|
+
# ===== Destroying the Terraform State
|
43
|
+
#
|
44
|
+
# {include:Kitchen::Terraform::Command::Destroy}
|
45
|
+
#
|
46
|
+
# ===== Selecting the Default Terraform Workspace
|
47
|
+
#
|
48
|
+
# {include:Kitchen::Terraform::Command::WorkspaceSelect}
|
49
|
+
#
|
50
|
+
# ===== Deleting the Test Terraform Workspace
|
51
|
+
#
|
52
|
+
# {include:Kitchen::Terraform::Command::WorkspaceDelete}
|
53
|
+
class Destroy
|
54
|
+
# #call executes the action.
|
55
|
+
#
|
56
|
+
# @raise [Kitchen::TransientFailure] if a command fails.
|
57
|
+
# @return [self]
|
58
|
+
def call
|
59
|
+
verify_version.call command: version, options: options
|
60
|
+
execute_workflow
|
61
|
+
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
# #initialize prepares a new instance of the class.
|
66
|
+
#
|
67
|
+
# @param config [Hash] the configuration of the driver.
|
68
|
+
# @param logger [Kitchen::Logger] a logger for logging messages.
|
69
|
+
# @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
|
70
|
+
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
71
|
+
# @return [Kitchen::Terraform::Driver::Destroy]
|
72
|
+
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
73
|
+
hash_config = config.to_hash.merge upgrade_during_init: false, workspace_name: workspace_name
|
74
|
+
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
75
|
+
client: config.fetch(:client),
|
76
|
+
logger: logger,
|
77
|
+
)
|
78
|
+
self.logger = logger
|
79
|
+
self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
|
80
|
+
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
|
86
|
+
self.workspace_select_default = ::Kitchen::Terraform::Command::WorkspaceSelect.new(
|
87
|
+
config: hash_config.merge(workspace_name: "default"),
|
88
|
+
)
|
89
|
+
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
90
|
+
command_executor: command_executor,
|
91
|
+
config: config,
|
92
|
+
logger: logger,
|
93
|
+
version_requirement: version_requirement,
|
94
|
+
)
|
95
|
+
self.version = ::Kitchen::Terraform::Command::Version.new
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
attr_accessor(
|
101
|
+
:command_executor,
|
102
|
+
:destroy,
|
103
|
+
:init,
|
104
|
+
:logger,
|
105
|
+
:options,
|
106
|
+
:verify_version,
|
107
|
+
:version,
|
108
|
+
:workspace_delete_test,
|
109
|
+
:workspace_name,
|
110
|
+
:workspace_new_test,
|
111
|
+
:workspace_select_default,
|
112
|
+
:workspace_select_test,
|
113
|
+
)
|
114
|
+
|
115
|
+
def create_test_workspace
|
116
|
+
logger.warn "Creating the #{workspace_name} Terraform workspace..."
|
117
|
+
command_executor.run command: workspace_new_test, options: options do |standard_output:|
|
118
|
+
end
|
119
|
+
logger.warn "Finished creating the #{workspace_name} Terraform workspace."
|
120
|
+
end
|
121
|
+
|
122
|
+
def destroy_infrastructure
|
123
|
+
logger.warn "Destroying the Terraform-managed infrastructure..."
|
124
|
+
command_executor.run command: destroy, options: options do |standard_output:|
|
125
|
+
end
|
126
|
+
logger.warn "Finished destroying the Terraform-managed infrastructure."
|
127
|
+
end
|
128
|
+
|
129
|
+
def delete_test_workspace
|
130
|
+
logger.warn "Deleting the #{workspace_name} Terraform workspace..."
|
131
|
+
command_executor.run command: workspace_delete_test, options: options do |standard_output:|
|
132
|
+
end
|
133
|
+
logger.warn "Finished deleting the #{workspace_name} Terraform workspace."
|
134
|
+
end
|
135
|
+
|
136
|
+
def execute_workflow
|
137
|
+
initialize_directory
|
138
|
+
select_or_create_test_workspace
|
139
|
+
destroy_infrastructure
|
140
|
+
select_default_workspace
|
141
|
+
delete_test_workspace
|
142
|
+
end
|
143
|
+
|
144
|
+
def initialize_directory
|
145
|
+
logger.warn "Initializing the Terraform working directory..."
|
146
|
+
command_executor.run command: init, options: options do |standard_output:|
|
147
|
+
end
|
148
|
+
logger.warn "Finished initializing the Terraform working directory."
|
149
|
+
end
|
150
|
+
|
151
|
+
def select_default_workspace
|
152
|
+
logger.warn "Selecting the default Terraform workspace..."
|
153
|
+
command_executor.run command: workspace_select_default, options: options do |standard_output:|
|
154
|
+
end
|
155
|
+
logger.warn "Finished selecting the default Terraform workspace."
|
156
|
+
end
|
157
|
+
|
158
|
+
def select_or_create_test_workspace
|
159
|
+
logger.warn "Selecting the #{workspace_name} Terraform workspace..."
|
160
|
+
command_executor.run command: workspace_select_test, options: options do |standard_output:|
|
161
|
+
end
|
162
|
+
logger.warn "Finished selecting the #{workspace_name} Terraform workspace."
|
163
|
+
rescue ::Kitchen::TransientFailure
|
164
|
+
create_test_workspace
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2016 New Context
|
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
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
class
|
17
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# Error is the class of objects which are raised Kitchen-Terraform experiences an error.
|
20
|
+
class Error < ::StandardError
|
21
|
+
end
|
22
|
+
end
|
21
23
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2016 New Context
|
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,35 +14,38 @@
|
|
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
17
|
require "kitchen/terraform/config_attribute_definer"
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
# FilePathConfigAttributeDefiner is the class of objects which define a file path configuration attribute on a
|
22
|
+
# plugin class.
|
23
|
+
class FilePathConfigAttributeDefiner
|
24
|
+
# #define defines the file path configuration attribute on a plugin class.
|
25
|
+
#
|
26
|
+
# @param plugin_class [Kitchen::ConfigAttributeVerifier] a plugin class which has configuration
|
27
|
+
# attribute verification behaviour.
|
28
|
+
# @return [self]
|
29
|
+
def define(plugin_class:)
|
30
|
+
definer.define plugin_class: plugin_class
|
31
|
+
plugin_class.expand_path_for attribute.to_sym
|
32
|
+
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# #initialize prepares a new instance of the class.
|
37
|
+
#
|
38
|
+
# @param attribute [Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class.
|
39
|
+
# @param schema [Dry::Validation::Schema] a schema to use for validation of values of the attribute.
|
40
|
+
# @return [Kitchen::Terraform::FilePathConfigAttributeDefiner]
|
41
|
+
def initialize(attribute:, schema:)
|
42
|
+
self.attribute = attribute
|
43
|
+
self.definer = ::Kitchen::Terraform::ConfigAttributeDefiner.new attribute: attribute, schema: schema
|
44
|
+
end
|
31
45
|
|
32
|
-
|
46
|
+
private
|
33
47
|
|
34
|
-
|
35
|
-
|
36
|
-
# @api private
|
37
|
-
# @param attribute [::Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class.
|
38
|
-
# @param schema [::Dry::Validation::Schema] a schema to use for validation of values of the attribute.
|
39
|
-
def initialize(attribute:, schema:)
|
40
|
-
@attribute = attribute
|
41
|
-
@definer =
|
42
|
-
::Kitchen::Terraform::ConfigAttributeDefiner
|
43
|
-
.new(
|
44
|
-
attribute: attribute,
|
45
|
-
schema: schema,
|
46
|
-
)
|
48
|
+
attr_accessor :attribute, :definer
|
49
|
+
end
|
47
50
|
end
|
48
51
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2016 New Context
|
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,64 +14,10 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require "inspec"
|
18
|
-
require "kitchen/terraform/error"
|
19
|
-
require "train"
|
20
|
-
|
21
17
|
module Kitchen
|
22
18
|
module Terraform
|
23
|
-
# InSpec is the
|
24
|
-
|
25
|
-
class << self
|
26
|
-
# .logger= sets the logger for all InSpec processes.
|
27
|
-
#
|
28
|
-
# The logdev of the logger is extended to conform to interface expected by InSpec.
|
29
|
-
#
|
30
|
-
# @param logger [::Kitchen::Logger] the logger to use.
|
31
|
-
# @return [void]
|
32
|
-
def logger=(logger)
|
33
|
-
logger.logdev.define_singleton_method :filename do
|
34
|
-
false
|
35
|
-
end
|
36
|
-
|
37
|
-
::Inspec::Log.logger = logger
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# #exec executes InSpec.
|
42
|
-
#
|
43
|
-
# @raise [::Kitchen::Terraform::Error] if executing InSpec fails.
|
44
|
-
# @return [self]
|
45
|
-
def exec
|
46
|
-
@runner.run.tap do |exit_code|
|
47
|
-
if 0 != exit_code
|
48
|
-
raise ::Kitchen::Terraform::Error, "InSpec Runner exited with #{exit_code}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
self
|
53
|
-
rescue ::ArgumentError, ::RuntimeError, ::Train::UserError => error
|
54
|
-
raise ::Kitchen::Terraform::Error, "Executing InSpec failed\n#{error.message}"
|
55
|
-
end
|
56
|
-
|
57
|
-
# #info logs an information message using the InSpec logger.
|
58
|
-
#
|
59
|
-
# @param message [::String] the message to be logged.
|
60
|
-
# @return [self]
|
61
|
-
def info(message:)
|
62
|
-
::Inspec::Log.info ::String.new message
|
63
|
-
|
64
|
-
self
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def initialize(options:, profile_locations:)
|
70
|
-
@runner = ::Inspec::Runner.new options.merge logger: ::Inspec::Log.logger
|
71
|
-
profile_locations.each do |profile_location|
|
72
|
-
@runner.add_target profile_location
|
73
|
-
end
|
74
|
-
end
|
19
|
+
# InSpec is the namespace for the classes of objects which execute InSpec.
|
20
|
+
module InSpec
|
75
21
|
end
|
76
22
|
end
|
77
23
|
end
|