kitchen-terraform 5.7.2 → 5.8.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 +2 -2
- data/lib/kitchen/terraform/command/init.rb +2 -79
- data/lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb +89 -0
- data/lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb +101 -0
- data/lib/kitchen/terraform/command/init_factory.rb +52 -0
- data/lib/kitchen/terraform/command/validate.rb +2 -40
- data/lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb +51 -0
- data/lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb +65 -0
- data/lib/kitchen/terraform/command/validate_factory.rb +54 -0
- data/lib/kitchen/terraform/command_flag/upgrade.rb +1 -1
- data/lib/kitchen/terraform/configurable.rb +1 -1
- data/lib/kitchen/terraform/driver/create.rb +36 -13
- data/lib/kitchen/terraform/driver/destroy.rb +43 -19
- data/lib/kitchen/terraform/inspec_runner.rb +1 -1
- data/lib/kitchen/terraform/provisioner/converge.rb +48 -21
- data/lib/kitchen/terraform/verify_version.rb +4 -16
- data/lib/kitchen/terraform/version.rb +1 -1
- metadata +10 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 449214862b898292af37271daa4aa2926650f252544bd1d72b778f5402631653
|
|
4
|
+
data.tar.gz: c7ea868e644097ff0302c12264a98d205da4368d30f926d860779fb5cf88bb98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98e59c3a77923430fbff7319968572174c54e52bcb987750e92a70e4dc35a74c8c590422d5467048fbda7480e2bb2d95710cbe6e5b3f576bd071038ba2e135ce
|
|
7
|
+
data.tar.gz: 6279a30cecd3b277bcac512c6da9c80b91f8fd7e6aa307876206161171e773291c94fe406b8ef88b00cd35a3b0745008b3b3a1324cd4a5e78844801b96ac7378
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -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, <
|
|
39
|
+
`>= 0.11.4, < 1.1.0`.
|
|
40
40
|
|
|
41
41
|
[tfenv] can be used to manage versions of Terraform on the system.
|
|
42
42
|
|
|
@@ -102,7 +102,7 @@ example.
|
|
|
102
102
|
> Installing Kitchen-Terraform with RubyGems
|
|
103
103
|
|
|
104
104
|
```sh
|
|
105
|
-
gem install kitchen-terraform --version 5.
|
|
105
|
+
gem install kitchen-terraform --version 5.8.0
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
This approach is not recommended as it requires more effort to install
|
|
@@ -14,88 +14,11 @@
|
|
|
14
14
|
# See the License for the specific language governing permissions and
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
|
-
require "kitchen/terraform/command_flag/backend_config"
|
|
18
|
-
require "kitchen/terraform/command_flag/color"
|
|
19
|
-
require "kitchen/terraform/command_flag/lock_timeout"
|
|
20
|
-
require "kitchen/terraform/command_flag/plugin_dir"
|
|
21
|
-
require "kitchen/terraform/command_flag/upgrade"
|
|
22
|
-
|
|
23
17
|
module Kitchen
|
|
24
18
|
module Terraform
|
|
25
19
|
module Command
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
# -input=false \
|
|
29
|
-
# -lock=<lock> \
|
|
30
|
-
# -lock-timeout=<lock_timeout>s \
|
|
31
|
-
# [-no-color] \
|
|
32
|
-
# [-upgrade] \
|
|
33
|
-
# -force-copy \
|
|
34
|
-
# -backend=true \
|
|
35
|
-
# [-backend-config=<backend_configurations[0]> ...] \
|
|
36
|
-
# -get=true \
|
|
37
|
-
# -get-plugins=true \
|
|
38
|
-
# [-plugin-dir=<plugin_directory>] \
|
|
39
|
-
# -verify-plugins=true \
|
|
40
|
-
# <root_module_directory>
|
|
41
|
-
class Init
|
|
42
|
-
# #initialize prepares a new instance of the class.
|
|
43
|
-
#
|
|
44
|
-
# @param config [Hash] the configuration of the driver.
|
|
45
|
-
# @option config [Hash{String=>String}] :backend_configurations Terraform backend configuration arguments to
|
|
46
|
-
# complete a partial backend configuration.
|
|
47
|
-
# @option config [Boolean] :color a toggle of colored output from the Terraform client.
|
|
48
|
-
# @option config [Integer] :command_timeout the the number of seconds to wait for the command to finish running.
|
|
49
|
-
# @option config [Boolean] :lock a toggle of locking for the Terraform state file.
|
|
50
|
-
# @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock
|
|
51
|
-
# on the state to be obtained during operations.
|
|
52
|
-
# @option config [String] :plugin_directory the pathname of the directory which contains
|
|
53
|
-
# customized Terraform provider plugins to install in place of the official Terraform provider plugins.
|
|
54
|
-
# @option config [String] :root_module_directory the pathname of the directory which contains the root
|
|
55
|
-
# Terraform module.
|
|
56
|
-
# @option config [Boolean] :upgrade_during_init a toggle for upgrading modules and plugins.
|
|
57
|
-
# @return [Kitchen::Terraform::Command::Init]
|
|
58
|
-
def initialize(config:)
|
|
59
|
-
self.backend_config = ::Kitchen::Terraform::CommandFlag::BackendConfig.new arguments: config.fetch(
|
|
60
|
-
:backend_configurations
|
|
61
|
-
)
|
|
62
|
-
self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
|
|
63
|
-
self.lock = config.fetch :lock
|
|
64
|
-
self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout)
|
|
65
|
-
self.plugin_dir = ::Kitchen::Terraform::CommandFlag::PluginDir.new pathname: config.fetch(
|
|
66
|
-
:plugin_directory
|
|
67
|
-
)
|
|
68
|
-
self.upgrade = ::Kitchen::Terraform::CommandFlag::Upgrade.new enabled: config.fetch(:upgrade_during_init)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# @return [String] the command with flags.
|
|
72
|
-
def to_s
|
|
73
|
-
"init " \
|
|
74
|
-
"-input=false " \
|
|
75
|
-
"-lock=#{lock} " \
|
|
76
|
-
"#{lock_timeout} " \
|
|
77
|
-
"#{color} " \
|
|
78
|
-
"#{upgrade} " \
|
|
79
|
-
"-force-copy " \
|
|
80
|
-
"-backend=true " \
|
|
81
|
-
"#{backend_config} " \
|
|
82
|
-
"-get=true " \
|
|
83
|
-
"-get-plugins=true " \
|
|
84
|
-
"#{plugin_dir} " \
|
|
85
|
-
"-verify-plugins=true"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
attr_accessor(
|
|
91
|
-
:backend_config,
|
|
92
|
-
:color,
|
|
93
|
-
:lock,
|
|
94
|
-
:lock_timeout,
|
|
95
|
-
:options,
|
|
96
|
-
:plugin_dir,
|
|
97
|
-
:upgrade,
|
|
98
|
-
)
|
|
20
|
+
# Init is the namespace for Terraform Init commands.
|
|
21
|
+
module Init
|
|
99
22
|
end
|
|
100
23
|
end
|
|
101
24
|
end
|
|
@@ -0,0 +1,89 @@
|
|
|
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/terraform/command_flag/backend_config"
|
|
18
|
+
require "kitchen/terraform/command_flag/color"
|
|
19
|
+
require "kitchen/terraform/command_flag/lock_timeout"
|
|
20
|
+
require "kitchen/terraform/command_flag/plugin_dir"
|
|
21
|
+
require "kitchen/terraform/command_flag/upgrade"
|
|
22
|
+
|
|
23
|
+
module Kitchen
|
|
24
|
+
module Terraform
|
|
25
|
+
module Command
|
|
26
|
+
module Init
|
|
27
|
+
# The working directory is initialized by running a command like the following example:
|
|
28
|
+
# terraform init \
|
|
29
|
+
# -backend=true \
|
|
30
|
+
# [-backend-config=<backend_configurations[0]> ...] \
|
|
31
|
+
# -force-copy \
|
|
32
|
+
# -get=true \
|
|
33
|
+
# -input=false \
|
|
34
|
+
# [-no-color] \
|
|
35
|
+
# [-plugin-dir=<plugin_directory>] \
|
|
36
|
+
# [-upgrade=true] \
|
|
37
|
+
# <root_module_directory>
|
|
38
|
+
class PostZeroFifteenZero
|
|
39
|
+
# #initialize prepares a new instance of the class.
|
|
40
|
+
#
|
|
41
|
+
# @param config [Hash] the configuration of the driver.
|
|
42
|
+
# @option config [Hash{String=>String}] :backend_configurations Terraform backend configuration arguments to
|
|
43
|
+
# complete a partial backend configuration.
|
|
44
|
+
# @option config [Boolean] :color a toggle of colored output from the Terraform client.
|
|
45
|
+
# on the state to be obtained during operations.
|
|
46
|
+
# @option config [String] :plugin_directory the pathname of the directory which contains
|
|
47
|
+
# customized Terraform provider plugins to install in place of the official Terraform provider plugins.
|
|
48
|
+
# @option config [Boolean] :upgrade_during_init a toggle for upgrading modules and plugins.
|
|
49
|
+
# @return [Kitchen::Terraform::Command::Init::PostZeroFifteenZero]
|
|
50
|
+
def initialize(config:)
|
|
51
|
+
self.backend_config = ::Kitchen::Terraform::CommandFlag::BackendConfig.new arguments: config.fetch(
|
|
52
|
+
:backend_configurations
|
|
53
|
+
)
|
|
54
|
+
self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
|
|
55
|
+
self.plugin_dir = ::Kitchen::Terraform::CommandFlag::PluginDir.new pathname: config.fetch(
|
|
56
|
+
:plugin_directory
|
|
57
|
+
)
|
|
58
|
+
self.upgrade = ::Kitchen::Terraform::CommandFlag::Upgrade.new enabled: config.fetch(:upgrade_during_init)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @return [String] the command with flags.
|
|
62
|
+
def to_s
|
|
63
|
+
"init " \
|
|
64
|
+
"-backend=true " \
|
|
65
|
+
"#{backend_config} " \
|
|
66
|
+
"-force-copy=true " \
|
|
67
|
+
"-get=true " \
|
|
68
|
+
"-input=false " \
|
|
69
|
+
"#{color} " \
|
|
70
|
+
"#{plugin_dir} " \
|
|
71
|
+
"#{upgrade}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
attr_accessor(
|
|
77
|
+
:backend_config,
|
|
78
|
+
:color,
|
|
79
|
+
:lock,
|
|
80
|
+
:lock_timeout,
|
|
81
|
+
:options,
|
|
82
|
+
:plugin_dir,
|
|
83
|
+
:upgrade,
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
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/terraform/command_flag/backend_config"
|
|
18
|
+
require "kitchen/terraform/command_flag/color"
|
|
19
|
+
require "kitchen/terraform/command_flag/lock_timeout"
|
|
20
|
+
require "kitchen/terraform/command_flag/plugin_dir"
|
|
21
|
+
require "kitchen/terraform/command_flag/upgrade"
|
|
22
|
+
|
|
23
|
+
module Kitchen
|
|
24
|
+
module Terraform
|
|
25
|
+
module Command
|
|
26
|
+
module Init
|
|
27
|
+
# The working directory is initialized by running a command like the following example:
|
|
28
|
+
# terraform init \
|
|
29
|
+
# -backend=true \
|
|
30
|
+
# [-backend-config=<backend_configurations[0]> ...] \
|
|
31
|
+
# -force-copy \
|
|
32
|
+
# -get=true \
|
|
33
|
+
# -get-plugins=true \
|
|
34
|
+
# -input=false \
|
|
35
|
+
# -lock=<lock> \
|
|
36
|
+
# -lock-timeout=<lock_timeout>s \
|
|
37
|
+
# [-no-color] \
|
|
38
|
+
# [-plugin-dir=<plugin_directory>] \
|
|
39
|
+
# [-upgrade=true] \
|
|
40
|
+
# -verify-plugins=true \
|
|
41
|
+
# <root_module_directory>
|
|
42
|
+
class PreZeroFifteenZero
|
|
43
|
+
# #initialize prepares a new instance of the class.
|
|
44
|
+
#
|
|
45
|
+
# @param config [Hash] the configuration of the driver.
|
|
46
|
+
# @option config [Hash{String=>String}] :backend_configurations Terraform backend configuration arguments to
|
|
47
|
+
# complete a partial backend configuration.
|
|
48
|
+
# @option config [Boolean] :color a toggle of colored output from the Terraform client.
|
|
49
|
+
# @option config [Boolean] :lock a toggle of locking for the Terraform state file.
|
|
50
|
+
# @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock
|
|
51
|
+
# on the state to be obtained during operations.
|
|
52
|
+
# @option config [String] :plugin_directory the pathname of the directory which contains
|
|
53
|
+
# customized Terraform provider plugins to install in place of the official Terraform provider plugins.
|
|
54
|
+
# @option config [Boolean] :upgrade_during_init a toggle for upgrading modules and plugins.
|
|
55
|
+
# @return [Kitchen::Terraform::Command::Init::PreZeroFifteenZero]
|
|
56
|
+
def initialize(config:)
|
|
57
|
+
self.backend_config = ::Kitchen::Terraform::CommandFlag::BackendConfig.new arguments: config.fetch(
|
|
58
|
+
:backend_configurations
|
|
59
|
+
)
|
|
60
|
+
self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
|
|
61
|
+
self.lock = config.fetch :lock
|
|
62
|
+
self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout)
|
|
63
|
+
self.plugin_dir = ::Kitchen::Terraform::CommandFlag::PluginDir.new pathname: config.fetch(
|
|
64
|
+
:plugin_directory
|
|
65
|
+
)
|
|
66
|
+
self.upgrade = ::Kitchen::Terraform::CommandFlag::Upgrade.new enabled: config.fetch(:upgrade_during_init)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @return [String] the command with flags.
|
|
70
|
+
def to_s
|
|
71
|
+
"init " \
|
|
72
|
+
"-backend=true " \
|
|
73
|
+
"#{backend_config} " \
|
|
74
|
+
"-force-copy=true " \
|
|
75
|
+
"-get=true " \
|
|
76
|
+
"-get-plugins=true " \
|
|
77
|
+
"-input=false " \
|
|
78
|
+
"-lock=#{lock} " \
|
|
79
|
+
"#{lock_timeout} " \
|
|
80
|
+
"#{color} " \
|
|
81
|
+
"#{plugin_dir} " \
|
|
82
|
+
"#{upgrade} " \
|
|
83
|
+
"-verify-plugins=true"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
attr_accessor(
|
|
89
|
+
:backend_config,
|
|
90
|
+
:color,
|
|
91
|
+
:lock,
|
|
92
|
+
:lock_timeout,
|
|
93
|
+
:options,
|
|
94
|
+
:plugin_dir,
|
|
95
|
+
:upgrade,
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
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/terraform/command/init/post_zero_fifteen_zero"
|
|
18
|
+
require "kitchen/terraform/command/init/pre_zero_fifteen_zero"
|
|
19
|
+
require "rubygems"
|
|
20
|
+
|
|
21
|
+
module Kitchen
|
|
22
|
+
module Terraform
|
|
23
|
+
module Command
|
|
24
|
+
# InitFactory is the class of objects which build Init objects.
|
|
25
|
+
class InitFactory
|
|
26
|
+
# #build creates a new instance of an Init object.
|
|
27
|
+
#
|
|
28
|
+
# @param config [Hash] the configuration of the driver.
|
|
29
|
+
# @return [Kitchen::Terraform::Command::Init::PreZeroFifteenZero,
|
|
30
|
+
# Kitchen::Terraform::Command::Init::PostZeroFifteenZero]
|
|
31
|
+
def build(config:)
|
|
32
|
+
return ::Kitchen::Terraform::Command::Init::PreZeroFifteenZero.new config: config if requirement.satisfied_by? version
|
|
33
|
+
|
|
34
|
+
::Kitchen::Terraform::Command::Init::PostZeroFifteenZero.new config: config
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# #initialize prepares a new instance of the class
|
|
38
|
+
#
|
|
39
|
+
# @param version [Gem::Version] a client version.
|
|
40
|
+
# @return [Kitchen::Terraform::Command::InitFactory]
|
|
41
|
+
def initialize(version:)
|
|
42
|
+
self.requirement = ::Gem::Requirement.new "< 0.15.0"
|
|
43
|
+
self.version = version
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
attr_accessor :requirement, :version
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -14,49 +14,11 @@
|
|
|
14
14
|
# See the License for the specific language governing permissions and
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
|
-
require "kitchen/terraform/command_flag/color"
|
|
18
|
-
require "kitchen/terraform/command_flag/var_file"
|
|
19
|
-
require "kitchen/terraform/command_flag/var"
|
|
20
|
-
require "shellwords"
|
|
21
|
-
|
|
22
17
|
module Kitchen
|
|
23
18
|
module Terraform
|
|
24
19
|
module Command
|
|
25
|
-
#
|
|
26
|
-
|
|
27
|
-
# [-no-color] \
|
|
28
|
-
# [-var=<variables.first>...] \
|
|
29
|
-
# [-var-file=<variable_files.first>...] \
|
|
30
|
-
# <directory>
|
|
31
|
-
class Validate
|
|
32
|
-
# #initialize prepares a new instance of the class.
|
|
33
|
-
#
|
|
34
|
-
# @param config [Hash] the configuration of the driver.
|
|
35
|
-
# @option config [Boolean] :color a toggle of colored output from the Terraform client.
|
|
36
|
-
# @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate.
|
|
37
|
-
# @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate.
|
|
38
|
-
# @return [Kitchen::Terraform::Command::Validate]
|
|
39
|
-
def initialize(config:)
|
|
40
|
-
self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
|
|
41
|
-
self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files)
|
|
42
|
-
self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# @return [String] the command with flags.
|
|
46
|
-
def to_s
|
|
47
|
-
"validate " \
|
|
48
|
-
"#{color} " \
|
|
49
|
-
"#{var} " \
|
|
50
|
-
"#{var_file}"
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
private
|
|
54
|
-
|
|
55
|
-
attr_accessor(
|
|
56
|
-
:color,
|
|
57
|
-
:var_file,
|
|
58
|
-
:var,
|
|
59
|
-
)
|
|
20
|
+
# Validate is the namespace for Terraform Validate commands.
|
|
21
|
+
module Validate
|
|
60
22
|
end
|
|
61
23
|
end
|
|
62
24
|
end
|
|
@@ -0,0 +1,51 @@
|
|
|
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/terraform/command_flag/color"
|
|
18
|
+
require "shellwords"
|
|
19
|
+
|
|
20
|
+
module Kitchen
|
|
21
|
+
module Terraform
|
|
22
|
+
module Command
|
|
23
|
+
module Validate
|
|
24
|
+
# The root module is validated by running a command like the following example:
|
|
25
|
+
# terraform validate \
|
|
26
|
+
# [-no-color] \
|
|
27
|
+
# <directory>
|
|
28
|
+
class PostZeroFifteenZero
|
|
29
|
+
# #initialize prepares a new instance of the class.
|
|
30
|
+
#
|
|
31
|
+
# @param config [Hash] the configuration of the driver.
|
|
32
|
+
# @option config [Boolean] :color a toggle of colored output from the Terraform client.
|
|
33
|
+
# @return [Kitchen::Terraform::Command::Validate]
|
|
34
|
+
def initialize(config:)
|
|
35
|
+
self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @return [String] the command with flags.
|
|
39
|
+
def to_s
|
|
40
|
+
"validate " \
|
|
41
|
+
"#{color}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
attr_accessor :color
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
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/terraform/command_flag/color"
|
|
18
|
+
require "kitchen/terraform/command_flag/var_file"
|
|
19
|
+
require "kitchen/terraform/command_flag/var"
|
|
20
|
+
require "shellwords"
|
|
21
|
+
|
|
22
|
+
module Kitchen
|
|
23
|
+
module Terraform
|
|
24
|
+
module Command
|
|
25
|
+
module Validate
|
|
26
|
+
# The root module is validated by running a command like the following example:
|
|
27
|
+
# terraform validate \
|
|
28
|
+
# [-no-color] \
|
|
29
|
+
# [-var=<variables.first>...] \
|
|
30
|
+
# [-var-file=<variable_files.first>...] \
|
|
31
|
+
# <directory>
|
|
32
|
+
class PreZeroFifteenZero
|
|
33
|
+
# #initialize prepares a new instance of the class.
|
|
34
|
+
#
|
|
35
|
+
# @param config [Hash] the configuration of the driver.
|
|
36
|
+
# @option config [Boolean] :color a toggle of colored output from the Terraform client.
|
|
37
|
+
# @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate.
|
|
38
|
+
# @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate.
|
|
39
|
+
# @return [Kitchen::Terraform::Command::Validate]
|
|
40
|
+
def initialize(config:)
|
|
41
|
+
self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
|
|
42
|
+
self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files)
|
|
43
|
+
self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [String] the command with flags.
|
|
47
|
+
def to_s
|
|
48
|
+
"validate " \
|
|
49
|
+
"#{color} " \
|
|
50
|
+
"#{var} " \
|
|
51
|
+
"#{var_file}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
attr_accessor(
|
|
57
|
+
:color,
|
|
58
|
+
:var_file,
|
|
59
|
+
:var,
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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/terraform/command/validate/post_zero_fifteen_zero"
|
|
18
|
+
require "kitchen/terraform/command/validate/pre_zero_fifteen_zero"
|
|
19
|
+
require "rubygems"
|
|
20
|
+
|
|
21
|
+
module Kitchen
|
|
22
|
+
module Terraform
|
|
23
|
+
module Command
|
|
24
|
+
# ValidateFactory is the class of objects which build Validate objects.
|
|
25
|
+
class ValidateFactory
|
|
26
|
+
# #build creates a new instance of an Validate object.
|
|
27
|
+
#
|
|
28
|
+
# @param config [Hash] the configuration of the driver.
|
|
29
|
+
# @return [Kitchen::Terraform::Command::Validate::PreZeroFifteenZero,
|
|
30
|
+
# Kitchen::Terraform::Command::Validate::PostZeroFifteenZero]
|
|
31
|
+
def build(config:)
|
|
32
|
+
if requirement.satisfied_by? version
|
|
33
|
+
return ::Kitchen::Terraform::Command::Validate::PreZeroFifteenZero.new config: config
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
::Kitchen::Terraform::Command::Validate::PostZeroFifteenZero.new config: config
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# #initialize prepares a new instance of the class
|
|
40
|
+
#
|
|
41
|
+
# @param version [Gem::Version] a client version.
|
|
42
|
+
# @return [Kitchen::Terraform::Command::ValidateFactory]
|
|
43
|
+
def initialize(version:)
|
|
44
|
+
self.requirement = ::Gem::Requirement.new "< 0.15.0"
|
|
45
|
+
self.version = version
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
attr_accessor :requirement, :version
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -42,7 +42,7 @@ module Kitchen
|
|
|
42
42
|
# @see Kitchen::Configurable#finalize_config!
|
|
43
43
|
def finalize_config!(instance)
|
|
44
44
|
super instance
|
|
45
|
-
self.version_requirement = ::Gem::Requirement.new ">= 0.11.4", "<
|
|
45
|
+
self.version_requirement = ::Gem::Requirement.new ">= 0.11.4", "< 1.1.0"
|
|
46
46
|
self.workspace_name = "kitchen-terraform-#{::Shellwords.escape instance.name}"
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
17
|
require "kitchen"
|
|
18
|
-
require "kitchen/terraform/command/
|
|
18
|
+
require "kitchen/terraform/command/init_factory"
|
|
19
19
|
require "kitchen/terraform/command/version"
|
|
20
20
|
require "kitchen/terraform/command/workspace_new"
|
|
21
21
|
require "kitchen/terraform/command/workspace_select"
|
|
22
22
|
require "kitchen/terraform/command_executor"
|
|
23
23
|
require "kitchen/terraform/verify_version"
|
|
24
|
+
require "rubygems"
|
|
24
25
|
|
|
25
26
|
module Kitchen
|
|
26
27
|
module Terraform
|
|
@@ -29,7 +30,13 @@ module Kitchen
|
|
|
29
30
|
#
|
|
30
31
|
# ===== Initializing the Terraform Working Directory
|
|
31
32
|
#
|
|
32
|
-
#
|
|
33
|
+
# ====== Terraform >= 0.15.0
|
|
34
|
+
#
|
|
35
|
+
# {include:Kitchen::Terraform::Command::Init::PostZeroFifteenZero}
|
|
36
|
+
#
|
|
37
|
+
# ====== Terraform < 0.15.0
|
|
38
|
+
#
|
|
39
|
+
# {include:Kitchen::Terraform::Command::Init::PreZeroFifteenZero}
|
|
33
40
|
#
|
|
34
41
|
# ===== Creating or Selecting the Test Terraform Workspace
|
|
35
42
|
#
|
|
@@ -42,7 +49,8 @@ module Kitchen
|
|
|
42
49
|
# @raise [Kitchen::TransientFailure] if a command fails.
|
|
43
50
|
# @return [self]
|
|
44
51
|
def call
|
|
45
|
-
|
|
52
|
+
read_client_version
|
|
53
|
+
verify_version.call version: client_version
|
|
46
54
|
initialize_directory
|
|
47
55
|
create_or_select_workspace
|
|
48
56
|
|
|
@@ -58,20 +66,22 @@ module Kitchen
|
|
|
58
66
|
# @option config [String] :client the pathname of the Terraform client.
|
|
59
67
|
# @return [Kitchen::Terraform::Driver::Create]
|
|
60
68
|
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
|
61
|
-
|
|
69
|
+
self.complete_config = config.to_hash.merge upgrade_during_init: true, workspace_name: workspace_name
|
|
70
|
+
self.client_version = ::Gem::Version.new "0.0.0"
|
|
62
71
|
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
|
63
|
-
client:
|
|
72
|
+
client: complete_config.fetch(:client),
|
|
64
73
|
logger: logger,
|
|
65
74
|
)
|
|
66
|
-
self.init = ::Kitchen::Terraform::Command::Init.new config: hash_config
|
|
67
75
|
self.logger = logger
|
|
68
|
-
self.options = {
|
|
76
|
+
self.options = {
|
|
77
|
+
cwd: complete_config.fetch(:root_module_directory),
|
|
78
|
+
timeout: complete_config.fetch(:command_timeout),
|
|
79
|
+
}
|
|
69
80
|
self.workspace_name = workspace_name
|
|
70
|
-
self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config:
|
|
71
|
-
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config:
|
|
81
|
+
self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
|
|
82
|
+
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
|
|
72
83
|
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
|
73
|
-
|
|
74
|
-
config: config,
|
|
84
|
+
config: complete_config,
|
|
75
85
|
logger: logger,
|
|
76
86
|
version_requirement: version_requirement,
|
|
77
87
|
)
|
|
@@ -81,8 +91,9 @@ module Kitchen
|
|
|
81
91
|
private
|
|
82
92
|
|
|
83
93
|
attr_accessor(
|
|
94
|
+
:client_version,
|
|
84
95
|
:command_executor,
|
|
85
|
-
:
|
|
96
|
+
:complete_config,
|
|
86
97
|
:logger,
|
|
87
98
|
:options,
|
|
88
99
|
:verify_version,
|
|
@@ -103,11 +114,23 @@ module Kitchen
|
|
|
103
114
|
|
|
104
115
|
def initialize_directory
|
|
105
116
|
logger.warn "Initializing the Terraform working directory..."
|
|
106
|
-
command_executor.run
|
|
117
|
+
command_executor.run(
|
|
118
|
+
command: ::Kitchen::Terraform::Command::InitFactory.new(version: client_version)
|
|
119
|
+
.build(config: complete_config),
|
|
120
|
+
options: options,
|
|
121
|
+
) do |standard_output:|
|
|
107
122
|
end
|
|
108
123
|
logger.warn "Finished initializing the Terraform working directory."
|
|
109
124
|
end
|
|
110
125
|
|
|
126
|
+
def read_client_version
|
|
127
|
+
logger.warn "Reading the Terraform client version..."
|
|
128
|
+
command_executor.run command: version, options: options do |standard_output:|
|
|
129
|
+
self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
|
130
|
+
end
|
|
131
|
+
logger.warn "Finished reading the Terraform client version."
|
|
132
|
+
end
|
|
133
|
+
|
|
111
134
|
def select_workspace
|
|
112
135
|
logger.warn "Selecting the #{workspace_name} Terraform workspace..."
|
|
113
136
|
command_executor.run command: workspace_select, options: options do |standard_output:|
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
require "kitchen"
|
|
18
18
|
require "kitchen/terraform/command_executor"
|
|
19
19
|
require "kitchen/terraform/command/destroy"
|
|
20
|
-
require "kitchen/terraform/command/
|
|
20
|
+
require "kitchen/terraform/command/init_factory"
|
|
21
21
|
require "kitchen/terraform/command/version"
|
|
22
22
|
require "kitchen/terraform/command/workspace_delete"
|
|
23
23
|
require "kitchen/terraform/command/workspace_new"
|
|
24
24
|
require "kitchen/terraform/command/workspace_select"
|
|
25
25
|
require "kitchen/terraform/verify_version"
|
|
26
|
+
require "rubygems"
|
|
26
27
|
|
|
27
28
|
module Kitchen
|
|
28
29
|
module Terraform
|
|
@@ -31,7 +32,13 @@ module Kitchen
|
|
|
31
32
|
#
|
|
32
33
|
# ===== Initializing the Terraform Working Directory
|
|
33
34
|
#
|
|
34
|
-
#
|
|
35
|
+
# ====== Terraform >= 0.15.0
|
|
36
|
+
#
|
|
37
|
+
# {include:Kitchen::Terraform::Command::Init::PostZeroFifteenZero}
|
|
38
|
+
#
|
|
39
|
+
# ====== Terraform < 0.15.0
|
|
40
|
+
#
|
|
41
|
+
# {include:Kitchen::Terraform::Command::Init::PreZeroFifteenZero}
|
|
35
42
|
#
|
|
36
43
|
# ===== Selecting or Creating the Test Terraform Workspace
|
|
37
44
|
#
|
|
@@ -56,7 +63,8 @@ module Kitchen
|
|
|
56
63
|
# @raise [Kitchen::TransientFailure] if a command fails.
|
|
57
64
|
# @return [self]
|
|
58
65
|
def call
|
|
59
|
-
|
|
66
|
+
read_client_version
|
|
67
|
+
verify_version.call version: client_version
|
|
60
68
|
execute_workflow
|
|
61
69
|
|
|
62
70
|
self
|
|
@@ -70,25 +78,24 @@ module Kitchen
|
|
|
70
78
|
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
|
71
79
|
# @return [Kitchen::Terraform::Driver::Destroy]
|
|
72
80
|
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
|
73
|
-
|
|
81
|
+
self.complete_config = config.to_hash.merge upgrade_during_init: false, workspace_name: workspace_name
|
|
82
|
+
self.client_version = ::Gem::Version.new "0.0.0"
|
|
74
83
|
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
|
75
|
-
client:
|
|
84
|
+
client: complete_config.fetch(:client),
|
|
76
85
|
logger: logger,
|
|
77
86
|
)
|
|
78
87
|
self.logger = logger
|
|
79
|
-
define_options
|
|
88
|
+
define_options
|
|
80
89
|
self.workspace_name = workspace_name
|
|
81
|
-
self.destroy = ::Kitchen::Terraform::Command::Destroy.new config:
|
|
82
|
-
self.
|
|
83
|
-
self.
|
|
84
|
-
self.
|
|
85
|
-
self.workspace_select_test = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
|
|
90
|
+
self.destroy = ::Kitchen::Terraform::Command::Destroy.new config: complete_config
|
|
91
|
+
self.workspace_delete_test = ::Kitchen::Terraform::Command::WorkspaceDelete.new config: complete_config
|
|
92
|
+
self.workspace_new_test = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
|
|
93
|
+
self.workspace_select_test = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
|
|
86
94
|
self.workspace_select_default = ::Kitchen::Terraform::Command::WorkspaceSelect.new(
|
|
87
|
-
config:
|
|
95
|
+
config: complete_config.merge(workspace_name: "default"),
|
|
88
96
|
)
|
|
89
97
|
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
|
90
|
-
|
|
91
|
-
config: config,
|
|
98
|
+
config: complete_config,
|
|
92
99
|
logger: logger,
|
|
93
100
|
version_requirement: version_requirement,
|
|
94
101
|
)
|
|
@@ -98,9 +105,11 @@ module Kitchen
|
|
|
98
105
|
private
|
|
99
106
|
|
|
100
107
|
attr_accessor(
|
|
108
|
+
:client_version,
|
|
101
109
|
:command_executor,
|
|
102
|
-
:
|
|
110
|
+
:complete_config,
|
|
103
111
|
:destroy_options,
|
|
112
|
+
:destroy,
|
|
104
113
|
:init,
|
|
105
114
|
:logger,
|
|
106
115
|
:options,
|
|
@@ -120,10 +129,13 @@ module Kitchen
|
|
|
120
129
|
logger.warn "Finished creating the #{workspace_name} Terraform workspace."
|
|
121
130
|
end
|
|
122
131
|
|
|
123
|
-
def define_options
|
|
124
|
-
self.options = {
|
|
132
|
+
def define_options
|
|
133
|
+
self.options = {
|
|
134
|
+
cwd: complete_config.fetch(:root_module_directory),
|
|
135
|
+
timeout: complete_config.fetch(:command_timeout),
|
|
136
|
+
}
|
|
125
137
|
self.destroy_options = options.merge(
|
|
126
|
-
environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "true" }
|
|
138
|
+
environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "true" },
|
|
127
139
|
)
|
|
128
140
|
end
|
|
129
141
|
|
|
@@ -151,11 +163,23 @@ module Kitchen
|
|
|
151
163
|
|
|
152
164
|
def initialize_directory
|
|
153
165
|
logger.warn "Initializing the Terraform working directory..."
|
|
154
|
-
command_executor.run
|
|
166
|
+
command_executor.run(
|
|
167
|
+
command: ::Kitchen::Terraform::Command::InitFactory.new(version: client_version)
|
|
168
|
+
.build(config: complete_config),
|
|
169
|
+
options: options,
|
|
170
|
+
) do |standard_output:|
|
|
155
171
|
end
|
|
156
172
|
logger.warn "Finished initializing the Terraform working directory."
|
|
157
173
|
end
|
|
158
174
|
|
|
175
|
+
def read_client_version
|
|
176
|
+
logger.warn "Reading the Terraform client version..."
|
|
177
|
+
command_executor.run command: version, options: options do |standard_output:|
|
|
178
|
+
self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
|
179
|
+
end
|
|
180
|
+
logger.warn "Finished reading the Terraform client version."
|
|
181
|
+
end
|
|
182
|
+
|
|
159
183
|
def select_default_workspace
|
|
160
184
|
logger.warn "Selecting the default Terraform workspace..."
|
|
161
185
|
command_executor.run command: workspace_select_default, options: options do |standard_output:|
|
|
@@ -19,7 +19,7 @@ require "kitchen/terraform/command_executor"
|
|
|
19
19
|
require "kitchen/terraform/command/apply"
|
|
20
20
|
require "kitchen/terraform/command/get"
|
|
21
21
|
require "kitchen/terraform/command/output"
|
|
22
|
-
require "kitchen/terraform/command/
|
|
22
|
+
require "kitchen/terraform/command/validate_factory"
|
|
23
23
|
require "kitchen/terraform/command/workspace_select"
|
|
24
24
|
require "kitchen/terraform/debug_logger"
|
|
25
25
|
require "kitchen/terraform/outputs_manager"
|
|
@@ -28,6 +28,7 @@ require "kitchen/terraform/outputs_reader"
|
|
|
28
28
|
require "kitchen/terraform/variables_manager"
|
|
29
29
|
require "kitchen/terraform/verify_version"
|
|
30
30
|
require "kitchen/terraform/version"
|
|
31
|
+
require "rubygems"
|
|
31
32
|
|
|
32
33
|
module Kitchen
|
|
33
34
|
module Terraform
|
|
@@ -44,7 +45,13 @@ module Kitchen
|
|
|
44
45
|
#
|
|
45
46
|
# ===== Validating the Terraform Root Module
|
|
46
47
|
#
|
|
47
|
-
#
|
|
48
|
+
# ====== Terraform >= 0.15.0
|
|
49
|
+
#
|
|
50
|
+
# {include:Kitchen::Terraform::Command::Validate::PostZeroFifteenZero}
|
|
51
|
+
#
|
|
52
|
+
# ====== Terraform < 0.15.0
|
|
53
|
+
#
|
|
54
|
+
# {include:Kitchen::Terraform::Command::Validate::PreZeroFifteenZero}
|
|
48
55
|
#
|
|
49
56
|
# ===== Applying the Terraform State Changes
|
|
50
57
|
#
|
|
@@ -60,7 +67,8 @@ module Kitchen
|
|
|
60
67
|
# @raise [Kitchen::TransientFailure] if a command fails.
|
|
61
68
|
# @return [self]
|
|
62
69
|
def call(state:)
|
|
63
|
-
|
|
70
|
+
read_client_version
|
|
71
|
+
verify_version.call version: client_version
|
|
64
72
|
execute_workflow
|
|
65
73
|
save_variables_and_outputs state: state
|
|
66
74
|
|
|
@@ -75,51 +83,50 @@ module Kitchen
|
|
|
75
83
|
# @param workspace_name [String] the name of the Terraform workspace to select or to create.
|
|
76
84
|
# @return [Kitchen::Terraform::Driver::Converge]
|
|
77
85
|
def initialize(config:, logger:, version_requirement:, workspace_name:)
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
self.complete_config = config.to_hash.merge workspace_name: workspace_name
|
|
87
|
+
client = complete_config.fetch :client
|
|
88
|
+
self.client_version = ::Gem::Version.new "0.0.0"
|
|
80
89
|
self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
|
|
81
90
|
client: client,
|
|
82
91
|
logger: logger,
|
|
83
92
|
)
|
|
84
93
|
self.logger = logger
|
|
85
|
-
self.options = {
|
|
94
|
+
self.options = {
|
|
95
|
+
cwd: complete_config.fetch(:root_module_directory),
|
|
96
|
+
timeout: complete_config.fetch(:command_timeout),
|
|
97
|
+
}
|
|
86
98
|
self.workspace_name = workspace_name
|
|
87
|
-
|
|
88
|
-
self.get = ::Kitchen::Terraform::Command::Get.new
|
|
89
|
-
self.output = ::Kitchen::Terraform::Command::Output.new
|
|
99
|
+
initialize_commands
|
|
90
100
|
initialize_outputs_handlers client: client, logger: logger
|
|
91
|
-
self.
|
|
92
|
-
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
|
|
93
|
-
self.variables = config.fetch :variables
|
|
101
|
+
self.variables = complete_config.fetch :variables
|
|
94
102
|
self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
|
|
95
103
|
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
|
|
96
|
-
|
|
97
|
-
config: config,
|
|
104
|
+
config: complete_config,
|
|
98
105
|
logger: logger,
|
|
99
106
|
version_requirement: version_requirement,
|
|
100
107
|
)
|
|
101
|
-
self.version = ::Kitchen::Terraform::Command::Version.new
|
|
102
108
|
end
|
|
103
109
|
|
|
104
110
|
private
|
|
105
111
|
|
|
106
112
|
attr_accessor(
|
|
107
|
-
:command_executor,
|
|
108
113
|
:apply,
|
|
114
|
+
:client_version,
|
|
115
|
+
:command_executor,
|
|
116
|
+
:complete_config,
|
|
109
117
|
:get,
|
|
110
|
-
:output,
|
|
111
|
-
:validate,
|
|
112
|
-
:workspace_select,
|
|
113
118
|
:logger,
|
|
114
119
|
:options,
|
|
120
|
+
:output,
|
|
115
121
|
:outputs_manager,
|
|
116
122
|
:outputs_parser,
|
|
117
123
|
:outputs_reader,
|
|
118
|
-
:variables,
|
|
119
124
|
:variables_manager,
|
|
125
|
+
:variables,
|
|
120
126
|
:verify_version,
|
|
121
127
|
:version,
|
|
122
128
|
:workspace_name,
|
|
129
|
+
:workspace_select,
|
|
123
130
|
)
|
|
124
131
|
|
|
125
132
|
def build_infrastructure
|
|
@@ -143,6 +150,14 @@ module Kitchen
|
|
|
143
150
|
build_infrastructure
|
|
144
151
|
end
|
|
145
152
|
|
|
153
|
+
def initialize_commands
|
|
154
|
+
self.apply = ::Kitchen::Terraform::Command::Apply.new config: complete_config
|
|
155
|
+
self.get = ::Kitchen::Terraform::Command::Get.new
|
|
156
|
+
self.output = ::Kitchen::Terraform::Command::Output.new
|
|
157
|
+
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
|
|
158
|
+
self.version = ::Kitchen::Terraform::Command::Version.new
|
|
159
|
+
end
|
|
160
|
+
|
|
146
161
|
def initialize_outputs_handlers(client:, logger:)
|
|
147
162
|
self.outputs_manager = ::Kitchen::Terraform::OutputsManager.new
|
|
148
163
|
self.outputs_parser = ::Kitchen::Terraform::OutputsParser.new
|
|
@@ -172,6 +187,14 @@ module Kitchen
|
|
|
172
187
|
end
|
|
173
188
|
end
|
|
174
189
|
|
|
190
|
+
def read_client_version
|
|
191
|
+
logger.warn "Reading the Terraform client version..."
|
|
192
|
+
command_executor.run command: version, options: options do |standard_output:|
|
|
193
|
+
self.client_version = ::Gem::Version.new standard_output.slice /Terraform v(\d+\.\d+\.\d+)/, 1
|
|
194
|
+
end
|
|
195
|
+
logger.warn "Finished reading the Terraform client version."
|
|
196
|
+
end
|
|
197
|
+
|
|
175
198
|
def save_outputs(parsed_outputs:, state:)
|
|
176
199
|
logger.warn "Writing the output variables to the Kitchen instance state..."
|
|
177
200
|
outputs_manager.save outputs: parsed_outputs, state: state
|
|
@@ -196,7 +219,11 @@ module Kitchen
|
|
|
196
219
|
|
|
197
220
|
def validate_files
|
|
198
221
|
logger.warn "Validating the Terraform configuration files..."
|
|
199
|
-
command_executor.run
|
|
222
|
+
command_executor.run(
|
|
223
|
+
command: ::Kitchen::Terraform::Command::ValidateFactory.new(version: client_version)
|
|
224
|
+
.build(config: complete_config),
|
|
225
|
+
options: options,
|
|
226
|
+
) do |standard_output:|
|
|
200
227
|
end
|
|
201
228
|
logger.warn "Finished validating the Terraform configuration files."
|
|
202
229
|
end
|
|
@@ -27,13 +27,12 @@ module Kitchen
|
|
|
27
27
|
class VerifyVersion
|
|
28
28
|
# #call invokes the verification.
|
|
29
29
|
#
|
|
30
|
-
# @param
|
|
31
|
-
# @param options [Hash] options for running the command.
|
|
30
|
+
# @param version [Gem::Version] the Terraform client version.
|
|
32
31
|
# @raise [Kitchen::ActionFailed] if the verification fails.
|
|
33
32
|
# @return [self]
|
|
34
|
-
def call(
|
|
33
|
+
def call(version:)
|
|
35
34
|
logger.warn start_message
|
|
36
|
-
|
|
35
|
+
version_verifier.verify version: version
|
|
37
36
|
logger.warn finish_message
|
|
38
37
|
rescue ::Kitchen::Terraform::UnsupportedClientVersionError
|
|
39
38
|
rescue_strategy.call
|
|
@@ -49,8 +48,7 @@ module Kitchen
|
|
|
49
48
|
# @option config [Boolean] :verify_version a toggle of strict or permissive verification of support for the
|
|
50
49
|
# version of the Terraform client.
|
|
51
50
|
# @return [Kitchen::Terraform::VerifyVersion]
|
|
52
|
-
def initialize(
|
|
53
|
-
self.command_executor = command_executor
|
|
51
|
+
def initialize(config:, logger:, version_requirement:)
|
|
54
52
|
self.finish_message = "Finished verifying the Terraform client version."
|
|
55
53
|
self.logger = logger
|
|
56
54
|
self.rescue_strategy = ::Kitchen::Terraform::VerifyVersionRescueStrategyFactory.new(
|
|
@@ -64,22 +62,12 @@ module Kitchen
|
|
|
64
62
|
private
|
|
65
63
|
|
|
66
64
|
attr_accessor(
|
|
67
|
-
:command_executor,
|
|
68
65
|
:finish_message,
|
|
69
66
|
:logger,
|
|
70
|
-
:options,
|
|
71
67
|
:rescue_strategy,
|
|
72
68
|
:start_message,
|
|
73
69
|
:version_verifier
|
|
74
70
|
)
|
|
75
|
-
|
|
76
|
-
def run_version_and_verify(command:, options:)
|
|
77
|
-
logger.warn "Reading the Terraform client version..."
|
|
78
|
-
command_executor.run command: command, options: options do |standard_output:|
|
|
79
|
-
logger.warn "Finished reading the Terraform client version."
|
|
80
|
-
version_verifier.verify version: ::Gem::Version.new(standard_output.slice(/Terraform v(\d+\.\d+\.\d+)/, 1))
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
71
|
end
|
|
84
72
|
end
|
|
85
73
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kitchen-terraform
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Lane
|
|
@@ -62,7 +62,7 @@ cert_chain:
|
|
|
62
62
|
JH4yGDzVEYaZHaohSDcYuGLK6OQylPu7oM75S+TNLWseDIT8bWgQk6NelVjtQQ2Q
|
|
63
63
|
XSbgfu863jyey/0qO01cUo3+iTqzl85cWg==
|
|
64
64
|
-----END CERTIFICATE-----
|
|
65
|
-
date: 2021-
|
|
65
|
+
date: 2021-05-19 00:00:00.000000000 Z
|
|
66
66
|
dependencies:
|
|
67
67
|
- !ruby/object:Gem::Dependency
|
|
68
68
|
name: bundler
|
|
@@ -428,8 +428,14 @@ files:
|
|
|
428
428
|
- lib/kitchen/terraform/command/destroy.rb
|
|
429
429
|
- lib/kitchen/terraform/command/get.rb
|
|
430
430
|
- lib/kitchen/terraform/command/init.rb
|
|
431
|
+
- lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb
|
|
432
|
+
- lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb
|
|
433
|
+
- lib/kitchen/terraform/command/init_factory.rb
|
|
431
434
|
- lib/kitchen/terraform/command/output.rb
|
|
432
435
|
- lib/kitchen/terraform/command/validate.rb
|
|
436
|
+
- lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb
|
|
437
|
+
- lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb
|
|
438
|
+
- lib/kitchen/terraform/command/validate_factory.rb
|
|
433
439
|
- lib/kitchen/terraform/command/version.rb
|
|
434
440
|
- lib/kitchen/terraform/command/workspace_delete.rb
|
|
435
441
|
- lib/kitchen/terraform/command/workspace_new.rb
|
|
@@ -542,8 +548,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
542
548
|
- !ruby/object:Gem::Version
|
|
543
549
|
version: '0'
|
|
544
550
|
requirements:
|
|
545
|
-
- Terraform >= v0.11.4, <
|
|
546
|
-
rubygems_version: 3.0.3
|
|
551
|
+
- Terraform >= v0.11.4, < v1.1.0
|
|
552
|
+
rubygems_version: 3.0.3.1
|
|
547
553
|
signing_key:
|
|
548
554
|
specification_version: 4
|
|
549
555
|
summary: Test Kitchen plugins for testing Terraform configuration
|
metadata.gz.sig
CHANGED
|
Binary file
|