kitchen-terraform 0.5.1 → 0.6.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 +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,42 @@
|
|
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 'hashie/extensions/coercion'
|
18
|
+
require 'hashie/hash'
|
19
|
+
|
20
|
+
module Terraform
|
21
|
+
# InSpec attributes of a group
|
22
|
+
class GroupAttributes < ::Hashie::Hash
|
23
|
+
include ::Hashie::Extensions::Coercion
|
24
|
+
|
25
|
+
coerce_value ::Object, ::String
|
26
|
+
|
27
|
+
def self.coerce(config_value)
|
28
|
+
self[config_value]
|
29
|
+
end
|
30
|
+
|
31
|
+
def resolve(client:)
|
32
|
+
client.each_output_name { |name| soft_store key: name, value: name }
|
33
|
+
dup.each_pair { |key, value| store key, client.output(name: value) }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def soft_store(key:, value:)
|
39
|
+
fetch(key) { store key, value }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
# Hostnames output variable for Group
|
19
|
+
class GroupHostnames
|
20
|
+
def resolve(client:, &block)
|
21
|
+
config_value.scan(/^\s*$/) { return yield 'localhost' }
|
22
|
+
|
23
|
+
client.iterate_output name: config_value, &block
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
config_value
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_accessor :config_value
|
33
|
+
|
34
|
+
def initialize(config_value = '')
|
35
|
+
self.config_value = String config_value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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 'hashie'
|
18
|
+
require 'terraform/group'
|
19
|
+
|
20
|
+
module Terraform
|
21
|
+
# A coercer for [:groups] config values
|
22
|
+
class GroupsCoercer
|
23
|
+
def coerce(attr:, value:)
|
24
|
+
configurable[attr] = Array(value).map do |group|
|
25
|
+
::Terraform::Group.new defaults.merge group
|
26
|
+
end
|
27
|
+
rescue ::TypeError, ::Hashie::CoercionError
|
28
|
+
configurable.config_error attr: attr, expected: 'a list of group mappings'
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_accessor :configurable, :defaults
|
34
|
+
|
35
|
+
def initialize(configurable:)
|
36
|
+
self.configurable = configurable
|
37
|
+
self.defaults = {
|
38
|
+
port: configurable.transport[:port],
|
39
|
+
username: configurable.transport[:username]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -14,65 +14,19 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
|
17
|
+
require 'terraform/groups_coercer'
|
18
|
+
require 'terraform/simple_config'
|
18
19
|
|
19
20
|
module Terraform
|
20
21
|
# Behaviour for the [:groups] config option
|
21
22
|
module GroupsConfig
|
22
|
-
|
23
|
-
configurable_class.required_config :groups do |_, value, configurable|
|
24
|
-
configurable.coerce_groups value: value
|
25
|
-
end
|
26
|
-
configurable_class.default_config :groups, []
|
27
|
-
end
|
28
|
-
|
29
|
-
def coerce_attributes(group:)
|
30
|
-
group[:attributes] = Hash group[:attributes]
|
31
|
-
rescue TypeError
|
32
|
-
config_error attribute: "groups][#{group}][:attributes",
|
33
|
-
expected: 'a mapping of Inspec attribute names to ' \
|
34
|
-
'Terraform output variable names'
|
35
|
-
end
|
36
|
-
|
37
|
-
def coerce_controls(group:)
|
38
|
-
group[:controls] = Array group[:controls]
|
39
|
-
end
|
40
|
-
|
41
|
-
def coerce_groups(value:)
|
42
|
-
config[:groups] = Array(value).map do |group|
|
43
|
-
Group.new data: coerced_group(value: group)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def coerce_hostnames(group:)
|
48
|
-
group[:hostnames] = String group[:hostnames]
|
49
|
-
end
|
50
|
-
|
51
|
-
def coerce_name(group:)
|
52
|
-
group[:name] = String group[:name]
|
53
|
-
end
|
54
|
-
|
55
|
-
def coerce_port(group:)
|
56
|
-
group[:port] = Integer group.fetch(:port) { transport[:port] }
|
57
|
-
rescue ArgumentError, TypeError
|
58
|
-
config_error attribute: "groups][#{group}][:port", expected: 'an integer'
|
59
|
-
end
|
60
|
-
|
61
|
-
def coerce_username(group:)
|
62
|
-
group[:username] = String group.fetch(:username) { transport[:username] }
|
63
|
-
end
|
23
|
+
include ::Terraform::SimpleConfig
|
64
24
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
coerce_name group: group
|
71
|
-
coerce_port group: group
|
72
|
-
coerce_username group: group
|
73
|
-
end
|
74
|
-
rescue TypeError
|
75
|
-
config_error attribute: "groups][#{value}", expected: 'a group mapping'
|
25
|
+
def self.extended(configurable_class)
|
26
|
+
configurable_class
|
27
|
+
.configure_required attr: :groups,
|
28
|
+
coercer_class: ::Terraform::GroupsCoercer,
|
29
|
+
default_value: []
|
76
30
|
end
|
77
31
|
end
|
78
32
|
end
|
@@ -0,0 +1,37 @@
|
|
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/simple_coercer'
|
18
|
+
|
19
|
+
module Terraform
|
20
|
+
# A coercer for config values that must be integers
|
21
|
+
class IntegerCoercer
|
22
|
+
def coerce(attr:, value:)
|
23
|
+
coercer.coerce attr: attr, value: value
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_accessor :coercer
|
29
|
+
|
30
|
+
def initialize(configurable:)
|
31
|
+
self.coercer =
|
32
|
+
::Terraform::SimpleCoercer.new configurable: configurable,
|
33
|
+
expected: 'an integer',
|
34
|
+
method: method(:Integer)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -15,13 +15,14 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
17
|
module Terraform
|
18
|
-
#
|
19
|
-
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
# A null parser for when there are no outputs defined
|
19
|
+
class NoOutputParser
|
20
|
+
def each_name; end
|
21
|
+
|
22
|
+
def iterate_parsed_output; end
|
23
|
+
|
24
|
+
def parsed_output
|
25
|
+
''
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -14,46 +14,10 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require '
|
18
|
-
require_relative 'command'
|
19
|
-
require_relative 'command_extender'
|
20
|
-
require_relative 'zero_six_output'
|
21
|
-
require_relative 'zero_seven_output'
|
17
|
+
require 'terraform/command'
|
22
18
|
|
23
19
|
module Terraform
|
24
|
-
#
|
25
|
-
class OutputCommand < Command
|
26
|
-
include CommandExtender
|
27
|
-
|
28
|
-
def name
|
29
|
-
'output'
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
attr_accessor :list, :state, :return_raw
|
35
|
-
|
36
|
-
def handle_error(exception:)
|
37
|
-
raise exception if !exception.is_a?(
|
38
|
-
Mixlib::ShellOut::ShellCommandFailed
|
39
|
-
) | !exception.message.match(/no outputs/)
|
40
|
-
|
41
|
-
define_singleton_method :output do
|
42
|
-
return '{}' if return_raw
|
43
|
-
|
44
|
-
list ? [] : ''
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def initialize_attributes(list:, version:, state:, return_raw: false)
|
49
|
-
extend_behaviour version: version
|
50
|
-
self.list = list
|
51
|
-
self.state = state
|
52
|
-
self.return_raw = return_raw
|
53
|
-
end
|
54
|
-
|
55
|
-
def version_behaviours
|
56
|
-
{ /v0.[7-8]/ => ZeroSevenOutput, /v0.6/ => ZeroSixOutput }
|
57
|
-
end
|
20
|
+
# A command to retrieve extract values of output variables
|
21
|
+
class OutputCommand < ::Terraform::Command
|
58
22
|
end
|
59
23
|
end
|
@@ -0,0 +1,55 @@
|
|
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 'json'
|
18
|
+
require 'terraform/deprecated_output_parser'
|
19
|
+
|
20
|
+
module Terraform
|
21
|
+
# A parser for output command values
|
22
|
+
class OutputParser
|
23
|
+
def self.create(output:, version:)
|
24
|
+
version.if_json_not_supported do
|
25
|
+
return ::Terraform::DeprecatedOutputParser.new output: output
|
26
|
+
end
|
27
|
+
|
28
|
+
new output: output
|
29
|
+
end
|
30
|
+
|
31
|
+
def each_name(&block)
|
32
|
+
json_output.each_key(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def iterate_parsed_output(&block)
|
36
|
+
Array(parsed_output).each(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def parsed_output
|
40
|
+
json_output.fetch 'value'
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_accessor :output
|
46
|
+
|
47
|
+
def initialize(output:)
|
48
|
+
self.output = output
|
49
|
+
end
|
50
|
+
|
51
|
+
def json_output
|
52
|
+
::JSON.parse output
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -14,21 +14,19 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
+
require 'terraform/integer_coercer'
|
18
|
+
require 'terraform/simple_config'
|
19
|
+
|
17
20
|
module Terraform
|
18
21
|
# Behaviour for the [:parallelism] config option
|
19
22
|
module ParallelismConfig
|
20
|
-
|
21
|
-
configurable_class
|
22
|
-
.required_config :parallelism do |_, value, configurable|
|
23
|
-
configurable.coerce_parallelism value: value
|
24
|
-
end
|
25
|
-
configurable_class.default_config :parallelism, 10
|
26
|
-
end
|
23
|
+
include ::Terraform::SimpleConfig
|
27
24
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
def self.extended(configurable_class)
|
26
|
+
configurable_class
|
27
|
+
.configure_required attr: :parallelism,
|
28
|
+
coercer_class: ::Terraform::IntegerCoercer,
|
29
|
+
default_value: 10
|
32
30
|
end
|
33
31
|
end
|
34
32
|
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/simple_coercer'
|
18
|
+
|
19
|
+
module Terraform
|
20
|
+
# A coercer for config values that must be pathnames
|
21
|
+
class PathnameCoercer
|
22
|
+
def coerce(attr:, value:)
|
23
|
+
coercer.coerce attr: attr, value: value
|
24
|
+
configurable[attr] =
|
25
|
+
configurable[attr].expand_path configurable[:kitchen_root]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_accessor :coercer, :configurable
|
31
|
+
|
32
|
+
def initialize(configurable:)
|
33
|
+
self.coercer =
|
34
|
+
::Terraform::SimpleCoercer.new configurable: configurable,
|
35
|
+
expected: 'a pathname',
|
36
|
+
method: method(:Pathname)
|
37
|
+
self.configurable = configurable
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -14,51 +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_output_file'
|
19
19
|
|
20
20
|
module Terraform
|
21
|
-
#
|
22
|
-
class PlanCommand < Command
|
23
|
-
include ColorSwitch
|
24
|
-
|
25
|
-
def name
|
26
|
-
'plan'
|
27
|
-
end
|
28
|
-
|
29
|
-
def options
|
30
|
-
"-destroy=#{destroy} -input=false -out=#{out} " \
|
31
|
-
"-parallelism=#{parallelism} -state=#{state} " \
|
32
|
-
"#{color_switch}#{processed_variables}#{processed_variable_files}"
|
33
|
-
end
|
34
|
-
|
21
|
+
# A command to plan an execution
|
22
|
+
class PlanCommand < ::Terraform::Command
|
35
23
|
private
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def initialize_attributes(
|
41
|
-
color:, destroy:, out:, parallelism:, state:, variables:, variable_files:
|
42
|
-
)
|
43
|
-
self.color = color
|
44
|
-
self.destroy = destroy
|
45
|
-
self.out = out
|
46
|
-
self.parallelism = parallelism
|
47
|
-
self.state = state
|
48
|
-
self.variables = variables
|
49
|
-
self.variable_files = variable_files
|
50
|
-
end
|
51
|
-
|
52
|
-
def processed_variable_files
|
53
|
-
variable_files.each_with_object String.new do |pathname, string|
|
54
|
-
string.concat " -var-file=#{pathname}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def processed_variables
|
59
|
-
variables.each_with_object String.new do |(key, value), string|
|
60
|
-
string.concat " -var='#{key}=#{value}'"
|
61
|
-
end
|
25
|
+
def initialize(target: '')
|
26
|
+
super
|
27
|
+
preparations.push ::Terraform::PrepareOutputFile.new file: options.out
|
62
28
|
end
|
63
29
|
end
|
64
30
|
end
|