rspec-terraform 0.1.0.pre.43 → 0.1.0.pre.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/rspec/terraform/helpers/apply.rb +16 -73
- data/lib/rspec/terraform/helpers/base.rb +90 -0
- data/lib/rspec/terraform/helpers/destroy.rb +13 -71
- data/lib/rspec/terraform/helpers/output.rb +9 -63
- data/lib/rspec/terraform/helpers/plan.rb +3 -71
- data/lib/rspec/terraform/helpers/var.rb +2 -22
- data/lib/rspec/terraform/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5e1e41e777f174198e1de6459ef21f280d11227fd2a0b97e0d6604458b48e34
|
4
|
+
data.tar.gz: 071164c5440ab7b9a094c0125c7d562acb40d235485baac554dfd6e14bbc55fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8f45a75288ba61061d435320509688ac960e4be4b1842b62d4a4c87cc6e5a75af656f6b6fad60b39fbe24f12060cc8d9d1bec4038616efb2d7dea02649caba9
|
7
|
+
data.tar.gz: d2e42b5ca9bbfbcb59842e656e9d2816fb838c8bed600aaeaeb008f6601dd64755fa8ac33c27b79cc38c84efc2c8f99b612b25498c98f0292c0fb115433e9e4d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-terraform (0.1.0.pre.
|
4
|
+
rspec-terraform (0.1.0.pre.45)
|
5
5
|
confidante (>= 0.27)
|
6
6
|
rspec (>= 3.0)
|
7
7
|
ruby-terraform (= 1.7.0.pre.17)
|
@@ -145,8 +145,8 @@ GEM
|
|
145
145
|
parser (>= 3.1.1.0)
|
146
146
|
rubocop-rake (0.6.0)
|
147
147
|
rubocop (~> 1.0)
|
148
|
-
rubocop-rspec (2.
|
149
|
-
rubocop (~> 1.
|
148
|
+
rubocop-rspec (2.13.1)
|
149
|
+
rubocop (~> 1.33)
|
150
150
|
ruby-progressbar (1.11.0)
|
151
151
|
ruby-terraform (1.7.0.pre.17)
|
152
152
|
immutable-struct (~> 2.4)
|
@@ -2,65 +2,41 @@
|
|
2
2
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
|
+
require_relative './base'
|
5
6
|
require_relative '../configuration/var_captor'
|
6
7
|
|
7
8
|
module RSpec
|
8
9
|
module Terraform
|
9
10
|
module Helpers
|
10
|
-
|
11
|
-
class Apply
|
12
|
-
attr_reader(
|
13
|
-
:configuration_provider,
|
14
|
-
:binary,
|
15
|
-
:logger,
|
16
|
-
:stdin,
|
17
|
-
:stdout,
|
18
|
-
:stderr,
|
19
|
-
:execution_mode
|
20
|
-
)
|
21
|
-
|
22
|
-
def initialize(opts = {})
|
23
|
-
@configuration_provider =
|
24
|
-
opts[:configuration_provider] || Configuration.identity_provider
|
25
|
-
@binary = opts[:binary] || 'terraform'
|
26
|
-
@logger = opts[:logger]
|
27
|
-
@stdin = opts[:stdin]
|
28
|
-
@stdout = opts[:stdout]
|
29
|
-
@stderr = opts[:stderr]
|
30
|
-
@execution_mode = opts[:execution_mode] || :in_place
|
31
|
-
end
|
32
|
-
|
11
|
+
class Apply < Base
|
33
12
|
def execute(overrides = {}, &block)
|
34
13
|
parameters = with_configuration_provider_parameters(overrides)
|
35
14
|
parameters = with_resolved_vars(parameters, &block)
|
36
15
|
parameters = with_mandatory_parameters(parameters)
|
37
16
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
17
|
+
execute_if_required(parameters) do
|
18
|
+
validate(parameters)
|
19
|
+
clean(parameters)
|
20
|
+
init(parameters)
|
21
|
+
apply(parameters)
|
22
|
+
end
|
43
23
|
end
|
44
24
|
|
45
25
|
private
|
46
26
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
def with_resolved_vars(parameters, &block)
|
52
|
-
return parameters unless block_given?
|
27
|
+
def execute_if_required(parameters, &block)
|
28
|
+
only_if = parameters[:only_if]
|
29
|
+
only_if_args = only_if ? [parameters].slice(0, only_if.arity) : []
|
30
|
+
should_execute = only_if ? only_if.call(*only_if_args) : true
|
53
31
|
|
54
|
-
|
55
|
-
block.call(var_captor)
|
56
|
-
parameters.merge(vars: var_captor.to_h)
|
32
|
+
block.call if should_execute
|
57
33
|
end
|
58
34
|
|
59
|
-
def
|
60
|
-
|
35
|
+
def mandatory_parameters
|
36
|
+
{
|
61
37
|
input: false,
|
62
38
|
auto_approve: true
|
63
|
-
|
39
|
+
}
|
64
40
|
end
|
65
41
|
|
66
42
|
def required_parameters(execution_mode)
|
@@ -70,28 +46,6 @@ module RSpec
|
|
70
46
|
}[execution_mode] || []
|
71
47
|
end
|
72
48
|
|
73
|
-
def ensure_required_parameters(parameters)
|
74
|
-
missing_parameters =
|
75
|
-
required_parameters(execution_mode)
|
76
|
-
.filter { |parameter| parameters[parameter].nil? }
|
77
|
-
|
78
|
-
return if missing_parameters.empty?
|
79
|
-
|
80
|
-
raise_missing_parameters(missing_parameters)
|
81
|
-
end
|
82
|
-
|
83
|
-
def raise_missing_parameters(parameters)
|
84
|
-
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
85
|
-
if parameters.count == 1
|
86
|
-
raise StandardError,
|
87
|
-
"Required parameter: #{parameters[0]} missing."
|
88
|
-
else
|
89
|
-
parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
|
90
|
-
raise StandardError,
|
91
|
-
"Required parameters: #{parameters} missing."
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
49
|
def clean(parameters)
|
96
50
|
return unless execution_mode == :isolated
|
97
51
|
|
@@ -145,18 +99,7 @@ module RSpec
|
|
145
99
|
apply_parameters
|
146
100
|
end
|
147
101
|
# rubocop:enable Metrics/MethodLength
|
148
|
-
|
149
|
-
def command_options
|
150
|
-
{
|
151
|
-
binary: binary,
|
152
|
-
logger: logger,
|
153
|
-
stdin: stdin,
|
154
|
-
stdout: stdout,
|
155
|
-
stderr: stderr
|
156
|
-
}
|
157
|
-
end
|
158
102
|
end
|
159
|
-
# rubocop:enable Metrics/ClassLength
|
160
103
|
end
|
161
104
|
end
|
162
105
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../configuration/var_captor'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Terraform
|
7
|
+
module Helpers
|
8
|
+
class Base
|
9
|
+
attr_reader(
|
10
|
+
:configuration_provider,
|
11
|
+
:binary,
|
12
|
+
:logger,
|
13
|
+
:stdin,
|
14
|
+
:stdout,
|
15
|
+
:stderr,
|
16
|
+
:execution_mode
|
17
|
+
)
|
18
|
+
|
19
|
+
def initialize(opts = {})
|
20
|
+
@configuration_provider =
|
21
|
+
opts[:configuration_provider] || Configuration.identity_provider
|
22
|
+
@binary = opts[:binary] || 'terraform'
|
23
|
+
@logger = opts[:logger]
|
24
|
+
@stdin = opts[:stdin]
|
25
|
+
@stdout = opts[:stdout]
|
26
|
+
@stderr = opts[:stderr]
|
27
|
+
@execution_mode = opts[:execution_mode] || :in_place
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def with_configuration_provider_parameters(parameters)
|
33
|
+
configuration_provider.resolve(parameters)
|
34
|
+
end
|
35
|
+
|
36
|
+
def with_resolved_vars(parameters, &block)
|
37
|
+
return parameters unless block_given?
|
38
|
+
|
39
|
+
var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
|
40
|
+
block.call(var_captor)
|
41
|
+
parameters.merge(vars: var_captor.to_h)
|
42
|
+
end
|
43
|
+
|
44
|
+
def with_mandatory_parameters(parameters)
|
45
|
+
parameters.merge(mandatory_parameters)
|
46
|
+
end
|
47
|
+
|
48
|
+
def raise_missing_parameters(parameters)
|
49
|
+
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
50
|
+
if parameters.count == 1
|
51
|
+
raise StandardError,
|
52
|
+
"Required parameter: #{parameters[0]} missing."
|
53
|
+
else
|
54
|
+
parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
|
55
|
+
raise StandardError,
|
56
|
+
"Required parameters: #{parameters} missing."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate(parameters)
|
61
|
+
missing_parameters =
|
62
|
+
required_parameters(execution_mode)
|
63
|
+
.filter { |parameter| parameters[parameter].nil? }
|
64
|
+
|
65
|
+
return if missing_parameters.empty?
|
66
|
+
|
67
|
+
raise_missing_parameters(missing_parameters)
|
68
|
+
end
|
69
|
+
|
70
|
+
def mandatory_parameters
|
71
|
+
{}
|
72
|
+
end
|
73
|
+
|
74
|
+
def required_parameters(_)
|
75
|
+
[]
|
76
|
+
end
|
77
|
+
|
78
|
+
def command_options
|
79
|
+
{
|
80
|
+
binary: binary,
|
81
|
+
logger: logger,
|
82
|
+
stdin: stdin,
|
83
|
+
stdout: stdout,
|
84
|
+
stderr: stderr
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -2,57 +2,32 @@
|
|
2
2
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
|
-
require_relative '
|
5
|
+
require_relative './base'
|
6
6
|
|
7
7
|
module RSpec
|
8
8
|
module Terraform
|
9
9
|
module Helpers
|
10
|
-
|
11
|
-
class Destroy
|
12
|
-
attr_reader(
|
13
|
-
:configuration_provider,
|
14
|
-
:binary,
|
15
|
-
:logger,
|
16
|
-
:stdin,
|
17
|
-
:stdout,
|
18
|
-
:stderr,
|
19
|
-
:execution_mode
|
20
|
-
)
|
21
|
-
|
22
|
-
def initialize(opts = {})
|
23
|
-
@configuration_provider =
|
24
|
-
opts[:configuration_provider] || Configuration.identity_provider
|
25
|
-
@binary = opts[:binary] || 'terraform'
|
26
|
-
@logger = opts[:logger]
|
27
|
-
@stdin = opts[:stdin]
|
28
|
-
@stdout = opts[:stdout]
|
29
|
-
@stderr = opts[:stderr]
|
30
|
-
@execution_mode = opts[:execution_mode] || :in_place
|
31
|
-
end
|
32
|
-
|
10
|
+
class Destroy < Base
|
33
11
|
def execute(overrides = {}, &block)
|
34
12
|
parameters = with_configuration_provider_parameters(overrides)
|
35
13
|
parameters = with_resolved_vars(parameters, &block)
|
36
14
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
15
|
+
execute_if_required(parameters) do
|
16
|
+
validate(parameters)
|
17
|
+
clean(parameters)
|
18
|
+
init(parameters)
|
19
|
+
destroy(parameters)
|
20
|
+
end
|
42
21
|
end
|
43
22
|
|
44
23
|
private
|
45
24
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def with_resolved_vars(parameters, &block)
|
51
|
-
return parameters unless block_given?
|
25
|
+
def execute_if_required(parameters, &block)
|
26
|
+
only_if = parameters[:only_if]
|
27
|
+
only_if_args = only_if ? [parameters].slice(0, only_if.arity) : []
|
28
|
+
should_execute = only_if ? only_if.call(*only_if_args) : true
|
52
29
|
|
53
|
-
|
54
|
-
block.call(var_captor)
|
55
|
-
parameters.merge(vars: var_captor.to_h)
|
30
|
+
block.call if should_execute
|
56
31
|
end
|
57
32
|
|
58
33
|
def required_parameters(execution_mode)
|
@@ -62,28 +37,6 @@ module RSpec
|
|
62
37
|
}[execution_mode] || []
|
63
38
|
end
|
64
39
|
|
65
|
-
def ensure_required_parameters(parameters)
|
66
|
-
missing_parameters =
|
67
|
-
required_parameters(execution_mode)
|
68
|
-
.filter { |parameter| parameters[parameter].nil? }
|
69
|
-
|
70
|
-
return if missing_parameters.empty?
|
71
|
-
|
72
|
-
raise_missing_parameters(missing_parameters)
|
73
|
-
end
|
74
|
-
|
75
|
-
def raise_missing_parameters(parameters)
|
76
|
-
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
77
|
-
if parameters.count == 1
|
78
|
-
raise StandardError,
|
79
|
-
"Required parameter: #{parameters[0]} missing."
|
80
|
-
else
|
81
|
-
parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
|
82
|
-
raise StandardError,
|
83
|
-
"Required parameters: #{parameters} missing."
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
40
|
def clean(parameters)
|
88
41
|
return unless execution_mode == :isolated
|
89
42
|
|
@@ -137,18 +90,7 @@ module RSpec
|
|
137
90
|
destroy_parameters
|
138
91
|
end
|
139
92
|
# rubocop:enable Metrics/MethodLength
|
140
|
-
|
141
|
-
def command_options
|
142
|
-
{
|
143
|
-
binary: binary,
|
144
|
-
logger: logger,
|
145
|
-
stdin: stdin,
|
146
|
-
stdout: stdout,
|
147
|
-
stderr: stderr
|
148
|
-
}
|
149
|
-
end
|
150
93
|
end
|
151
|
-
# rubocop:enable Metrics/ClassLength
|
152
94
|
end
|
153
95
|
end
|
154
96
|
end
|
@@ -2,38 +2,17 @@
|
|
2
2
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
|
+
require_relative './base'
|
6
|
+
|
5
7
|
module RSpec
|
6
8
|
module Terraform
|
7
9
|
module Helpers
|
8
|
-
|
9
|
-
class Output
|
10
|
-
attr_reader(
|
11
|
-
:configuration_provider,
|
12
|
-
:binary,
|
13
|
-
:logger,
|
14
|
-
:stdin,
|
15
|
-
:stdout,
|
16
|
-
:stderr,
|
17
|
-
:execution_mode
|
18
|
-
)
|
19
|
-
|
20
|
-
def initialize(opts = {})
|
21
|
-
@configuration_provider =
|
22
|
-
opts[:configuration_provider] || Configuration.identity_provider
|
23
|
-
@binary = opts[:binary] || 'terraform'
|
24
|
-
@logger = opts[:logger]
|
25
|
-
@stdin = opts[:stdin]
|
26
|
-
@stdout = opts[:stdout]
|
27
|
-
@stderr = opts[:stderr]
|
28
|
-
@execution_mode = opts[:execution_mode] || :in_place
|
29
|
-
end
|
30
|
-
|
10
|
+
class Output < Base
|
31
11
|
def execute(overrides = {})
|
32
12
|
parameters = with_configuration_provider_parameters(overrides)
|
33
13
|
parameters = with_mandatory_parameters(parameters)
|
34
14
|
|
35
|
-
|
36
|
-
|
15
|
+
validate(parameters)
|
37
16
|
clean(parameters)
|
38
17
|
init(parameters)
|
39
18
|
output_value = output(parameters)
|
@@ -43,14 +22,14 @@ module RSpec
|
|
43
22
|
|
44
23
|
private
|
45
24
|
|
46
|
-
def
|
47
|
-
|
25
|
+
def with_mandatory_parameters(parameters)
|
26
|
+
parameters.merge(mandatory_parameters)
|
48
27
|
end
|
49
28
|
|
50
|
-
def
|
51
|
-
|
29
|
+
def mandatory_parameters
|
30
|
+
{
|
52
31
|
json: true
|
53
|
-
|
32
|
+
}
|
54
33
|
end
|
55
34
|
|
56
35
|
def required_parameters(execution_mode)
|
@@ -60,28 +39,6 @@ module RSpec
|
|
60
39
|
}[execution_mode] || []
|
61
40
|
end
|
62
41
|
|
63
|
-
def ensure_required_parameters(parameters)
|
64
|
-
missing_parameters =
|
65
|
-
required_parameters(execution_mode)
|
66
|
-
.filter { |parameter| parameters[parameter].nil? }
|
67
|
-
|
68
|
-
return if missing_parameters.empty?
|
69
|
-
|
70
|
-
raise_missing_parameters(missing_parameters)
|
71
|
-
end
|
72
|
-
|
73
|
-
def raise_missing_parameters(parameters)
|
74
|
-
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
75
|
-
if parameters.count == 1
|
76
|
-
raise StandardError,
|
77
|
-
"Required parameter: #{parameters[0]} missing."
|
78
|
-
else
|
79
|
-
parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
|
80
|
-
raise StandardError,
|
81
|
-
"Required parameters: #{parameters} missing."
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
42
|
def clean(parameters)
|
86
43
|
return unless execution_mode == :isolated
|
87
44
|
|
@@ -134,18 +91,7 @@ module RSpec
|
|
134
91
|
|
135
92
|
output_parameters
|
136
93
|
end
|
137
|
-
|
138
|
-
def command_options
|
139
|
-
{
|
140
|
-
binary: binary,
|
141
|
-
logger: logger,
|
142
|
-
stdin: stdin,
|
143
|
-
stdout: stdout,
|
144
|
-
stderr: stderr
|
145
|
-
}
|
146
|
-
end
|
147
94
|
end
|
148
95
|
end
|
149
|
-
# rubocop:enable Metrics/ClassLength
|
150
96
|
end
|
151
97
|
end
|
@@ -4,40 +4,17 @@ require 'ruby_terraform'
|
|
4
4
|
require 'securerandom'
|
5
5
|
require 'stringio'
|
6
6
|
|
7
|
-
require_relative '
|
7
|
+
require_relative './base'
|
8
8
|
|
9
9
|
module RSpec
|
10
10
|
module Terraform
|
11
11
|
module Helpers
|
12
|
-
|
13
|
-
class Plan
|
14
|
-
attr_reader(
|
15
|
-
:configuration_provider,
|
16
|
-
:binary,
|
17
|
-
:logger,
|
18
|
-
:stdin,
|
19
|
-
:stdout,
|
20
|
-
:stderr,
|
21
|
-
:execution_mode
|
22
|
-
)
|
23
|
-
|
24
|
-
def initialize(opts = {})
|
25
|
-
@configuration_provider =
|
26
|
-
opts[:configuration_provider] || Configuration.identity_provider
|
27
|
-
@binary = opts[:binary] || 'terraform'
|
28
|
-
@logger = opts[:logger]
|
29
|
-
@stdin = opts[:stdin]
|
30
|
-
@stdout = opts[:stdout]
|
31
|
-
@stderr = opts[:stderr]
|
32
|
-
@execution_mode = opts[:execution_mode] || :in_place
|
33
|
-
end
|
34
|
-
|
12
|
+
class Plan < Base
|
35
13
|
def execute(overrides = {}, &block)
|
36
14
|
parameters = with_configuration_provider_parameters(overrides)
|
37
15
|
parameters = with_resolved_vars(parameters, &block)
|
38
16
|
|
39
|
-
|
40
|
-
|
17
|
+
validate(parameters)
|
41
18
|
clean(parameters)
|
42
19
|
init(parameters)
|
43
20
|
plan_file = plan(parameters)
|
@@ -48,18 +25,6 @@ module RSpec
|
|
48
25
|
|
49
26
|
private
|
50
27
|
|
51
|
-
def with_configuration_provider_parameters(parameters)
|
52
|
-
configuration_provider.resolve(parameters)
|
53
|
-
end
|
54
|
-
|
55
|
-
def with_resolved_vars(parameters, &block)
|
56
|
-
return parameters unless block_given?
|
57
|
-
|
58
|
-
var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
|
59
|
-
block.call(var_captor)
|
60
|
-
parameters.merge(vars: var_captor.to_h)
|
61
|
-
end
|
62
|
-
|
63
28
|
def required_parameters(execution_mode)
|
64
29
|
{
|
65
30
|
in_place: [:configuration_directory],
|
@@ -67,28 +32,6 @@ module RSpec
|
|
67
32
|
}[execution_mode] || []
|
68
33
|
end
|
69
34
|
|
70
|
-
def ensure_required_parameters(parameters)
|
71
|
-
missing_parameters =
|
72
|
-
required_parameters(execution_mode)
|
73
|
-
.filter { |parameter| parameters[parameter].nil? }
|
74
|
-
|
75
|
-
return if missing_parameters.empty?
|
76
|
-
|
77
|
-
raise_missing_parameters(missing_parameters)
|
78
|
-
end
|
79
|
-
|
80
|
-
def raise_missing_parameters(parameters)
|
81
|
-
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
82
|
-
if parameters.count == 1
|
83
|
-
raise StandardError,
|
84
|
-
"Required parameter: #{parameters[0]} missing."
|
85
|
-
else
|
86
|
-
parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
|
87
|
-
raise StandardError,
|
88
|
-
"Required parameters: #{parameters} missing."
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
35
|
def clean(parameters)
|
93
36
|
return unless execution_mode == :isolated
|
94
37
|
|
@@ -177,18 +120,7 @@ module RSpec
|
|
177
120
|
json: true
|
178
121
|
)
|
179
122
|
end
|
180
|
-
|
181
|
-
def command_options
|
182
|
-
{
|
183
|
-
binary: binary,
|
184
|
-
logger: logger,
|
185
|
-
stdin: stdin,
|
186
|
-
stdout: stdout,
|
187
|
-
stderr: stderr
|
188
|
-
}
|
189
|
-
end
|
190
123
|
end
|
191
|
-
# rubocop:enable Metrics/ClassLength
|
192
124
|
end
|
193
125
|
end
|
194
126
|
end
|
@@ -1,38 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './base'
|
3
4
|
require_relative '../configuration/var_captor'
|
4
5
|
|
5
6
|
module RSpec
|
6
7
|
module Terraform
|
7
8
|
module Helpers
|
8
|
-
class Var
|
9
|
-
attr_reader(:configuration_provider)
|
10
|
-
|
11
|
-
def initialize(opts = {})
|
12
|
-
@configuration_provider =
|
13
|
-
opts[:configuration_provider] || Configuration.identity_provider
|
14
|
-
end
|
15
|
-
|
9
|
+
class Var < Base
|
16
10
|
def execute(overrides = {}, &block)
|
17
11
|
parameters = with_configuration_provider_parameters(overrides)
|
18
12
|
parameters = with_resolved_vars(parameters, &block)
|
19
13
|
|
20
14
|
parameters[:vars][parameters[:name].to_sym]
|
21
15
|
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def with_configuration_provider_parameters(parameters)
|
26
|
-
configuration_provider.resolve(parameters)
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_resolved_vars(parameters, &block)
|
30
|
-
return parameters unless block_given?
|
31
|
-
|
32
|
-
var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
|
33
|
-
block.call(var_captor)
|
34
|
-
parameters.merge(vars: var_captor.to_h)
|
35
|
-
end
|
36
16
|
end
|
37
17
|
end
|
38
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-terraform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- InfraBlocks Maintainers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: confidante
|
@@ -305,6 +305,7 @@ files:
|
|
305
305
|
- lib/rspec/terraform/configuration/var_captor.rb
|
306
306
|
- lib/rspec/terraform/helpers.rb
|
307
307
|
- lib/rspec/terraform/helpers/apply.rb
|
308
|
+
- lib/rspec/terraform/helpers/base.rb
|
308
309
|
- lib/rspec/terraform/helpers/destroy.rb
|
309
310
|
- lib/rspec/terraform/helpers/output.rb
|
310
311
|
- lib/rspec/terraform/helpers/plan.rb
|