kitchen-terraform 1.0.2 → 2.0.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 +3 -3
- data/lib/kitchen/driver/terraform.rb +363 -221
- data/lib/kitchen/provisioner/terraform.rb +2 -3
- data/lib/kitchen/terraform.rb +3 -1
- data/lib/kitchen/terraform/clear_directory.rb +38 -0
- data/lib/kitchen/terraform/client/command.rb +168 -0
- data/lib/kitchen/terraform/client/options.rb +275 -0
- data/lib/kitchen/terraform/client_version_verifier.rb +57 -0
- data/lib/{terraform/debug_logger.rb → kitchen/terraform/config_attribute.rb} +7 -13
- data/lib/kitchen/terraform/config_attribute/backend_configurations.rb +53 -0
- data/lib/kitchen/terraform/config_attribute/color.rb +56 -0
- data/lib/kitchen/terraform/config_attribute/command_timeout.rb +52 -0
- data/lib/kitchen/terraform/config_attribute/directory.rb +54 -0
- data/lib/kitchen/terraform/config_attribute/groups.rb +96 -0
- data/lib/kitchen/terraform/config_attribute/lock_timeout.rb +52 -0
- data/lib/kitchen/terraform/config_attribute/parallelism.rb +53 -0
- data/lib/kitchen/terraform/config_attribute/plugin_directory.rb +55 -0
- data/lib/kitchen/terraform/config_attribute/state.rb +55 -0
- data/lib/kitchen/terraform/config_attribute/variable_files.rb +51 -0
- data/lib/kitchen/terraform/config_attribute/variables.rb +53 -0
- data/lib/kitchen/terraform/config_attribute/verify_plugins.rb +52 -0
- data/lib/kitchen/terraform/config_attribute_cacher.rb +44 -0
- data/lib/kitchen/terraform/config_attribute_definer.rb +66 -0
- data/lib/kitchen/terraform/config_predicates.rb +21 -0
- data/lib/kitchen/terraform/config_predicates/hash_of_symbols_and_strings.rb +72 -0
- data/lib/{terraform.rb → kitchen/terraform/config_schemas.rb} +4 -2
- data/lib/kitchen/terraform/config_schemas/array_of_hashes_of_symbols_and_strings.rb +47 -0
- data/lib/kitchen/terraform/config_schemas/array_of_strings.rb +31 -0
- data/lib/kitchen/terraform/config_schemas/boolean.rb +27 -0
- data/lib/kitchen/terraform/config_schemas/hash_of_symbols_and_strings.rb +32 -0
- data/lib/kitchen/terraform/config_schemas/integer.rb +27 -0
- data/lib/kitchen/terraform/config_schemas/optional_string.rb +31 -0
- data/lib/kitchen/terraform/config_schemas/string.rb +26 -0
- data/lib/kitchen/terraform/configurable.rb +75 -0
- data/lib/kitchen/terraform/file_path_config_attribute_definer.rb +48 -0
- data/lib/{terraform/project_version.rb → kitchen/terraform/version.rb} +3 -3
- data/lib/kitchen/verifier/terraform.rb +40 -129
- data/lib/kitchen/verifier/terraform/configure_inspec_runner_attributes.rb +7 -4
- data/lib/kitchen/verifier/terraform/enumerate_groups_and_hostnames.rb +2 -2
- metadata +69 -43
- metadata.gz.sig +0 -0
- data/lib/kitchen/driver/terraform/verify_client_version.rb +0 -44
- data/lib/kitchen/driver/terraform/workflow.rb +0 -90
- data/lib/kitchen/terraform/client/apply.rb +0 -38
- data/lib/kitchen/terraform/client/execute_command.rb +0 -56
- data/lib/kitchen/terraform/client/get.rb +0 -35
- data/lib/kitchen/terraform/client/output.rb +0 -50
- data/lib/kitchen/terraform/client/plan.rb +0 -42
- data/lib/kitchen/terraform/client/process_options.rb +0 -87
- data/lib/kitchen/terraform/client/validate.rb +0 -35
- data/lib/kitchen/terraform/client/version.rb +0 -48
- data/lib/kitchen/terraform/define_config_attribute.rb +0 -39
- data/lib/kitchen/terraform/define_integer_config_attribute.rb +0 -43
- data/lib/kitchen/terraform/define_string_config_attribute.rb +0 -43
- data/lib/terraform/configurable.rb +0 -42
@@ -0,0 +1,53 @@
|
|
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/terraform/config_attribute"
|
18
|
+
require "kitchen/terraform/config_attribute_cacher"
|
19
|
+
require "kitchen/terraform/config_attribute_definer"
|
20
|
+
require "kitchen/terraform/config_schemas/integer"
|
21
|
+
|
22
|
+
# The +:parallelism+ configuration attribute is an optional integer which represents the maximum number of concurrent
|
23
|
+
# operations to allow while walking the resource graph for the Terraform Client apply command.
|
24
|
+
#
|
25
|
+
# @abstract It must be included by a plugin class in order to be used.
|
26
|
+
# @see https://www.terraform.io/docs/commands/apply.html#parallelism-n Terraform: Command: apply: -parallelism
|
27
|
+
# @see https://www.terraform.io/docs/internals/graph.html Terraform: Resource Graph
|
28
|
+
module ::Kitchen::Terraform::ConfigAttribute::Parallelism
|
29
|
+
# A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
|
30
|
+
#
|
31
|
+
# @param plugin_class [::Kitchen::Configurable] A plugin class.
|
32
|
+
# @return [void]
|
33
|
+
def self.included(plugin_class)
|
34
|
+
::Kitchen::Terraform::ConfigAttributeDefiner
|
35
|
+
.new(
|
36
|
+
attribute: self,
|
37
|
+
schema: ::Kitchen::Terraform::ConfigSchemas::Integer
|
38
|
+
)
|
39
|
+
.define plugin_class: plugin_class
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [::Symbol] the symbol corresponding to the attribute.
|
43
|
+
def self.to_sym
|
44
|
+
:parallelism
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ::Kitchen::Terraform::ConfigAttributeCacher
|
48
|
+
|
49
|
+
# @return [::Integer] a maximum of 10 concurrent operations.
|
50
|
+
def config_parallelism_default_value
|
51
|
+
10
|
52
|
+
end
|
53
|
+
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 "kitchen/terraform/config_attribute"
|
18
|
+
require "kitchen/terraform/config_attribute_cacher"
|
19
|
+
require "kitchen/terraform/config_schemas/optional_string"
|
20
|
+
require "kitchen/terraform/file_path_config_attribute_definer"
|
21
|
+
|
22
|
+
# The +:plugin_directory+ configuration attribute is an optional string which contains the path to the directory
|
23
|
+
# containing customized Terraform provider plugins to install in place of the official Terraform provider plugins.
|
24
|
+
#
|
25
|
+
# @abstract It must be included by a plugin class in order to be used.
|
26
|
+
# @see https://www.terraform.io/docs/commands/init.html#plugin-installation Terraform: Command: init: Plugin
|
27
|
+
# Installation
|
28
|
+
module ::Kitchen::Terraform::ConfigAttribute::PluginDirectory
|
29
|
+
# A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
|
30
|
+
#
|
31
|
+
# @param plugin_class [::Kitchen::Configurable] A plugin class.
|
32
|
+
# @return [void]
|
33
|
+
def self.included(plugin_class)
|
34
|
+
::Kitchen::Terraform::FilePathConfigAttributeDefiner
|
35
|
+
.new(
|
36
|
+
attribute: self,
|
37
|
+
schema: ::Kitchen::Terraform::ConfigSchemas::OptionalString
|
38
|
+
)
|
39
|
+
.define plugin_class: plugin_class
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [::Symbol] the symbol corresponding to this attribute.
|
43
|
+
def self.to_sym
|
44
|
+
:plugin_directory
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ::Kitchen::Terraform::ConfigAttributeCacher
|
48
|
+
|
49
|
+
# There is no default value because any value will disable the normal Terraform plugin retrieval process.
|
50
|
+
#
|
51
|
+
# @return [nil]
|
52
|
+
def config_plugin_directory_default_value
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
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 "kitchen/terraform/config_attribute"
|
18
|
+
require "kitchen/terraform/config_attribute_cacher"
|
19
|
+
require "kitchen/terraform/config_schemas/string"
|
20
|
+
require "kitchen/terraform/file_path_config_attribute_definer"
|
21
|
+
|
22
|
+
# The +:state+ configuration attribute is an optianl string which contains the path to the Terraform state file which
|
23
|
+
# will be generated and managed.
|
24
|
+
#
|
25
|
+
# @abstract It must be included by a plugin class in order to be used.
|
26
|
+
# @see https://www.terraform.io/docs/commands/apply.html#state-path Terraform: Command: apply: -state-path
|
27
|
+
# @see https://www.terraform.io/docs/state/index.html Terraform: State
|
28
|
+
module ::Kitchen::Terraform::ConfigAttribute::State
|
29
|
+
# A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
|
30
|
+
#
|
31
|
+
# @param plugin_class [::Kitchen::Configurable] A plugin class.
|
32
|
+
# @return [void]
|
33
|
+
def self.included(plugin_class)
|
34
|
+
::Kitchen::Terraform::FilePathConfigAttributeDefiner
|
35
|
+
.new(
|
36
|
+
attribute: self,
|
37
|
+
schema: ::Kitchen::Terraform::ConfigSchemas::String
|
38
|
+
)
|
39
|
+
.define plugin_class: plugin_class
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [::Symbol] the symbol corresponding to this attribute.
|
43
|
+
def self.to_sym
|
44
|
+
:state
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ::Kitchen::Terraform::ConfigAttributeCacher
|
48
|
+
|
49
|
+
# The path to a file under the kitchen-terraform suite directory.
|
50
|
+
#
|
51
|
+
# @return [::String] +".kitchen/kitchen-terraform/<suite_name>/terraform.tfstate"+.
|
52
|
+
def config_state_default_value
|
53
|
+
instance_pathname filename: "terraform.tfstate"
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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/terraform/config_attribute"
|
18
|
+
require "kitchen/terraform/config_attribute_cacher"
|
19
|
+
require "kitchen/terraform/config_schemas/array_of_strings"
|
20
|
+
require "kitchen/terraform/file_path_config_attribute_definer"
|
21
|
+
|
22
|
+
# The +:variable_files+ configuration attribute is an optional array of string which represent file paths.
|
23
|
+
#
|
24
|
+
# @abstract It must be included by a plugin class in order to be used.
|
25
|
+
# @see https://www.terraform.io/docs/commands/apply.html#var-file-foo Terraform: Command: apply: -var-file
|
26
|
+
module ::Kitchen::Terraform::ConfigAttribute::VariableFiles
|
27
|
+
# A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
|
28
|
+
#
|
29
|
+
# @param plugin_class [::Kitchen::Configurable] A plugin class.
|
30
|
+
# @return [void]
|
31
|
+
def self.included(plugin_class)
|
32
|
+
::Kitchen::Terraform::FilePathConfigAttributeDefiner
|
33
|
+
.new(
|
34
|
+
attribute: self,
|
35
|
+
schema: ::Kitchen::Terraform::ConfigSchemas::ArrayOfStrings
|
36
|
+
)
|
37
|
+
.define plugin_class: plugin_class
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [::Symbol] the symbol corresponding to this attribute.
|
41
|
+
def self.to_sym
|
42
|
+
:variable_files
|
43
|
+
end
|
44
|
+
|
45
|
+
extend ::Kitchen::Terraform::ConfigAttributeCacher
|
46
|
+
|
47
|
+
# @return [::Array] an empty array.
|
48
|
+
def config_variable_files_default_value
|
49
|
+
[]
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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/terraform/config_attribute"
|
18
|
+
require "kitchen/terraform/config_attribute_cacher"
|
19
|
+
require "kitchen/terraform/config_attribute_definer"
|
20
|
+
require "kitchen/terraform/config_schemas/hash_of_symbols_and_strings"
|
21
|
+
|
22
|
+
# The +:variables+ configuration attribute is an optional hash of symbols and strings comprising Terraform variables to
|
23
|
+
# be overridden during the application of Terraform state changes.
|
24
|
+
#
|
25
|
+
# @abstract It must be included by a plugin class in order to be used.
|
26
|
+
# @see https://www.terraform.io/docs/commands/apply.html#var-39-foo-bar-39- Terraform: Command: apply: -var
|
27
|
+
# @see https://www.terraform.io/docs/configuration/variables.html Terraform: Variables
|
28
|
+
module ::Kitchen::Terraform::ConfigAttribute::Variables
|
29
|
+
# A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
|
30
|
+
#
|
31
|
+
# @param plugin_class [::Kitchen::Configurable] A plugin class.
|
32
|
+
# @return [void]
|
33
|
+
def self.included(plugin_class)
|
34
|
+
::Kitchen::Terraform::ConfigAttributeDefiner
|
35
|
+
.new(
|
36
|
+
attribute: self,
|
37
|
+
schema: ::Kitchen::Terraform::ConfigSchemas::HashOfSymbolsAndStrings
|
38
|
+
)
|
39
|
+
.define plugin_class: plugin_class
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [::Symbol] the symbol corresponding to this attribute.
|
43
|
+
def self.to_sym
|
44
|
+
:variables
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ::Kitchen::Terraform::ConfigAttributeCacher
|
48
|
+
|
49
|
+
# @return [::Hash] an empty hash.
|
50
|
+
def config_variables_default_value
|
51
|
+
{}
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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/terraform/config_attribute"
|
18
|
+
require "kitchen/terraform/config_attribute_cacher"
|
19
|
+
require "kitchen/terraform/config_attribute_definer"
|
20
|
+
require "kitchen/terraform/config_schemas/boolean"
|
21
|
+
|
22
|
+
# The +:verify_plugins+ configuration attribute is an optional boolean which toggles verification of Terraform plugins.
|
23
|
+
#
|
24
|
+
# @abstract It must be included by a plugin class in order to be used.
|
25
|
+
# @see https://www.terraform.io/docs/commands/init.html#plugin-installation Terraform: Command: init: Plugin
|
26
|
+
# Installation
|
27
|
+
module ::Kitchen::Terraform::ConfigAttribute::VerifyPlugins
|
28
|
+
# A callback to define the configuration attribute which is invoked when this module is included in a plugin class.
|
29
|
+
#
|
30
|
+
# @param plugin_class [::Kitchen::Configurable] A plugin class.
|
31
|
+
# @return [void]
|
32
|
+
def self.included(plugin_class)
|
33
|
+
::Kitchen::Terraform::ConfigAttributeDefiner
|
34
|
+
.new(
|
35
|
+
attribute: self,
|
36
|
+
schema: ::Kitchen::Terraform::ConfigSchemas::Boolean
|
37
|
+
)
|
38
|
+
.define plugin_class: plugin_class
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [::Symbol] the symbol corresponding to the attribute.
|
42
|
+
def self.to_sym
|
43
|
+
:verify_plugins
|
44
|
+
end
|
45
|
+
|
46
|
+
extend ::Kitchen::Terraform::ConfigAttributeCacher
|
47
|
+
|
48
|
+
# @return [true]
|
49
|
+
def config_verify_plugins_default_value
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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/terraform"
|
18
|
+
|
19
|
+
# Behaviour to cache configuration attribute lookups.
|
20
|
+
module ::Kitchen::Terraform::ConfigAttributeCacher
|
21
|
+
# A callback to define an attribute lookup cache which is invoked when this module is extended by a
|
22
|
+
# configuration attribute.
|
23
|
+
#
|
24
|
+
# @param configuration_attribute [::Kitchen::Terraform::ConfigAttribute] a configuration attribute.
|
25
|
+
# @return [void]
|
26
|
+
def self.extended(configuration_attribute)
|
27
|
+
configuration_attribute.define_cache
|
28
|
+
end
|
29
|
+
|
30
|
+
# Defines an instance method named "config_<attribute_name>" which caches the value of the configuration attribute
|
31
|
+
# lookup using an equivalently named instance variable.
|
32
|
+
#
|
33
|
+
# @param attribute_name [::Symbol] the name of the attribute
|
34
|
+
def define_cache(attribute_name: to_sym)
|
35
|
+
define_method "config_#{attribute_name}" do
|
36
|
+
instance_variable_defined? "@config_#{attribute_name}" and
|
37
|
+
instance_variable_get "@config_#{attribute_name}" or
|
38
|
+
instance_variable_set(
|
39
|
+
"@config_#{attribute_name}",
|
40
|
+
config.fetch(attribute_name)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,66 @@
|
|
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/terraform"
|
18
|
+
|
19
|
+
# Defines a configuration attribute on a plugin class.
|
20
|
+
class ::Kitchen::Terraform::ConfigAttributeDefiner
|
21
|
+
# Defines the configuration attribute on a plugin class.
|
22
|
+
#
|
23
|
+
# @param plugin_class [::Kitchen::Configurable] a plugin class.
|
24
|
+
# @return [void]
|
25
|
+
def define(plugin_class:)
|
26
|
+
plugin_class
|
27
|
+
.required_config @attribute do |_attribute, value, _plugin|
|
28
|
+
process(
|
29
|
+
messages:
|
30
|
+
@schema
|
31
|
+
.call(value: value)
|
32
|
+
.messages,
|
33
|
+
plugin_class: plugin_class
|
34
|
+
)
|
35
|
+
end
|
36
|
+
plugin_class
|
37
|
+
.default_config @attribute do |plugin|
|
38
|
+
plugin.send "config_#{@attribute}_default_value"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Initializes a definer.
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
# @param attribute [::Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class.
|
48
|
+
# @param schema [::Dry::Validation::Schema] a schema to use for validation of values of the attribute.
|
49
|
+
def initialize(attribute:, schema:)
|
50
|
+
@attribute = attribute.to_sym
|
51
|
+
@schema = schema
|
52
|
+
end
|
53
|
+
|
54
|
+
# Processes the schema messages of the configuration attribute.
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
# @param messages [::Array] messages generated by validating the schema against a value.
|
58
|
+
# @param plugin_class [::Kitchen::Configurable] a plugin class.
|
59
|
+
def process(messages:, plugin_class:)
|
60
|
+
messages.empty? or
|
61
|
+
raise(
|
62
|
+
::Kitchen::UserError,
|
63
|
+
"#{plugin_class} configuration: #{@attribute} #{messages}"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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/terraform"
|
18
|
+
|
19
|
+
# The namespace for configuration attribute predicates.
|
20
|
+
module ::Kitchen::Terraform::ConfigPredicates
|
21
|
+
end
|