kitchen-terraform 5.1.1 → 5.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 +0 -0
- data/README.md +37 -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 +143 -80
- 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
@@ -0,0 +1,23 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
# CommandFlag is the namespace for command flags.
|
20
|
+
module CommandFlag
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
module CommandFlag
|
20
|
+
# BackendConfig is the class of objects which control the arguments to the backend configuration.
|
21
|
+
class BackendConfig
|
22
|
+
# #initialize prepares a new instance of the class.
|
23
|
+
#
|
24
|
+
# @param arguments [Hash{String=>String}] the arguments.
|
25
|
+
# @return [Kitchen::Terraform::CommandFlag::BackendConfig]
|
26
|
+
def initialize(arguments:)
|
27
|
+
self.arguments = arguments
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] the backend configuration flag.
|
31
|
+
def to_s
|
32
|
+
arguments.map do |key, value|
|
33
|
+
"-backend-config=\"#{key}=#{value}\""
|
34
|
+
end.join " "
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_accessor :arguments
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
module CommandFlag
|
20
|
+
# Color is the class of objects which control coloured output.
|
21
|
+
class Color
|
22
|
+
# #initialize prepares a new instance of the class.
|
23
|
+
#
|
24
|
+
# @param enabled [Boolean] a toggle to enable or disable color.
|
25
|
+
# @return [Kitchen::Terraform::CommandFlag::Color]
|
26
|
+
def initialize(enabled:)
|
27
|
+
self.enabled = enabled
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] the color flag.
|
31
|
+
def to_s
|
32
|
+
if enabled
|
33
|
+
""
|
34
|
+
else
|
35
|
+
"-no-color"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_accessor :enabled
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
module CommandFlag
|
20
|
+
# LockTimeout is the class of objects which control the duration in which to retry the acquisition of the state
|
21
|
+
# lock.
|
22
|
+
class LockTimeout
|
23
|
+
# #initialize prepares a new instance of the class.
|
24
|
+
#
|
25
|
+
# @param duration [Integer] the duration in seconds.
|
26
|
+
# @return [Kitchen::Terraform::CommandFlag::LockTimeout]
|
27
|
+
def initialize(duration:)
|
28
|
+
self.duration = duration
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [String] the backend configuration flag.
|
32
|
+
def to_s
|
33
|
+
"-lock-timeout=#{duration}s"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_accessor :duration
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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 "shellwords"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module CommandFlag
|
22
|
+
# PluginDir is the class of objects which control the location of the directory which contains plugin binaries.
|
23
|
+
class PluginDir
|
24
|
+
# #initialize prepares a new instance of the class.
|
25
|
+
#
|
26
|
+
# @param pathname [String] the pathname of the directory.
|
27
|
+
# @return [Kitchen::Terraform::CommandFlag::PluginDir]
|
28
|
+
def initialize(pathname:)
|
29
|
+
self.pathname = pathname.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String] the plugin directory flag.
|
33
|
+
def to_s
|
34
|
+
if pathname.empty?
|
35
|
+
""
|
36
|
+
else
|
37
|
+
"-plugin-dir=\"#{::Shellwords.shelljoin ::Shellwords.shellsplit pathname}\""
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_accessor :pathname
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
module CommandFlag
|
20
|
+
# Upgrade is the class of objects which control the upgrade of existing modules and plugins.
|
21
|
+
class Upgrade
|
22
|
+
# #initialize prepares a new instance of the class.
|
23
|
+
#
|
24
|
+
# @param enabled [Boolean] a toggle to enable or disable the upgrade.
|
25
|
+
# @return [Kitchen::Terraform::CommandFlag::Upgrade]
|
26
|
+
def initialize(enabled:)
|
27
|
+
self.enabled = enabled
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] the upgrade flag.
|
31
|
+
def to_s
|
32
|
+
if enabled
|
33
|
+
"-upgrade"
|
34
|
+
else
|
35
|
+
""
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_accessor :enabled
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
module Kitchen
|
18
|
+
module Terraform
|
19
|
+
module CommandFlag
|
20
|
+
# Var is the class of objects which control the configuration variables.
|
21
|
+
class Var
|
22
|
+
# #initialize prepares a new instance of the class.
|
23
|
+
#
|
24
|
+
# @param arguments [Hash{String=>String}] the arguments.
|
25
|
+
# @return [Kitchen::Terraform::CommandFlag::Var]
|
26
|
+
def initialize(arguments:)
|
27
|
+
self.arguments = arguments
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] the backend configuration flag.
|
31
|
+
def to_s
|
32
|
+
arguments.map do |key, value|
|
33
|
+
"-var=\"#{key}=#{value}\""
|
34
|
+
end.join " "
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_accessor :arguments
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 "shellwords"
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
module Terraform
|
21
|
+
module CommandFlag
|
22
|
+
# VarFile is the class of objects which control the locations of configuration variables files.
|
23
|
+
class VarFile
|
24
|
+
# #initialize prepares a new instance of the class.
|
25
|
+
#
|
26
|
+
# @param pathnames [Array[String]] the pathnames.
|
27
|
+
# @return [Kitchen::Terraform::CommandFlag::VarFile]
|
28
|
+
def initialize(pathnames:)
|
29
|
+
self.pathnames = pathnames
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String] the backend configuration flag.
|
33
|
+
def to_s
|
34
|
+
pathnames.map do |path|
|
35
|
+
"-var-file=\"#{::Shellwords.shelljoin ::Shellwords.shellsplit path}\""
|
36
|
+
end.join " "
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_accessor :pathnames
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -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.
|
@@ -14,71 +14,74 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require "kitchen/terraform"
|
18
17
|
require "kitchen/terraform/config_attribute_cacher"
|
19
18
|
require "kitchen/terraform/config_attribute_definer"
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
module Kitchen
|
21
|
+
module Terraform
|
22
|
+
# ConfigAttribute is the class of objects which apply the behaviour of a configuration attribute to a module which must
|
23
|
+
# be included by a plugin class.
|
24
|
+
class ConfigAttribute
|
25
|
+
# #apply applies the configuration attribute behaviour to a module.
|
26
|
+
#
|
27
|
+
# @param config_attribute [Module] a module.
|
28
|
+
# @return [self]
|
29
|
+
def apply(config_attribute:)
|
30
|
+
self.config_attribute = config_attribute
|
31
|
+
define_singleton_included
|
32
|
+
define_singleton_to_sym
|
33
|
+
define_config_attribute_default_value
|
34
|
+
|
35
|
+
self
|
36
|
+
end
|
34
37
|
|
35
|
-
|
38
|
+
# #initialize prepares a new instance of the class.
|
39
|
+
#
|
40
|
+
# @param attribute [Symbol] the name of the attribute.
|
41
|
+
# @param default_value [Proc] a block which returns the default value for the attribute.
|
42
|
+
# @param schema [Dry::Validation::Schema] the schema of the attribute.
|
43
|
+
def initialize(attribute:, default_value:, schema:)
|
44
|
+
self.attribute = attribute
|
45
|
+
self.default_value = default_value
|
46
|
+
self.schema = schema
|
47
|
+
end
|
36
48
|
|
37
|
-
|
38
|
-
:attribute,
|
39
|
-
:config_attribute,
|
40
|
-
:default_value,
|
41
|
-
:schema
|
42
|
-
)
|
49
|
+
private
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:
|
49
|
-
"config_#{attribute}_default_value",
|
50
|
-
&default_value
|
51
|
+
attr_accessor(
|
52
|
+
:attribute,
|
53
|
+
:config_attribute,
|
54
|
+
:default_value,
|
55
|
+
:schema
|
51
56
|
)
|
52
|
-
end
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
def define_config_attribute_default_value
|
59
|
+
config_attribute
|
60
|
+
.send(
|
61
|
+
:define_method,
|
62
|
+
"config_#{attribute}_default_value",
|
63
|
+
&default_value
|
64
|
+
)
|
65
|
+
end
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
.new(
|
61
|
-
attribute: self,
|
62
|
-
schema: local_schema,
|
63
|
-
).define plugin_class: plugin_class
|
64
|
-
end
|
65
|
-
end
|
67
|
+
def define_singleton_included
|
68
|
+
local_schema = schema
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
config_attribute.define_singleton_method :included do |plugin_class|
|
71
|
+
::Kitchen::Terraform::ConfigAttributeDefiner.new(attribute: self, schema: local_schema).define(
|
72
|
+
plugin_class: plugin_class,
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
70
76
|
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
config_attribute.extend ::Kitchen::Terraform::ConfigAttributeCacher
|
76
|
-
end
|
77
|
+
def define_singleton_to_sym
|
78
|
+
local_attribute = attribute
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
config_attribute.define_singleton_method :to_sym do
|
81
|
+
local_attribute
|
82
|
+
end
|
83
|
+
config_attribute.extend ::Kitchen::Terraform::ConfigAttributeCacher
|
84
|
+
end
|
85
|
+
end
|
83
86
|
end
|
84
87
|
end
|