kitchen-terraform 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -2
- data/README.md +61 -6
- data/lib/kitchen/driver/terraform.rb +37 -22
- data/lib/kitchen/provisioner/terraform.rb +14 -18
- data/lib/kitchen/verifier/terraform.rb +25 -48
- data/lib/terraform/apply_command.rb +11 -20
- data/lib/terraform/apply_timeout_config.rb +9 -11
- data/lib/terraform/cli_config.rb +29 -0
- data/lib/terraform/client.rb +57 -52
- data/lib/terraform/color_coercer.rb +35 -0
- data/lib/terraform/color_config.rb +9 -11
- data/lib/terraform/command.rb +16 -30
- data/lib/terraform/command_factory.rb +111 -0
- data/lib/terraform/command_option.rb +65 -0
- data/lib/terraform/command_options.rb +95 -0
- data/lib/terraform/configurable.rb +42 -17
- data/lib/terraform/{zero_six_output.rb → debug_logger.rb} +10 -7
- data/lib/terraform/deprecated_output_parser.rb +41 -0
- data/lib/terraform/deprecated_variables_coercer.rb +35 -0
- data/lib/terraform/{command_extender.rb → deprecated_version.rb} +10 -7
- data/lib/terraform/destructive_plan_command.rb +35 -0
- data/lib/terraform/directory_config.rb +10 -5
- data/lib/terraform/file_configs.rb +36 -0
- data/lib/terraform/get_command.rb +3 -10
- data/lib/terraform/group.rb +29 -29
- data/lib/terraform/group_attributes.rb +42 -0
- data/lib/terraform/group_hostnames.rb +38 -0
- data/lib/terraform/groups_coercer.rb +43 -0
- data/lib/terraform/groups_config.rb +8 -54
- data/lib/terraform/integer_coercer.rb +37 -0
- data/lib/terraform/{plan_config.rb → no_output_parser.rb} +8 -7
- data/lib/terraform/output_command.rb +3 -39
- data/lib/terraform/output_parser.rb +55 -0
- data/lib/terraform/parallelism_config.rb +9 -11
- data/lib/terraform/pathname_coercer.rb +40 -0
- data/lib/terraform/plan_command.rb +7 -41
- data/lib/terraform/prepare_input_file.rb +34 -0
- data/lib/terraform/{zero_seven_output.rb → prepare_output_file.rb} +11 -9
- data/lib/terraform/project_version.rb +19 -0
- data/lib/terraform/shell_out.rb +59 -0
- data/lib/terraform/show_command.rb +7 -16
- data/lib/terraform/simple_coercer.rb +36 -0
- data/lib/terraform/{state_config.rb → simple_config.rb} +7 -6
- data/lib/terraform/{color_switch.rb → unsupported_version.rb} +6 -8
- data/lib/terraform/validate_command.rb +3 -10
- data/lib/terraform/variable_files_coercer.rb +40 -0
- data/lib/terraform/variable_files_config.rb +9 -10
- data/lib/terraform/variables_coercer.rb +49 -0
- data/lib/terraform/variables_config.rb +9 -24
- data/lib/terraform/version.rb +55 -1
- data/lib/terraform/version_command.rb +3 -10
- metadata +58 -9
- metadata.gz.sig +0 -0
- data/lib/terraform/command_executor.rb +0 -41
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016 New Context Services, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'kitchen'
|
18
|
+
|
19
|
+
module Terraform
|
20
|
+
# A preparation for a command with an input file
|
21
|
+
class PrepareInputFile
|
22
|
+
def execute
|
23
|
+
file.open {}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_accessor :file
|
29
|
+
|
30
|
+
def initialize(file:)
|
31
|
+
self.file = file
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -14,21 +14,23 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require '
|
17
|
+
require 'fileutils'
|
18
18
|
|
19
19
|
module Terraform
|
20
|
-
#
|
21
|
-
|
22
|
-
def
|
23
|
-
|
20
|
+
# A preparation for a command with an output file
|
21
|
+
class PrepareOutputFile
|
22
|
+
def execute
|
23
|
+
parent_directory.mkpath
|
24
|
+
file.open('a') {}
|
24
25
|
end
|
25
26
|
|
26
27
|
private
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
attr_accessor :file, :parent_directory
|
30
|
+
|
31
|
+
def initialize(file:)
|
32
|
+
self.file = file
|
33
|
+
self.parent_directory = file.parent
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016 New Context Services, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Terraform
|
18
|
+
PROJECT_VERSION = '0.6.0'
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016 New Context Services, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'kitchen'
|
18
|
+
require 'mixlib/shellout'
|
19
|
+
|
20
|
+
module Terraform
|
21
|
+
# Facilitates execution of commands in a shell
|
22
|
+
class ShellOut
|
23
|
+
def execute(&block)
|
24
|
+
block ||= proc {}
|
25
|
+
|
26
|
+
command.prepare
|
27
|
+
run_command
|
28
|
+
block.call shell_out.stdout
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_accessor :command, :shell_out
|
34
|
+
|
35
|
+
def initialize(
|
36
|
+
cli:, command:, logger:, timeout: ::Mixlib::ShellOut::DEFAULT_READ_TIMEOUT
|
37
|
+
)
|
38
|
+
self.command = command
|
39
|
+
self.shell_out = ::Mixlib::ShellOut.new "#{cli} #{command}",
|
40
|
+
live_stream: logger,
|
41
|
+
timeout: timeout
|
42
|
+
end
|
43
|
+
|
44
|
+
def instance_failures
|
45
|
+
[
|
46
|
+
::Errno::EACCES, ::Errno::ENOENT, ::Mixlib::ShellOut::CommandTimeout,
|
47
|
+
::Mixlib::ShellOut::ShellCommandFailed
|
48
|
+
]
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_command
|
52
|
+
shell_out.run_command
|
53
|
+
shell_out.error!
|
54
|
+
rescue *instance_failures => error
|
55
|
+
raise ::Kitchen::StandardError,
|
56
|
+
%(`#{shell_out.command}` failed: "#{error.message}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -14,26 +14,17 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
require 'terraform/command'
|
18
|
+
require 'terraform/prepare_input_file'
|
19
19
|
|
20
20
|
module Terraform
|
21
|
-
#
|
22
|
-
class ShowCommand < Command
|
23
|
-
include ColorSwitch
|
24
|
-
|
25
|
-
def name
|
26
|
-
'show'
|
27
|
-
end
|
28
|
-
|
29
|
-
def options
|
30
|
-
color_switch
|
31
|
-
end
|
32
|
-
|
21
|
+
# A command to show a state
|
22
|
+
class ShowCommand < ::Terraform::Command
|
33
23
|
private
|
34
24
|
|
35
|
-
def
|
36
|
-
|
25
|
+
def initialize(target: '')
|
26
|
+
super
|
27
|
+
preparations.push ::Terraform::PrepareInputFile.new file: target
|
37
28
|
end
|
38
29
|
end
|
39
30
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016 New Context Services, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Terraform
|
18
|
+
# Performs simple coercions
|
19
|
+
class SimpleCoercer
|
20
|
+
def coerce(attr:, value:)
|
21
|
+
configurable[attr] = method.call value
|
22
|
+
rescue ArgumentError, TypeError
|
23
|
+
configurable.config_error attr: attr, expected: expected
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_accessor :configurable, :expected, :method
|
29
|
+
|
30
|
+
def initialize(configurable:, expected:, method:)
|
31
|
+
self.configurable = configurable
|
32
|
+
self.expected = expected
|
33
|
+
self.method = method
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -15,13 +15,14 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
17
|
module Terraform
|
18
|
-
# Behaviour for
|
19
|
-
module
|
20
|
-
def
|
21
|
-
|
22
|
-
|
18
|
+
# Behaviour for simple config options
|
19
|
+
module SimpleConfig
|
20
|
+
def configure_required(attr:, coercer_class:, default_value:)
|
21
|
+
required_config attr do |_, value, configurable|
|
22
|
+
coercer_class
|
23
|
+
.new(configurable: configurable).coerce attr: attr, value: value
|
23
24
|
end
|
24
|
-
|
25
|
+
default_config attr, default_value
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -14,15 +14,13 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
+
require 'delegate'
|
18
|
+
|
17
19
|
module Terraform
|
18
|
-
#
|
19
|
-
|
20
|
-
def
|
21
|
-
|
20
|
+
# An unsupported version of Terraform
|
21
|
+
class UnsupportedVersion < ::SimpleDelegator
|
22
|
+
def if_not_supported
|
23
|
+
yield
|
22
24
|
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_accessor :color
|
27
25
|
end
|
28
26
|
end
|
@@ -14,17 +14,10 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
|
17
|
+
require 'terraform/command'
|
18
18
|
|
19
19
|
module Terraform
|
20
|
-
#
|
21
|
-
class ValidateCommand < Command
|
22
|
-
def name
|
23
|
-
'validate'
|
24
|
-
end
|
25
|
-
|
26
|
-
def options
|
27
|
-
''
|
28
|
-
end
|
20
|
+
# A command to valdidate configuration files
|
21
|
+
class ValidateCommand < ::Terraform::Command
|
29
22
|
end
|
30
23
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016 New Context Services, 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 'terraform/pathname_coercer'
|
18
|
+
|
19
|
+
module Terraform
|
20
|
+
# A coercer for the [:variable_files] config option
|
21
|
+
class VariableFilesCoercer
|
22
|
+
def coerce(attr:, value:)
|
23
|
+
configurable[attr] = Array(value).map do |pathname|
|
24
|
+
coercer.coerce attr: attr, value: pathname
|
25
|
+
|
26
|
+
configurable[attr]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_accessor :coercer, :configurable
|
33
|
+
|
34
|
+
def initialize(configurable:)
|
35
|
+
self.coercer =
|
36
|
+
::Terraform::PathnameCoercer.new configurable: configurable
|
37
|
+
self.configurable = configurable
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -14,20 +14,19 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
+
require_relative 'simple_config'
|
18
|
+
require_relative 'variable_files_coercer'
|
19
|
+
|
17
20
|
module Terraform
|
18
21
|
# Behaviour for the [:variable_files] config option
|
19
22
|
module VariableFilesConfig
|
20
|
-
|
21
|
-
configurable_class
|
22
|
-
.required_config :variable_files do |_, value, configurable|
|
23
|
-
configurable.coerce_variable_files value: value
|
24
|
-
end
|
25
|
-
configurable_class.default_config :variable_files, []
|
26
|
-
configurable_class.expand_path_for :variable_files
|
27
|
-
end
|
23
|
+
include ::Terraform::SimpleConfig
|
28
24
|
|
29
|
-
def
|
30
|
-
|
25
|
+
def self.extended(configurable_class)
|
26
|
+
configurable_class
|
27
|
+
.configure_required attr: :variable_files,
|
28
|
+
coercer_class: ::Terraform::VariableFilesCoercer,
|
29
|
+
default_value: []
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2016 New Context Services, 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_relative 'deprecated_variables_coercer'
|
18
|
+
require_relative 'simple_coercer'
|
19
|
+
|
20
|
+
module Terraform
|
21
|
+
# A coercer for values of [:variables]
|
22
|
+
class VariablesCoercer
|
23
|
+
def coerce(attr:, value:)
|
24
|
+
coercer(value: value).coerce attr: attr, value: value
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_accessor :configurable
|
30
|
+
|
31
|
+
def coercer(value:)
|
32
|
+
[::Array, ::String]
|
33
|
+
.find proc { return simple_coercer }, &value.method(:is_a?)
|
34
|
+
|
35
|
+
::Terraform::DeprecatedVariablesCoercer.new configurable: configurable
|
36
|
+
end
|
37
|
+
|
38
|
+
def simple_coercer
|
39
|
+
::Terraform::SimpleCoercer
|
40
|
+
.new configurable: configurable,
|
41
|
+
expected: 'a mapping of Terraform variable assignments',
|
42
|
+
method: method(:Hash)
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(configurable:)
|
46
|
+
self.configurable = configurable
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -14,34 +14,19 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
+
require_relative 'simple_config'
|
18
|
+
require_relative 'variables_coercer'
|
19
|
+
|
17
20
|
module Terraform
|
18
21
|
# Behaviour for the [:variables] config option
|
19
22
|
module VariablesConfig
|
20
|
-
|
21
|
-
configurable_class.required_config :variables do |_, value, configurable|
|
22
|
-
configurable.coerce_variables value: value
|
23
|
-
end
|
24
|
-
configurable_class.default_config :variables, {}
|
25
|
-
end
|
26
|
-
|
27
|
-
def coerce_variables(value:)
|
28
|
-
config[:variables] =
|
29
|
-
if value.is_a?(Array) || value.is_a?(String)
|
30
|
-
deprecated_variables_format value: value
|
31
|
-
else
|
32
|
-
Hash value
|
33
|
-
end
|
34
|
-
rescue ArgumentError, TypeError
|
35
|
-
config_error attribute: 'variables',
|
36
|
-
expected: 'a mapping of Terraform variable assignments'
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
23
|
+
include ::Terraform::SimpleConfig
|
40
24
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
25
|
+
def self.extended(configurable_class)
|
26
|
+
configurable_class
|
27
|
+
.configure_required attr: :variables,
|
28
|
+
coercer_class: ::Terraform::VariablesCoercer,
|
29
|
+
default_value: {}
|
45
30
|
end
|
46
31
|
end
|
47
32
|
end
|