kitchen-terraform 0.7.0 → 1.0.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 +3 -1
- data/README.md +33 -359
- data/lib/kitchen/driver/terraform.rb +273 -57
- data/lib/kitchen/driver/terraform/verify_client_version.rb +44 -0
- data/lib/kitchen/driver/terraform/workflow.rb +90 -0
- data/lib/kitchen/provisioner/terraform.rb +31 -37
- data/lib/{terraform/get_command.rb → kitchen/terraform.rb} +3 -5
- data/lib/{terraform/deprecated_version.rb → kitchen/terraform/client.rb} +5 -12
- data/lib/kitchen/terraform/client/apply.rb +38 -0
- data/lib/kitchen/terraform/client/execute_command.rb +56 -0
- data/lib/kitchen/terraform/client/get.rb +35 -0
- data/lib/kitchen/terraform/client/output.rb +50 -0
- data/lib/kitchen/terraform/client/plan.rb +42 -0
- data/lib/kitchen/terraform/client/process_options.rb +87 -0
- data/lib/kitchen/terraform/client/validate.rb +35 -0
- data/lib/kitchen/terraform/client/version.rb +48 -0
- data/lib/{terraform/apply_timeout_config.rb → kitchen/terraform/create_directories.rb} +18 -11
- data/lib/kitchen/terraform/define_config_attribute.rb +39 -0
- data/lib/kitchen/terraform/define_integer_config_attribute.rb +43 -0
- data/lib/kitchen/terraform/define_string_config_attribute.rb +43 -0
- data/lib/kitchen/verifier/terraform.rb +186 -38
- data/lib/kitchen/verifier/terraform/configure_inspec_runner_attributes.rb +93 -0
- data/lib/kitchen/verifier/terraform/configure_inspec_runner_backend.rb +32 -0
- data/lib/kitchen/verifier/terraform/configure_inspec_runner_controls.rb +39 -0
- data/lib/{terraform/apply_command.rb → kitchen/verifier/terraform/configure_inspec_runner_host.rb} +11 -15
- data/lib/{terraform/deprecated_output_parser.rb → kitchen/verifier/terraform/configure_inspec_runner_port.rb} +16 -20
- data/lib/{terraform/deprecated_variables_coercer.rb → kitchen/verifier/terraform/configure_inspec_runner_user.rb} +16 -14
- data/lib/kitchen/verifier/terraform/enumerate_groups_and_hostnames.rb +67 -0
- data/lib/{terraform/version_command.rb → terraform.rb} +1 -5
- data/lib/terraform/configurable.rb +18 -61
- data/lib/terraform/debug_logger.rb +12 -12
- data/lib/terraform/project_version.rb +1 -1
- metadata +72 -135
- metadata.gz.sig +0 -0
- data/lib/terraform/cli_config.rb +0 -29
- data/lib/terraform/client.rb +0 -96
- data/lib/terraform/color_coercer.rb +0 -35
- data/lib/terraform/color_config.rb +0 -32
- data/lib/terraform/command.rb +0 -53
- data/lib/terraform/command_factory.rb +0 -111
- data/lib/terraform/command_option.rb +0 -65
- data/lib/terraform/command_options.rb +0 -103
- data/lib/terraform/destructive_plan_command.rb +0 -35
- data/lib/terraform/directory_config.rb +0 -32
- data/lib/terraform/file_configs.rb +0 -36
- data/lib/terraform/group.rb +0 -61
- data/lib/terraform/group_attributes.rb +0 -42
- data/lib/terraform/group_hostnames.rb +0 -38
- data/lib/terraform/groups_coercer.rb +0 -43
- data/lib/terraform/groups_config.rb +0 -32
- data/lib/terraform/integer_coercer.rb +0 -37
- data/lib/terraform/no_output_parser.rb +0 -28
- data/lib/terraform/output_command.rb +0 -23
- data/lib/terraform/output_parser.rb +0 -55
- data/lib/terraform/parallelism_config.rb +0 -32
- data/lib/terraform/pathname_coercer.rb +0 -40
- data/lib/terraform/plan_command.rb +0 -30
- data/lib/terraform/prepare_input_file.rb +0 -34
- data/lib/terraform/prepare_output_file.rb +0 -36
- data/lib/terraform/shell_out.rb +0 -59
- data/lib/terraform/show_command.rb +0 -30
- data/lib/terraform/simple_coercer.rb +0 -36
- data/lib/terraform/simple_config.rb +0 -28
- data/lib/terraform/unsupported_version.rb +0 -26
- data/lib/terraform/validate_command.rb +0 -23
- data/lib/terraform/variable_files_coercer.rb +0 -40
- data/lib/terraform/variable_files_config.rb +0 -32
- data/lib/terraform/variables_coercer.rb +0 -49
- data/lib/terraform/variables_config.rb +0 -32
- data/lib/terraform/version.rb +0 -73
@@ -1,35 +0,0 @@
|
|
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/prepare_input_file'
|
18
|
-
require 'terraform/plan_command'
|
19
|
-
|
20
|
-
module Terraform
|
21
|
-
# A command to plan a destructive execution
|
22
|
-
class DestructivePlanCommand < ::Terraform::PlanCommand
|
23
|
-
def name
|
24
|
-
'plan'
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def initialize(target: '')
|
30
|
-
super
|
31
|
-
preparations
|
32
|
-
.push ::Terraform::PrepareInputFile.new file: options.state
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,32 +0,0 @@
|
|
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
|
-
require 'terraform/simple_config'
|
19
|
-
|
20
|
-
module Terraform
|
21
|
-
# Behaviour for the [:directory] config option
|
22
|
-
module DirectoryConfig
|
23
|
-
include ::Terraform::SimpleConfig
|
24
|
-
|
25
|
-
def self.extended(configurable_class)
|
26
|
-
configurable_class.configure_required(
|
27
|
-
attr: :directory, coercer_class: ::Terraform::PathnameCoercer,
|
28
|
-
default_value: lambda do |configurable| configurable[:kitchen_root] end
|
29
|
-
)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,36 +0,0 @@
|
|
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
|
-
require 'terraform/simple_config'
|
19
|
-
|
20
|
-
module Terraform
|
21
|
-
# Behaviour for the [:plan] and [:state] config options
|
22
|
-
module FileConfigs
|
23
|
-
include ::Terraform::SimpleConfig
|
24
|
-
|
25
|
-
def self.extended(configurable_class)
|
26
|
-
%i(plan state).each do |attr|
|
27
|
-
configurable_class.configure_required(
|
28
|
-
attr: attr, coercer_class: ::Terraform::PathnameCoercer,
|
29
|
-
default_value: lambda do |configurable|
|
30
|
-
configurable.instance_pathname filename: "terraform.tf#{attr}"
|
31
|
-
end
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/terraform/group.rb
DELETED
@@ -1,61 +0,0 @@
|
|
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/dash'
|
18
|
-
require 'hashie/extensions/dash/coercion'
|
19
|
-
require 'terraform/group_attributes'
|
20
|
-
require 'terraform/group_hostnames'
|
21
|
-
|
22
|
-
module Terraform
|
23
|
-
# Group of Terraform server instances to be verified
|
24
|
-
class Group < ::Hashie::Dash
|
25
|
-
include ::Hashie::Extensions::Dash::Coercion
|
26
|
-
|
27
|
-
property :attributes, coerce: ::Terraform::GroupAttributes,
|
28
|
-
default: ::Terraform::GroupAttributes.new
|
29
|
-
|
30
|
-
property :controls, coerce: ::Array[::String], default: []
|
31
|
-
|
32
|
-
property :hostname, coerce: ::String
|
33
|
-
|
34
|
-
property :hostnames, coerce: ::Terraform::GroupHostnames,
|
35
|
-
default: ::Terraform::GroupHostnames.new
|
36
|
-
|
37
|
-
property :name, coerce: ::String, required: true
|
38
|
-
|
39
|
-
property :port
|
40
|
-
|
41
|
-
coerce_key(:port, lambda do |value| Integer value end)
|
42
|
-
|
43
|
-
property :username, coerce: ::String
|
44
|
-
|
45
|
-
def description
|
46
|
-
"host '#{hostname}' of group '#{name}'"
|
47
|
-
end
|
48
|
-
|
49
|
-
def resolve(client:)
|
50
|
-
attributes.resolve client: client
|
51
|
-
hostnames
|
52
|
-
.resolve(client: client) { |hostname| yield merge hostname: hostname }
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def initialize(attributes = {}, &block)
|
58
|
-
super Hash(attributes), &block
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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
|
@@ -1,38 +0,0 @@
|
|
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
|
@@ -1,43 +0,0 @@
|
|
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
|
@@ -1,32 +0,0 @@
|
|
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/groups_coercer'
|
18
|
-
require 'terraform/simple_config'
|
19
|
-
|
20
|
-
module Terraform
|
21
|
-
# Behaviour for the [:groups] config option
|
22
|
-
module GroupsConfig
|
23
|
-
include ::Terraform::SimpleConfig
|
24
|
-
|
25
|
-
def self.extended(configurable_class)
|
26
|
-
configurable_class
|
27
|
-
.configure_required attr: :groups,
|
28
|
-
coercer_class: ::Terraform::GroupsCoercer,
|
29
|
-
default_value: []
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,37 +0,0 @@
|
|
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
|
@@ -1,28 +0,0 @@
|
|
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
|
-
# 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
|
-
''
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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/command'
|
18
|
-
|
19
|
-
module Terraform
|
20
|
-
# A command to retrieve extract values of output variables
|
21
|
-
class OutputCommand < ::Terraform::Command
|
22
|
-
end
|
23
|
-
end
|
@@ -1,55 +0,0 @@
|
|
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
|