kitchen-terraform 5.1.0 → 5.5.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 +48 -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 +139 -62
- 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: 83839e8130c2a9767f6fd28f5fc7f382ccdc6af319b00e1d282b6bb1f8e089f2
|
|
4
|
+
data.tar.gz: 39d379b085ec51381c80cdf7cc243fdc56cba9f10844e04c012eea6f6d18cf94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f800c55453edf301d0f9227d674922ad5f7df5c1b04e704f838ac88128cf02198ac7ade685e51b078b14f936ba057d25ec48d91737eaf3a8063ebd6e0c9311a7
|
|
7
|
+
data.tar.gz: 6403f2e106f88463cf2edc6a4d4dc2ee5aba68b3c7c62fd5e2b01797b654f041859548b79d9d2538c66bd2ccded02a9ec083a23b919c4882f1d842e4ff278d06
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ![Kitchen-Terraform Logo][kitchen-terraform-logo] Kitchen-Terraform
|
|
2
2
|
|
|
3
|
-
> Kitchen-Terraform enables verification of Terraform
|
|
3
|
+
> Kitchen-Terraform enables verification of infrastructure systems provisioned with Terraform.
|
|
4
4
|
|
|
5
5
|
[![Gem version][gem-version-shield]][kitchen-terraform-gem]
|
|
6
6
|
[![Gem downloads version][gem-downloads-version-shield]][kitchen-terraform-gem]
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
[![Gitter chat][gitter-shield]][gitter]
|
|
17
17
|
|
|
18
|
-
Kitchen-Terraform provides a set of [
|
|
19
|
-
which enable
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
Kitchen-Terraform provides a set of [Kitchen][kitchen] plugins
|
|
19
|
+
which enable the use of Kitchen to converge a [Terraform][terraform]
|
|
20
|
+
configuration and verify the resulting infrastructure systems with
|
|
21
|
+
[InSpec][inspec] controls.
|
|
22
22
|
|
|
23
23
|
As Kitchen-Terraform integrates several distinctive technologies in a
|
|
24
24
|
nontrivial manner, reviewing the documentation of each of the
|
|
@@ -36,7 +36,7 @@ Installation instructions can be found in the
|
|
|
36
36
|
[Terraform: Install Terraform][terraform-install] article.
|
|
37
37
|
|
|
38
38
|
Kitchen-Terraform supports versions of Terraform in the interval of
|
|
39
|
-
`>= 0.11.4, < 0.
|
|
39
|
+
`>= 0.11.4, < 0.14.0`.
|
|
40
40
|
|
|
41
41
|
[tfenv] can be used to manage versions of Terraform on the system.
|
|
42
42
|
|
|
@@ -50,7 +50,7 @@ Installation instructions can be found in the
|
|
|
50
50
|
|
|
51
51
|
Kitchen-Terraform aims to support all versions of Ruby that are in
|
|
52
52
|
["normal" or "security" maintenance][ruby-branches], which is currently
|
|
53
|
-
the interval of `>= 2.4, < 2.
|
|
53
|
+
the interval of `>= 2.4, < 2.8`.
|
|
54
54
|
|
|
55
55
|
[rbenv] can be used to manage versions of Ruby on the system.
|
|
56
56
|
|
|
@@ -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.5"
|
|
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.5.0
|
|
109
106
|
```
|
|
110
107
|
|
|
111
108
|
This approach is not recommended as it requires more effort to install
|
|
@@ -115,13 +112,23 @@ conflicts.
|
|
|
115
112
|
More information can be found in the
|
|
116
113
|
[RubyGems: Installing Gems][rubygems-installing-gems] article.
|
|
117
114
|
|
|
115
|
+
#### Extra Dependencies
|
|
116
|
+
|
|
117
|
+
The RbNaCl gem may need to be [installed][rbnacl-installation] in order
|
|
118
|
+
to use Ed25519-type SSH keys to connect to systems with the SSH backend.
|
|
119
|
+
This gem implicitly depends on the system package libsodium, and its
|
|
120
|
+
presence when libsodium is not installed causes unexpected errors when
|
|
121
|
+
loading InSpec transport plugins like GCP, so it is not included by
|
|
122
|
+
default to reduce the burden on users whom do not require support for
|
|
123
|
+
Ed25519-type SSH keys.
|
|
124
|
+
|
|
118
125
|
## Usage
|
|
119
126
|
|
|
120
127
|
### Configuration
|
|
121
128
|
|
|
122
129
|
Kitchen-Terraform provides three Test Kitchen plugins which must be
|
|
123
130
|
configured in a
|
|
124
|
-
[
|
|
131
|
+
[Kitchen configuration file][kitchen-configuration-file] in
|
|
125
132
|
order to successfully test Terraform configuration.
|
|
126
133
|
|
|
127
134
|
The [Terraform driver][terraform-driver] manages the state of the
|
|
@@ -136,166 +143,27 @@ Terraform state.
|
|
|
136
143
|
More information can be found in the
|
|
137
144
|
[Ruby gem documentation][ruby-gem-documentation].
|
|
138
145
|
|
|
139
|
-
###
|
|
140
|
-
|
|
141
|
-
This example demonstrates how to test a simple Terraform configuration
|
|
142
|
-
which utilizes the [Docker provider][docker-provider].
|
|
143
|
-
|
|
144
|
-
The test system is assumed to be running Ubuntu 17.04.
|
|
145
|
-
|
|
146
|
-
Terraform, Ruby, and Bundler are assumed to have been installed on the
|
|
147
|
-
test system as described in the [Installation](#installation) section.
|
|
148
|
-
|
|
149
|
-
The [Docker Community Edition][docker-community-edition] is assumed to
|
|
150
|
-
have been installed on the test system.
|
|
151
|
-
|
|
152
|
-
The working directory on the test system is assumed to contain a
|
|
153
|
-
hierarchy of files comprising the following blocks.
|
|
154
|
-
|
|
155
|
-
> Directory hierarchy
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
.
|
|
159
|
-
├── .kitchen.yml
|
|
160
|
-
├── Gemfile
|
|
161
|
-
├── main.tf
|
|
162
|
-
├── outputs.tf
|
|
163
|
-
└── test
|
|
164
|
-
└── integration
|
|
165
|
-
└── example
|
|
166
|
-
├── controls
|
|
167
|
-
│ ├── operating_system.rb
|
|
168
|
-
└── inspec.yml
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
> Gemfile
|
|
172
|
-
|
|
173
|
-
```ruby
|
|
174
|
-
source "https://rubygems.org/"
|
|
175
|
-
|
|
176
|
-
gem 'kitchen-terraform'
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
> ./.kitchen.yml (Test Kitchen configuration)
|
|
180
|
-
|
|
181
|
-
```yaml
|
|
182
|
-
driver:
|
|
183
|
-
name: terraform
|
|
184
|
-
|
|
185
|
-
provisioner:
|
|
186
|
-
name: terraform
|
|
187
|
-
|
|
188
|
-
verifier:
|
|
189
|
-
name: terraform
|
|
190
|
-
systems:
|
|
191
|
-
- name: container
|
|
192
|
-
backend: ssh
|
|
193
|
-
hosts_output: container_hostname
|
|
194
|
-
password: root
|
|
195
|
-
port: 2222
|
|
196
|
-
user: root
|
|
197
|
-
|
|
198
|
-
platforms:
|
|
199
|
-
- name: ubuntu
|
|
200
|
-
|
|
201
|
-
suites:
|
|
202
|
-
- name: example
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
> ./main.tf
|
|
206
|
-
|
|
207
|
-
```hcl
|
|
208
|
-
provider "docker" {
|
|
209
|
-
host = "unix://localhost/var/run/docker.sock"
|
|
210
|
-
}
|
|
146
|
+
### Caveats
|
|
211
147
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
148
|
+
Versions of Terraform in the 0.11 series may cause `kitchen test` to
|
|
149
|
+
fail if the initial destroy targets an empty Terraform state. A
|
|
150
|
+
workaround for this problem is to use
|
|
151
|
+
`kitchen verify && kitchen destroy` instead of `kitchen test`. More
|
|
152
|
+
details about the problem are available in
|
|
153
|
+
[issue #271](issue-271).
|
|
215
154
|
|
|
216
|
-
|
|
217
|
-
name = "${data.docker_registry_image.ubuntu.name}"
|
|
218
|
-
pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"]
|
|
219
|
-
}
|
|
155
|
+
### Tutorials and Examples
|
|
220
156
|
|
|
221
|
-
|
|
222
|
-
image = "${docker_image.ubuntu.name}"
|
|
223
|
-
must_run = true
|
|
224
|
-
name = "ubuntu_container"
|
|
225
|
-
|
|
226
|
-
ports {
|
|
227
|
-
external = 2222
|
|
228
|
-
internal = 22
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
> ./outputs.tf
|
|
234
|
-
|
|
235
|
-
```hcl
|
|
236
|
-
output "container_hostname" {
|
|
237
|
-
description = "The hostname of the container."
|
|
238
|
-
value = "127.0.0.1"
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
> ./test/integration/example/inspec.yml
|
|
243
|
-
|
|
244
|
-
```yaml
|
|
245
|
-
name: example
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
> ./test/integration/example/controls/operating_system.rb
|
|
249
|
-
|
|
250
|
-
```ruby
|
|
251
|
-
# frozen_string_literal: true
|
|
252
|
-
|
|
253
|
-
control "operating_system" do
|
|
254
|
-
describe "the operating system" do
|
|
255
|
-
subject do
|
|
256
|
-
command("cat /etc/os-release").stdout
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it "is Ubuntu" do
|
|
260
|
-
is_expected.to match /Ubuntu/
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
Running the following command would initialize the working directory for
|
|
267
|
-
Terraform, create a Docker container by applying the configuration file,
|
|
268
|
-
and verify that the container is running Ubuntu.
|
|
269
|
-
|
|
270
|
-
> Verifying with Kitchen-Terraform
|
|
271
|
-
|
|
272
|
-
```sh
|
|
273
|
-
$ bundle install
|
|
274
|
-
$ bundle exec kitchen test
|
|
275
|
-
-----> Starting Kitchen...
|
|
276
|
-
...
|
|
277
|
-
$$$$$$ Running command `terraform init...`
|
|
278
|
-
...
|
|
279
|
-
$$$$$$ Running command `terraform apply...`
|
|
280
|
-
...
|
|
281
|
-
docker_container.ubuntu: Creation complete after 1s...
|
|
282
|
-
|
|
283
|
-
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
|
|
284
|
-
...
|
|
285
|
-
Finished converging <example-ubuntu>...
|
|
286
|
-
...
|
|
287
|
-
-----> Verifying <example-ubuntu>...
|
|
288
|
-
Verifying host 'localhost' of system 'container'
|
|
289
|
-
...
|
|
290
|
-
✔ operating_system: the operating system is Ubuntu
|
|
291
|
-
...
|
|
292
|
-
Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
|
|
293
|
-
...
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
More information can be found on the
|
|
157
|
+
Several tutorials are available on the
|
|
297
158
|
[Kitchen-Terraform Tutorials][kitchen-terraform-tutorials] page.
|
|
298
159
|
|
|
160
|
+
The integration tests for Kitchen-Terraform can also be viewed as
|
|
161
|
+
examples of how it works. The
|
|
162
|
+
[integration test Kitchen configuration file][int-kitchen-config]
|
|
163
|
+
and the [integration test directory][test-directory] provide several
|
|
164
|
+
functional examples which exercise various features of
|
|
165
|
+
Kitchen-Terraform.
|
|
166
|
+
|
|
299
167
|
## Contributing
|
|
300
168
|
|
|
301
169
|
Kitchen-Terraform thrives on community contributions.
|
|
@@ -313,7 +181,8 @@ Information about changes to Kitchen-Terraform can be found in the
|
|
|
313
181
|
|
|
314
182
|
## Maintainers
|
|
315
183
|
|
|
316
|
-
Kitchen-Terraform is maintained by
|
|
184
|
+
Kitchen-Terraform is maintained by [community contributors][contributors]
|
|
185
|
+
and New Context.
|
|
317
186
|
|
|
318
187
|
<img
|
|
319
188
|
alt="New Context logo"
|
|
@@ -366,17 +235,22 @@ Kitchen-Terraform is distributed under the [Apache License][license].
|
|
|
366
235
|
[code-coverage-shield]: https://img.shields.io/codeclimate/coverage/newcontext-oss/kitchen-terraform.svg
|
|
367
236
|
[code-coverage]: https://codeclimate.com/github/newcontext-oss/kitchen-terraform/
|
|
368
237
|
[contributing-document]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/CONTRIBUTING.md
|
|
238
|
+
[contributors]: https://github.com/newcontext-oss/kitchen-terraform/graphs/contributors
|
|
369
239
|
[docker]: https://www.docker.com/
|
|
370
240
|
[docker-community-edition]: https://store.docker.com/editions/community/docker-ce-server-ubuntu
|
|
371
241
|
[docker-provider]: https://www.terraform.io/docs/providers/docker/index.html
|
|
372
242
|
[gem-downloads-total-shield]: https://img.shields.io/gem/dt/kitchen-terraform.svg
|
|
373
243
|
[gem-downloads-version-shield]: https://img.shields.io/gem/dtv/kitchen-terraform.svg
|
|
374
244
|
[gem-version-shield]: https://img.shields.io/gem/v/kitchen-terraform.svg
|
|
375
|
-
[hakiri-shield]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/master.svg
|
|
376
|
-
[hakiri]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/
|
|
377
245
|
[gitter-shield]: https://img.shields.io/gitter/room/kitchen-terraform/Lobby.svg
|
|
378
246
|
[gitter]: https://gitter.im/kitchen-terraform/Lobby
|
|
247
|
+
[hakiri-shield]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/master.svg
|
|
248
|
+
[hakiri]: https://hakiri.io/github/newcontext-oss/kitchen-terraform/
|
|
379
249
|
[inspec]: https://www.inspec.io/
|
|
250
|
+
[int-kitchen-config]: https://github.com/newcontext-oss/kitchen-terraform/blob/master/kitchen.yml
|
|
251
|
+
[issue-271]: https://github.com/newcontext-oss/kitchen-terraform/issues/271
|
|
252
|
+
[kitchen]: http://kitchen.ci/index.html
|
|
253
|
+
[kitchen-configuration-file]: https://docs.chef.io/config_yml_kitchen.html
|
|
380
254
|
[kitchen-terraform-gem]: https://rubygems.org/gems/kitchen-terraform
|
|
381
255
|
[kitchen-terraform-logo]: https://raw.githubusercontent.com/newcontext-oss/kitchen-terraform/master/assets/logo.png
|
|
382
256
|
[kitchen-terraform-tutorials]: https://newcontext-oss.github.io/kitchen-terraform/tutorials/
|
|
@@ -388,6 +262,7 @@ Kitchen-Terraform is distributed under the [Apache License][license].
|
|
|
388
262
|
[new-context-twitter]: https://twitter.com/newcontext
|
|
389
263
|
[new-context]: https://newcontext.com/
|
|
390
264
|
[rbenv]: https://github.com/rbenv/rbenv
|
|
265
|
+
[rbnacl-installation]: https://github.com/crypto-rb/rbnacl/tree/v4.0.2#installation
|
|
391
266
|
[ruby-branches]: https://www.ruby-lang.org/en/downloads/branches/
|
|
392
267
|
[ruby-gem-documentation]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/
|
|
393
268
|
[ruby-gems-what-is]: http://guides.rubygems.org/ruby-gems-what-is/index.html
|
|
@@ -402,8 +277,8 @@ Kitchen-Terraform is distributed under the [Apache License][license].
|
|
|
402
277
|
[terraform-provisioner]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Provisioner/Terraform
|
|
403
278
|
[terraform-verifier]: http://www.rubydoc.info/github/newcontext-oss/kitchen-terraform/Kitchen/Verifier/Terraform
|
|
404
279
|
[terraform]: https://www.terraform.io/
|
|
405
|
-
[test-
|
|
406
|
-
[test-kitchen]: http://kitchen.ci/index.html
|
|
280
|
+
[test-directory]: https://github.com/newcontext-oss/kitchen-terraform/tree/master/test
|
|
407
281
|
[tfenv]: https://github.com/kamatama41/tfenv
|
|
408
282
|
[travis-build-status-shield]: https://img.shields.io/travis/com/newcontext-oss/kitchen-terraform.svg
|
|
409
283
|
[travis-build-status]: https://travis-ci.com/newcontext-oss/kitchen-terraform
|
|
284
|
+
|
|
@@ -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
|