kitchen-terraform 5.1.1 → 5.2.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +8 -10
- 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 +14 -12
- 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 +67 -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 +196 -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 +62 -94
- 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_hosts_resolver.rb +39 -17
- data/lib/kitchen/terraform/system_inspec_map.rb +50 -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 +132 -42
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df1c8cf5af302e8ff0157356cdcd17b629b4613a279f44f6776b1c83532fee55
|
|
4
|
+
data.tar.gz: ddf2fee8e8b4191bdae7305ca3c2fb1464c58aa9eff9edbfe14495051f31d757
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 179e8d7217c594ad88c2bcfe3c81537a7ac18a4b9a0ff9645a56261ec6143468e08d026e99fdd105c253a8567e19f0df9293a1b91a0143a81687ae7b69c963ac
|
|
7
|
+
data.tar.gz: f32b9ebb0be2ca34102d51650bf0d73e83807a6d49ab38de21aac89c188be9850ff9d2c1a995d9a154c4a83fe044a3529f2ee53f3f8153158b77049bbd655aee
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -75,10 +75,7 @@ the semantic versioning of the Ruby gem.
|
|
|
75
75
|
|
|
76
76
|
```ruby
|
|
77
77
|
source "https://rubygems.org/" do
|
|
78
|
-
gem
|
|
79
|
-
"kitchen-terraform",
|
|
80
|
-
"~> 4.0"
|
|
81
|
-
)
|
|
78
|
+
gem "kitchen-terraform", "~> 5.2"
|
|
82
79
|
end
|
|
83
80
|
```
|
|
84
81
|
|
|
@@ -105,7 +102,7 @@ example.
|
|
|
105
102
|
> Installing Kitchen-Terraform with RubyGems
|
|
106
103
|
|
|
107
104
|
```sh
|
|
108
|
-
gem install kitchen-terraform --version
|
|
105
|
+
gem install kitchen-terraform --version 5.2.0
|
|
109
106
|
```
|
|
110
107
|
|
|
111
108
|
This approach is not recommended as it requires more effort to install
|
|
@@ -183,10 +180,10 @@ hierarchy of files comprising the following blocks.
|
|
|
183
180
|
```ruby
|
|
184
181
|
source "https://rubygems.org/"
|
|
185
182
|
|
|
186
|
-
gem 'kitchen-terraform'
|
|
183
|
+
gem 'kitchen-terraform', '~> 5.1'
|
|
187
184
|
```
|
|
188
185
|
|
|
189
|
-
>
|
|
186
|
+
> ./kitchen.yml (Test Kitchen configuration)
|
|
190
187
|
|
|
191
188
|
```yaml
|
|
192
189
|
driver:
|
|
@@ -212,11 +209,12 @@ suites:
|
|
|
212
209
|
- name: example
|
|
213
210
|
```
|
|
214
211
|
|
|
212
|
+
Although Kitchen-Terraform supports multiple versions of Terraform, below snippets are compatible with v0.12:
|
|
215
213
|
> ./main.tf
|
|
216
214
|
|
|
217
215
|
```hcl
|
|
218
216
|
provider "docker" {
|
|
219
|
-
host
|
|
217
|
+
host = "unix:///var/run/docker.sock"
|
|
220
218
|
}
|
|
221
219
|
|
|
222
220
|
data "docker_registry_image" "ubuntu" {
|
|
@@ -224,12 +222,12 @@ data "docker_registry_image" "ubuntu" {
|
|
|
224
222
|
}
|
|
225
223
|
|
|
226
224
|
resource "docker_image" "ubuntu" {
|
|
227
|
-
name =
|
|
225
|
+
name = data.docker_registry_image.ubuntu.name
|
|
228
226
|
pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"]
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
resource "docker_container" "ubuntu" {
|
|
232
|
-
image =
|
|
230
|
+
image = docker_image.ubuntu.name
|
|
233
231
|
must_run = true
|
|
234
232
|
name = "ubuntu_container"
|
|
235
233
|
|
|
@@ -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.
|
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
17
|
require "kitchen"
|
|
18
|
-
require "kitchen/terraform/
|
|
19
|
-
require "kitchen/terraform/command/version"
|
|
18
|
+
require "kitchen/terraform/raise/action_failed"
|
|
20
19
|
require "kitchen/terraform/config_attribute/backend_configurations"
|
|
21
20
|
require "kitchen/terraform/config_attribute/client"
|
|
22
21
|
require "kitchen/terraform/config_attribute/color"
|
|
23
22
|
require "kitchen/terraform/config_attribute/command_timeout"
|
|
24
|
-
require "kitchen/terraform/config_attribute/lock"
|
|
25
23
|
require "kitchen/terraform/config_attribute/lock_timeout"
|
|
24
|
+
require "kitchen/terraform/config_attribute/lock"
|
|
26
25
|
require "kitchen/terraform/config_attribute/parallelism"
|
|
27
26
|
require "kitchen/terraform/config_attribute/plugin_directory"
|
|
28
27
|
require "kitchen/terraform/config_attribute/root_module_directory"
|
|
@@ -30,521 +29,204 @@ require "kitchen/terraform/config_attribute/variable_files"
|
|
|
30
29
|
require "kitchen/terraform/config_attribute/variables"
|
|
31
30
|
require "kitchen/terraform/config_attribute/verify_version"
|
|
32
31
|
require "kitchen/terraform/configurable"
|
|
33
|
-
require "kitchen/terraform/
|
|
34
|
-
require "kitchen/terraform/
|
|
35
|
-
require "kitchen/terraform/
|
|
32
|
+
require "kitchen/terraform/driver/create"
|
|
33
|
+
require "kitchen/terraform/driver/destroy"
|
|
34
|
+
require "kitchen/terraform/version_verifier"
|
|
35
|
+
require "rubygems"
|
|
36
36
|
require "shellwords"
|
|
37
37
|
|
|
38
38
|
# This namespace is defined by Kitchen.
|
|
39
39
|
#
|
|
40
|
-
# @see http://www.rubydoc.info/gems/test-kitchen/Kitchen
|
|
41
|
-
module
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# The driver is the bridge between Test Kitchen and Terraform. It manages the
|
|
45
|
-
# {https://www.terraform.io/docs/state/index.html state} of the Terraform root module by shelling out and running
|
|
46
|
-
# Terraform commands.
|
|
47
|
-
#
|
|
48
|
-
# === Commands
|
|
49
|
-
#
|
|
50
|
-
# The following command-line commands are provided by the driver.
|
|
51
|
-
#
|
|
52
|
-
# ==== kitchen create
|
|
53
|
-
#
|
|
54
|
-
# A Test Kitchen instance is created through the following steps.
|
|
55
|
-
#
|
|
56
|
-
# ===== Initializing the Terraform Working Directory
|
|
57
|
-
#
|
|
58
|
-
# terraform init \
|
|
59
|
-
# -input=false \
|
|
60
|
-
# -lock=<lock> \
|
|
61
|
-
# -lock-timeout=<lock_timeout>s \
|
|
62
|
-
# [-no-color] \
|
|
63
|
-
# -upgrade \
|
|
64
|
-
# -force-copy \
|
|
65
|
-
# -backend=true \
|
|
66
|
-
# [-backend-config=<backend_configurations.first> ...] \
|
|
67
|
-
# -get=true \
|
|
68
|
-
# -get-plugins=true \
|
|
69
|
-
# [-plugin-dir=<plugin_directory>] \
|
|
70
|
-
# -verify-plugins=true \
|
|
71
|
-
# <root_module_directory>
|
|
72
|
-
#
|
|
73
|
-
# ===== Creating a Test Terraform Workspace
|
|
74
|
-
#
|
|
75
|
-
# terraform workspace <new|select> kitchen-terraform-<instance>
|
|
76
|
-
#
|
|
77
|
-
# ==== kitchen destroy
|
|
78
|
-
#
|
|
79
|
-
# A Test Kitchen instance is destroyed through the following steps.
|
|
80
|
-
#
|
|
81
|
-
# ===== Initializing the Terraform Working Directory
|
|
82
|
-
#
|
|
83
|
-
# terraform init \
|
|
84
|
-
# -input=false \
|
|
85
|
-
# -lock=<lock> \
|
|
86
|
-
# -lock-timeout=<lock_timeout>s \
|
|
87
|
-
# [-no-color] \
|
|
88
|
-
# -force-copy \
|
|
89
|
-
# -backend=true \
|
|
90
|
-
# [-backend-config=<backend_configurations.first>...] \
|
|
91
|
-
# -get=true \
|
|
92
|
-
# -get-plugins=true \
|
|
93
|
-
# [-plugin-dir=<plugin_directory>] \
|
|
94
|
-
# -verify-plugins=true \
|
|
95
|
-
# <root_module_directory>
|
|
96
|
-
#
|
|
97
|
-
# ===== Selecting the Test Terraform Workspace
|
|
98
|
-
#
|
|
99
|
-
# terraform workspace <select|new> kitchen-terraform-<instance>
|
|
100
|
-
#
|
|
101
|
-
# ===== Destroying the Terraform State
|
|
102
|
-
#
|
|
103
|
-
# terraform destroy \
|
|
104
|
-
# -auto-approve \
|
|
105
|
-
# -lock=<lock> \
|
|
106
|
-
# -lock-timeout=<lock_timeout>s \
|
|
107
|
-
# -input=false \
|
|
108
|
-
# [-no-color] \
|
|
109
|
-
# -parallelism=<parallelism> \
|
|
110
|
-
# -refresh=true \
|
|
111
|
-
# [-var=<variables.first>...] \
|
|
112
|
-
# [-var-file=<variable_files.first>...] \
|
|
113
|
-
# <root_module_directory>
|
|
114
|
-
#
|
|
115
|
-
# ===== Selecting the Default Terraform Workspace
|
|
116
|
-
#
|
|
117
|
-
# terraform workspace select default
|
|
118
|
-
#
|
|
119
|
-
# ===== Deleting the Test Terraform Workspace
|
|
120
|
-
#
|
|
121
|
-
# terraform workspace delete kitchen-terraform-<instance>
|
|
122
|
-
#
|
|
123
|
-
# === Shelling Out
|
|
124
|
-
#
|
|
125
|
-
# {include:Kitchen::Terraform::ShellOut}
|
|
126
|
-
#
|
|
127
|
-
# === Configuration Attributes
|
|
128
|
-
#
|
|
129
|
-
# The configuration attributes of the driver control the behaviour of the Terraform commands that are run. Within the
|
|
130
|
-
# {http://kitchen.ci/docs/getting-started/kitchen-yml Test Kitchen configuration file}, these attributes must be
|
|
131
|
-
# declared in the +driver+ mapping along with the plugin name.
|
|
132
|
-
#
|
|
133
|
-
# driver:
|
|
134
|
-
# name: terraform
|
|
135
|
-
# a_configuration_attribute: some value
|
|
136
|
-
#
|
|
137
|
-
# ==== backend_configurations
|
|
138
|
-
#
|
|
139
|
-
# {include:Kitchen::Terraform::ConfigAttribute::BackendConfigurations}
|
|
140
|
-
#
|
|
141
|
-
# ==== client
|
|
142
|
-
#
|
|
143
|
-
# {include:Kitchen::Terraform::ConfigAttribute::Client}
|
|
144
|
-
#
|
|
145
|
-
# ==== color
|
|
146
|
-
#
|
|
147
|
-
# {include:Kitchen::Terraform::ConfigAttribute::Color}
|
|
148
|
-
#
|
|
149
|
-
# ==== command_timeout
|
|
150
|
-
#
|
|
151
|
-
# {include:Kitchen::Terraform::ConfigAttribute::CommandTimeout}
|
|
152
|
-
#
|
|
153
|
-
# ==== lock
|
|
154
|
-
#
|
|
155
|
-
# {include:Kitchen::Terraform::ConfigAttribute::Lock}
|
|
156
|
-
#
|
|
157
|
-
# ==== lock_timeout
|
|
158
|
-
#
|
|
159
|
-
# {include:Kitchen::Terraform::ConfigAttribute::LockTimeout}
|
|
160
|
-
#
|
|
161
|
-
# ==== parallelism
|
|
162
|
-
#
|
|
163
|
-
# {include:Kitchen::Terraform::ConfigAttribute::Parallelism}
|
|
164
|
-
#
|
|
165
|
-
# ==== plugin_directory
|
|
166
|
-
#
|
|
167
|
-
# {include:Kitchen::Terraform::ConfigAttribute::PluginDirectory}
|
|
168
|
-
#
|
|
169
|
-
# ==== root_module_directory
|
|
170
|
-
#
|
|
171
|
-
# {include:Kitchen::Terraform::ConfigAttribute::RootModuleDirectory}
|
|
172
|
-
#
|
|
173
|
-
# ==== variable_files
|
|
174
|
-
#
|
|
175
|
-
# {include:Kitchen::Terraform::ConfigAttribute::VariableFiles}
|
|
176
|
-
#
|
|
177
|
-
# ==== variables
|
|
178
|
-
#
|
|
179
|
-
# {include:Kitchen::Terraform::ConfigAttribute::Variables}
|
|
180
|
-
#
|
|
181
|
-
# ==== verify_version
|
|
182
|
-
#
|
|
183
|
-
# {include:Kitchen::Terraform::ConfigAttribute::VerifyVersion}
|
|
184
|
-
#
|
|
185
|
-
# @example Describe the create command
|
|
186
|
-
# kitchen help create
|
|
187
|
-
# @example Create a Test Kitchen instance
|
|
188
|
-
# kitchen create default-ubuntu
|
|
189
|
-
# @example Describe the destroy command
|
|
190
|
-
# kitchen help destroy
|
|
191
|
-
# @example Destroy a Test Kitchen instance
|
|
192
|
-
# kitchen destroy default-ubuntu
|
|
193
|
-
# @version 2
|
|
194
|
-
class ::Kitchen::Driver::Terraform < ::Kitchen::Driver::Base
|
|
195
|
-
kitchen_driver_api_version 2
|
|
196
|
-
|
|
197
|
-
no_parallel_for(
|
|
198
|
-
:create,
|
|
199
|
-
:converge,
|
|
200
|
-
:setup,
|
|
201
|
-
:destroy
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
include ::Kitchen::Terraform::ConfigAttribute::BackendConfigurations
|
|
205
|
-
|
|
206
|
-
include ::Kitchen::Terraform::ConfigAttribute::Client
|
|
207
|
-
|
|
208
|
-
include ::Kitchen::Terraform::ConfigAttribute::Color
|
|
209
|
-
|
|
210
|
-
include ::Kitchen::Terraform::ConfigAttribute::CommandTimeout
|
|
211
|
-
|
|
212
|
-
include ::Kitchen::Terraform::ConfigAttribute::Lock
|
|
213
|
-
|
|
214
|
-
include ::Kitchen::Terraform::ConfigAttribute::LockTimeout
|
|
215
|
-
|
|
216
|
-
include ::Kitchen::Terraform::ConfigAttribute::Parallelism
|
|
217
|
-
|
|
218
|
-
include ::Kitchen::Terraform::ConfigAttribute::PluginDirectory
|
|
219
|
-
|
|
220
|
-
include ::Kitchen::Terraform::ConfigAttribute::RootModuleDirectory
|
|
221
|
-
|
|
222
|
-
include ::Kitchen::Terraform::ConfigAttribute::VariableFiles
|
|
223
|
-
|
|
224
|
-
include ::Kitchen::Terraform::ConfigAttribute::Variables
|
|
225
|
-
|
|
226
|
-
include ::Kitchen::Terraform::ConfigAttribute::VerifyVersion
|
|
227
|
-
|
|
228
|
-
include ::Kitchen::Terraform::Configurable
|
|
229
|
-
|
|
230
|
-
# Applies changes to the state by selecting the test workspace, updating the dependency modules, validating the root
|
|
231
|
-
# module, and applying the state changes.
|
|
232
|
-
#
|
|
233
|
-
# @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
|
|
234
|
-
# @return [void]
|
|
235
|
-
def apply(&block)
|
|
236
|
-
verify_version
|
|
237
|
-
run_workspace_select_instance
|
|
238
|
-
apply_run
|
|
239
|
-
rescue ::Kitchen::Terraform::Error => error
|
|
240
|
-
raise ::Kitchen::ActionFailed, error.message
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
# Creates a Test Kitchen instance by initializing the working directory and creating a test workspace.
|
|
244
|
-
#
|
|
245
|
-
# @param _state [::Hash] the mutable instance and driver state.
|
|
246
|
-
# @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
|
|
247
|
-
# @return [void]
|
|
248
|
-
def create(_state)
|
|
249
|
-
verify_version
|
|
250
|
-
create_run_init
|
|
251
|
-
run_workspace_select_instance
|
|
252
|
-
rescue ::Kitchen::Terraform::Error => error
|
|
253
|
-
raise ::Kitchen::ActionFailed, error.message
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
# Destroys a Test Kitchen instance by initializing the working directory, selecting the test workspace,
|
|
257
|
-
# deleting the state, selecting the default workspace, and deleting the test workspace.
|
|
258
|
-
#
|
|
259
|
-
# @param _state [::Hash] the mutable instance and driver state.
|
|
260
|
-
# @raise [::Kitchen::ActionFailed] if the result of the action is a failure.
|
|
261
|
-
# @return [void]
|
|
262
|
-
def destroy(_state)
|
|
263
|
-
verify_version
|
|
264
|
-
destroy_run_init
|
|
265
|
-
run_workspace_select_instance
|
|
266
|
-
destroy_run_destroy
|
|
267
|
-
destroy_run_workspace_select_default
|
|
268
|
-
destroy_run_workspace_delete_instance
|
|
269
|
-
rescue ::Kitchen::Terraform::Error => error
|
|
270
|
-
raise ::Kitchen::ActionFailed, error.message
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
# Retrieves the Terraform input variables for a Kitchen instance provided by the configuration.
|
|
274
|
-
#
|
|
275
|
-
# @return [self]
|
|
276
|
-
# @yieldparam inputs [::Hash] the input variables.
|
|
277
|
-
def retrieve_inputs
|
|
278
|
-
yield inputs: config_variables
|
|
279
|
-
|
|
280
|
-
self
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
# Retrieves the Terraform state outputs for a Kitchen instance by selecting the test workspace and fetching the
|
|
284
|
-
# outputs.
|
|
40
|
+
# @see http://www.rubydoc.info/gems/test-kitchen/Kitchen
|
|
41
|
+
module Kitchen
|
|
42
|
+
# This namespace is defined by Kitchen.
|
|
285
43
|
#
|
|
286
|
-
# @
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
::Kitchen::
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
def initialize(config = {})
|
|
474
|
-
super
|
|
475
|
-
self.debug_logger = ::Kitchen::Terraform::DebugLogger.new logger
|
|
476
|
-
end
|
|
477
|
-
|
|
478
|
-
# @api private
|
|
479
|
-
def lock_flag
|
|
480
|
-
"-lock=#{config_lock}"
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
# @api private
|
|
484
|
-
def lock_timeout_flag
|
|
485
|
-
"-lock-timeout=#{config_lock_timeout}s"
|
|
486
|
-
end
|
|
487
|
-
|
|
488
|
-
# @api private
|
|
489
|
-
def parallelism_flag
|
|
490
|
-
"-parallelism=#{config_parallelism}"
|
|
491
|
-
end
|
|
492
|
-
|
|
493
|
-
# @api private
|
|
494
|
-
def plugin_directory_flag
|
|
495
|
-
if config_plugin_directory
|
|
496
|
-
"-plugin-dir=\"#{::Shellwords.shelljoin ::Shellwords.shellsplit config_plugin_directory}\" "
|
|
497
|
-
else
|
|
498
|
-
""
|
|
499
|
-
end
|
|
500
|
-
end
|
|
501
|
-
|
|
502
|
-
# @api private
|
|
503
|
-
def run_workspace_select_instance
|
|
504
|
-
::Kitchen::Terraform::ShellOut.run(
|
|
505
|
-
client: config_client,
|
|
506
|
-
command: "workspace select #{workspace_name}",
|
|
507
|
-
options: {
|
|
508
|
-
cwd: config_root_module_directory,
|
|
509
|
-
live_stream: logger,
|
|
510
|
-
timeout: config_command_timeout,
|
|
511
|
-
},
|
|
512
|
-
)
|
|
513
|
-
rescue ::Kitchen::Terraform::Error
|
|
514
|
-
::Kitchen::Terraform::ShellOut.run(
|
|
515
|
-
client: config_client,
|
|
516
|
-
command: "workspace new #{workspace_name}",
|
|
517
|
-
options: {
|
|
518
|
-
cwd: config_root_module_directory,
|
|
519
|
-
live_stream: logger,
|
|
520
|
-
timeout: config_command_timeout,
|
|
521
|
-
},
|
|
522
|
-
)
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
# @api private
|
|
526
|
-
def variable_files_flags
|
|
527
|
-
config_variable_files.map do |path|
|
|
528
|
-
"-var-file=\"#{::Shellwords.shelljoin ::Shellwords.shellsplit path}\""
|
|
529
|
-
end.join " "
|
|
530
|
-
end
|
|
531
|
-
|
|
532
|
-
# @api private
|
|
533
|
-
def variables_flags
|
|
534
|
-
config_variables.map do |key, value|
|
|
535
|
-
"-var=\"#{key}=#{value}\""
|
|
536
|
-
end.join " "
|
|
537
|
-
end
|
|
538
|
-
|
|
539
|
-
def verify_version
|
|
540
|
-
if config_verify_version
|
|
541
|
-
::Kitchen::Terraform::VerifyVersion.call
|
|
542
|
-
else
|
|
543
|
-
logger.warn "Verification of support for the available version of Terraform is disabled"
|
|
44
|
+
# @see http://www.rubydoc.info/gems/test-kitchen/Kitchen/Driver
|
|
45
|
+
module Driver
|
|
46
|
+
|
|
47
|
+
# The driver is the bridge between Test Kitchen and Terraform. It manages the
|
|
48
|
+
# {https://www.terraform.io/docs/state/index.html state} of the Terraform root module by shelling out and running
|
|
49
|
+
# Terraform commands.
|
|
50
|
+
#
|
|
51
|
+
# === Commands
|
|
52
|
+
#
|
|
53
|
+
# The following command-line commands are provided by the driver.
|
|
54
|
+
#
|
|
55
|
+
# ==== kitchen create
|
|
56
|
+
#
|
|
57
|
+
# {include:Kitchen::Terraform::Driver::Create}
|
|
58
|
+
#
|
|
59
|
+
# ==== kitchen destroy
|
|
60
|
+
#
|
|
61
|
+
# {include:Kitchen::Terraform::Driver::Destroy}
|
|
62
|
+
#
|
|
63
|
+
# === Configuration Attributes
|
|
64
|
+
#
|
|
65
|
+
# The configuration attributes of the driver control the behaviour of the Terraform commands that are run. Within the
|
|
66
|
+
# {http://kitchen.ci/docs/getting-started/kitchen-yml Test Kitchen configuration file}, these attributes must be
|
|
67
|
+
# declared in the +driver+ mapping along with the plugin name.
|
|
68
|
+
#
|
|
69
|
+
# driver:
|
|
70
|
+
# name: terraform
|
|
71
|
+
# a_configuration_attribute: some value
|
|
72
|
+
#
|
|
73
|
+
# ==== backend_configurations
|
|
74
|
+
#
|
|
75
|
+
# {include:Kitchen::Terraform::ConfigAttribute::BackendConfigurations}
|
|
76
|
+
#
|
|
77
|
+
# ==== client
|
|
78
|
+
#
|
|
79
|
+
# {include:Kitchen::Terraform::ConfigAttribute::Client}
|
|
80
|
+
#
|
|
81
|
+
# ==== color
|
|
82
|
+
#
|
|
83
|
+
# {include:Kitchen::Terraform::ConfigAttribute::Color}
|
|
84
|
+
#
|
|
85
|
+
# ==== command_timeout
|
|
86
|
+
#
|
|
87
|
+
# {include:Kitchen::Terraform::ConfigAttribute::CommandTimeout}
|
|
88
|
+
#
|
|
89
|
+
# ==== lock
|
|
90
|
+
#
|
|
91
|
+
# {include:Kitchen::Terraform::ConfigAttribute::Lock}
|
|
92
|
+
#
|
|
93
|
+
# ==== lock_timeout
|
|
94
|
+
#
|
|
95
|
+
# {include:Kitchen::Terraform::ConfigAttribute::LockTimeout}
|
|
96
|
+
#
|
|
97
|
+
# ==== parallelism
|
|
98
|
+
#
|
|
99
|
+
# {include:Kitchen::Terraform::ConfigAttribute::Parallelism}
|
|
100
|
+
#
|
|
101
|
+
# ==== plugin_directory
|
|
102
|
+
#
|
|
103
|
+
# {include:Kitchen::Terraform::ConfigAttribute::PluginDirectory}
|
|
104
|
+
#
|
|
105
|
+
# ==== root_module_directory
|
|
106
|
+
#
|
|
107
|
+
# {include:Kitchen::Terraform::ConfigAttribute::RootModuleDirectory}
|
|
108
|
+
#
|
|
109
|
+
# ==== variable_files
|
|
110
|
+
#
|
|
111
|
+
# {include:Kitchen::Terraform::ConfigAttribute::VariableFiles}
|
|
112
|
+
#
|
|
113
|
+
# ==== variables
|
|
114
|
+
#
|
|
115
|
+
# {include:Kitchen::Terraform::ConfigAttribute::Variables}
|
|
116
|
+
#
|
|
117
|
+
# ==== verify_version
|
|
118
|
+
#
|
|
119
|
+
# {include:Kitchen::Terraform::ConfigAttribute::VerifyVersion}
|
|
120
|
+
#
|
|
121
|
+
# === Ruby Interface
|
|
122
|
+
#
|
|
123
|
+
# This class implements the interface of Kitchen::Configurable which requires the following Reek suppressions:
|
|
124
|
+
# :reek:MissingSafeMethod { exclude: [ finalize_config! ] }
|
|
125
|
+
#
|
|
126
|
+
# @example Describe the create command
|
|
127
|
+
# kitchen help create
|
|
128
|
+
# @example Create a Test Kitchen instance
|
|
129
|
+
# kitchen create default-ubuntu
|
|
130
|
+
# @example Describe the destroy command
|
|
131
|
+
# kitchen help destroy
|
|
132
|
+
# @example Destroy a Test Kitchen instance
|
|
133
|
+
# kitchen destroy default-ubuntu
|
|
134
|
+
# @version 2
|
|
135
|
+
class Terraform < ::Kitchen::Driver::Base
|
|
136
|
+
kitchen_driver_api_version 2
|
|
137
|
+
|
|
138
|
+
no_parallel_for(
|
|
139
|
+
:create,
|
|
140
|
+
:converge,
|
|
141
|
+
:setup,
|
|
142
|
+
:destroy
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
include ::Kitchen::Terraform::ConfigAttribute::BackendConfigurations
|
|
146
|
+
|
|
147
|
+
include ::Kitchen::Terraform::ConfigAttribute::Client
|
|
148
|
+
|
|
149
|
+
include ::Kitchen::Terraform::ConfigAttribute::Color
|
|
150
|
+
|
|
151
|
+
include ::Kitchen::Terraform::ConfigAttribute::CommandTimeout
|
|
152
|
+
|
|
153
|
+
include ::Kitchen::Terraform::ConfigAttribute::Lock
|
|
154
|
+
|
|
155
|
+
include ::Kitchen::Terraform::ConfigAttribute::LockTimeout
|
|
156
|
+
|
|
157
|
+
include ::Kitchen::Terraform::ConfigAttribute::Parallelism
|
|
158
|
+
|
|
159
|
+
include ::Kitchen::Terraform::ConfigAttribute::PluginDirectory
|
|
160
|
+
|
|
161
|
+
include ::Kitchen::Terraform::ConfigAttribute::RootModuleDirectory
|
|
162
|
+
|
|
163
|
+
include ::Kitchen::Terraform::ConfigAttribute::VariableFiles
|
|
164
|
+
|
|
165
|
+
include ::Kitchen::Terraform::ConfigAttribute::Variables
|
|
166
|
+
|
|
167
|
+
include ::Kitchen::Terraform::ConfigAttribute::VerifyVersion
|
|
168
|
+
|
|
169
|
+
include ::Kitchen::Terraform::Configurable
|
|
170
|
+
|
|
171
|
+
# Creates a Test Kitchen instance by initializing the working directory and creating a test workspace.
|
|
172
|
+
#
|
|
173
|
+
# @param _state [Hash] the mutable instance and driver state.
|
|
174
|
+
# @raise [Kitchen::ActionFailed] if the result of the action is a failure.
|
|
175
|
+
# @return [void]
|
|
176
|
+
def create(_state)
|
|
177
|
+
create_strategy.call
|
|
178
|
+
rescue => error
|
|
179
|
+
action_failed.call message: error.message
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Destroys a Test Kitchen instance by initializing the working directory, selecting the test workspace,
|
|
183
|
+
# deleting the state, selecting the default workspace, and deleting the test workspace.
|
|
184
|
+
#
|
|
185
|
+
# @param _state [Hash] the mutable instance and driver state.
|
|
186
|
+
# @raise [Kitchen::ActionFailed] if the result of the action is a failure.
|
|
187
|
+
# @return [void]
|
|
188
|
+
def destroy(_state)
|
|
189
|
+
destroy_strategy.call
|
|
190
|
+
rescue => error
|
|
191
|
+
action_failed.call message: error.message
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# #finalize_config! invokes the super implementation and then initializes the strategies.
|
|
195
|
+
#
|
|
196
|
+
# @param instance [Kitchen::Instance] an associated instance.
|
|
197
|
+
# @raise [Kitchen::ClientError] if the instance is nil.
|
|
198
|
+
# @return [self]
|
|
199
|
+
# @see Kitchen::Configurable#finalize_config!
|
|
200
|
+
def finalize_config!(instance)
|
|
201
|
+
super instance
|
|
202
|
+
self.create_strategy = ::Kitchen::Terraform::Driver::Create.new(
|
|
203
|
+
config: config,
|
|
204
|
+
logger: logger,
|
|
205
|
+
version_requirement: version_requirement,
|
|
206
|
+
workspace_name: workspace_name,
|
|
207
|
+
)
|
|
208
|
+
self.destroy_strategy = ::Kitchen::Terraform::Driver::Destroy.new(
|
|
209
|
+
config: config,
|
|
210
|
+
logger: logger,
|
|
211
|
+
version_requirement: version_requirement,
|
|
212
|
+
workspace_name: workspace_name,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
self
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# #initialize prepares a new instance of the class.
|
|
219
|
+
#
|
|
220
|
+
# @param config [Hash] the driver configuration.
|
|
221
|
+
# @return [Kitchen::Driver::Terraform]
|
|
222
|
+
def initialize(config = {})
|
|
223
|
+
super config
|
|
224
|
+
self.action_failed = ::Kitchen::Terraform::Raise::ActionFailed.new logger: logger
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
private
|
|
228
|
+
|
|
229
|
+
attr_accessor :action_failed, :create_strategy, :destroy_strategy
|
|
544
230
|
end
|
|
545
231
|
end
|
|
546
|
-
|
|
547
|
-
def workspace_name
|
|
548
|
-
@workspace_name ||= "kitchen-terraform-#{::Shellwords.escape instance.name}"
|
|
549
|
-
end
|
|
550
232
|
end
|