rspec-terraform 0.1.0.pre.45 → 0.1.0.pre.46
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/actions.rb +209 -0
- data/lib/rspec/terraform/helpers/apply.rb +1 -66
- data/lib/rspec/terraform/helpers/base.rb +5 -39
- data/lib/rspec/terraform/helpers/destroy.rb +1 -64
- data/lib/rspec/terraform/helpers/output.rb +4 -58
- data/lib/rspec/terraform/helpers/parameters.rb +33 -0
- data/lib/rspec/terraform/helpers/plan.rb +1 -85
- data/lib/rspec/terraform/helpers/var.rb +1 -2
- data/lib/rspec/terraform/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2595a9e060198c8472a6a91148d1d0e8c11532efee15fef65d9c732605b17a8d
|
4
|
+
data.tar.gz: e63395a9eb9228904cf3641b27e8f98d383757e1f2caa32a4249db296de99162
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8cf7c02682147df95b9229c8fbf923b0cb1d35fc2b3b104452b560bbc5f0ee796d0fac397bc24ce188d7293ec7bc49bbed9782846d3e381aac20be9d2e89d94
|
7
|
+
data.tar.gz: 531a6420c69096768cb72f8593bea6e8e1d347ebe0182cc58e7a8c9b2ca76cfc67ec89b67c47bf1579712978a5d76a38bc850683cfe192adead3ca1e7d8e9368
|
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.46)
|
5
5
|
confidante (>= 0.27)
|
6
6
|
rspec (>= 3.0)
|
7
7
|
ruby-terraform (= 1.7.0.pre.17)
|
@@ -145,7 +145,7 @@ GEM
|
|
145
145
|
parser (>= 3.1.1.0)
|
146
146
|
rubocop-rake (0.6.0)
|
147
147
|
rubocop (~> 1.0)
|
148
|
-
rubocop-rspec (2.13.
|
148
|
+
rubocop-rspec (2.13.2)
|
149
149
|
rubocop (~> 1.33)
|
150
150
|
ruby-progressbar (1.11.0)
|
151
151
|
ruby-terraform (1.7.0.pre.17)
|
@@ -178,7 +178,7 @@ GEM
|
|
178
178
|
thor (1.2.1)
|
179
179
|
tzinfo (2.0.5)
|
180
180
|
concurrent-ruby (~> 1.0)
|
181
|
-
unicode-display_width (2.
|
181
|
+
unicode-display_width (2.3.0)
|
182
182
|
|
183
183
|
PLATFORMS
|
184
184
|
arm64-darwin-21
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../configuration/var_captor'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Terraform
|
7
|
+
module Helpers
|
8
|
+
# rubocop:disable Metrics/ModuleLength
|
9
|
+
module Actions
|
10
|
+
def execute_if_required(parameters, &block)
|
11
|
+
only_if = parameters[:only_if]
|
12
|
+
only_if_args = only_if ? [parameters].slice(0, only_if.arity) : []
|
13
|
+
should_execute = only_if ? only_if.call(*only_if_args) : true
|
14
|
+
|
15
|
+
block.call if should_execute
|
16
|
+
end
|
17
|
+
|
18
|
+
def clean(parameters)
|
19
|
+
return unless execution_mode == :isolated
|
20
|
+
|
21
|
+
FileUtils.rm_rf(parameters[:configuration_directory])
|
22
|
+
FileUtils.mkdir_p(parameters[:configuration_directory])
|
23
|
+
end
|
24
|
+
|
25
|
+
def remove(parameters, file)
|
26
|
+
FileUtils.rm_f(
|
27
|
+
File.join(parameters[:configuration_directory], file)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate(parameters)
|
32
|
+
missing_parameters =
|
33
|
+
required_parameters(execution_mode)
|
34
|
+
.filter { |parameter| parameters[parameter].nil? }
|
35
|
+
|
36
|
+
return if missing_parameters.empty?
|
37
|
+
|
38
|
+
raise_missing_parameters(missing_parameters)
|
39
|
+
end
|
40
|
+
|
41
|
+
def init(parameters)
|
42
|
+
init_command.execute(init_parameters(parameters))
|
43
|
+
end
|
44
|
+
|
45
|
+
def apply(parameters)
|
46
|
+
apply_command.execute(apply_parameters(parameters))
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy(parameters)
|
50
|
+
destroy_command.execute(destroy_parameters(parameters))
|
51
|
+
end
|
52
|
+
|
53
|
+
def plan(parameters)
|
54
|
+
plan_parameters = plan_parameters(parameters)
|
55
|
+
plan_command.execute(plan_parameters)
|
56
|
+
plan_parameters[:out]
|
57
|
+
end
|
58
|
+
|
59
|
+
def show(parameters, plan_file)
|
60
|
+
stdout = StringIO.new
|
61
|
+
show_command(stdout: stdout)
|
62
|
+
.execute(show_parameters(parameters, plan_file))
|
63
|
+
stdout.string
|
64
|
+
end
|
65
|
+
|
66
|
+
def output(parameters)
|
67
|
+
stdout = StringIO.new
|
68
|
+
output_command(stdout: stdout)
|
69
|
+
.execute(output_parameters(parameters))
|
70
|
+
stdout.string
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
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
|
+
def instantiate_command(klass, opts = {})
|
88
|
+
klass.new(command_options.merge(opts))
|
89
|
+
end
|
90
|
+
|
91
|
+
def init_command
|
92
|
+
instantiate_command(RubyTerraform::Commands::Init)
|
93
|
+
end
|
94
|
+
|
95
|
+
def apply_command
|
96
|
+
instantiate_command(RubyTerraform::Commands::Apply)
|
97
|
+
end
|
98
|
+
|
99
|
+
def destroy_command
|
100
|
+
instantiate_command(RubyTerraform::Commands::Destroy)
|
101
|
+
end
|
102
|
+
|
103
|
+
def plan_command
|
104
|
+
instantiate_command(RubyTerraform::Commands::Plan)
|
105
|
+
end
|
106
|
+
|
107
|
+
def show_command(opts = {})
|
108
|
+
instantiate_command(RubyTerraform::Commands::Show, opts)
|
109
|
+
end
|
110
|
+
|
111
|
+
def output_command(opts = {})
|
112
|
+
instantiate_command(RubyTerraform::Commands::Output, opts)
|
113
|
+
end
|
114
|
+
|
115
|
+
def init_parameters(parameters)
|
116
|
+
init_parameters = parameters.merge(
|
117
|
+
chdir: parameters[:configuration_directory],
|
118
|
+
input: false
|
119
|
+
)
|
120
|
+
if execution_mode == :isolated
|
121
|
+
init_parameters =
|
122
|
+
init_parameters.merge(from_module: parameters[:source_directory])
|
123
|
+
end
|
124
|
+
|
125
|
+
init_parameters
|
126
|
+
end
|
127
|
+
|
128
|
+
# rubocop:disable Metrics/MethodLength
|
129
|
+
def apply_parameters(parameters)
|
130
|
+
apply_parameters =
|
131
|
+
parameters.merge(
|
132
|
+
chdir: parameters[:configuration_directory],
|
133
|
+
input: false,
|
134
|
+
auto_approve: true
|
135
|
+
)
|
136
|
+
|
137
|
+
if parameters[:state_file]
|
138
|
+
apply_parameters =
|
139
|
+
apply_parameters.merge(state: parameters[:state_file])
|
140
|
+
end
|
141
|
+
|
142
|
+
apply_parameters
|
143
|
+
end
|
144
|
+
# rubocop:enable Metrics/MethodLength
|
145
|
+
|
146
|
+
# rubocop:disable Metrics/MethodLength
|
147
|
+
def destroy_parameters(parameters)
|
148
|
+
destroy_parameters =
|
149
|
+
parameters.merge(
|
150
|
+
chdir: parameters[:configuration_directory],
|
151
|
+
input: false,
|
152
|
+
auto_approve: true
|
153
|
+
)
|
154
|
+
|
155
|
+
if parameters[:state_file]
|
156
|
+
destroy_parameters =
|
157
|
+
destroy_parameters.merge(state: parameters[:state_file])
|
158
|
+
end
|
159
|
+
|
160
|
+
destroy_parameters
|
161
|
+
end
|
162
|
+
# rubocop:enable Metrics/MethodLength
|
163
|
+
|
164
|
+
# rubocop:disable Metrics/MethodLength
|
165
|
+
def plan_parameters(parameters)
|
166
|
+
plan_parameters =
|
167
|
+
parameters.merge(
|
168
|
+
chdir: parameters[:configuration_directory],
|
169
|
+
out: parameters[:plan_file_name] ||
|
170
|
+
"#{SecureRandom.hex[0, 10]}.tfplan",
|
171
|
+
input: false
|
172
|
+
)
|
173
|
+
|
174
|
+
if parameters[:state_file]
|
175
|
+
plan_parameters =
|
176
|
+
plan_parameters.merge(state: parameters[:state_file])
|
177
|
+
end
|
178
|
+
|
179
|
+
plan_parameters
|
180
|
+
end
|
181
|
+
# rubocop:enable Metrics/MethodLength
|
182
|
+
|
183
|
+
def show_parameters(parameters, plan_file)
|
184
|
+
parameters.merge(
|
185
|
+
chdir: parameters[:configuration_directory],
|
186
|
+
path: plan_file,
|
187
|
+
no_color: true,
|
188
|
+
json: true
|
189
|
+
)
|
190
|
+
end
|
191
|
+
|
192
|
+
def output_parameters(parameters)
|
193
|
+
output_parameters =
|
194
|
+
parameters.merge(
|
195
|
+
chdir: parameters[:configuration_directory]
|
196
|
+
)
|
197
|
+
|
198
|
+
if parameters[:state_file]
|
199
|
+
output_parameters =
|
200
|
+
output_parameters.merge(state: parameters[:state_file])
|
201
|
+
end
|
202
|
+
|
203
|
+
output_parameters
|
204
|
+
end
|
205
|
+
end
|
206
|
+
# rubocop:enable Metrics/ModuleLength
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -3,16 +3,13 @@
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
5
|
require_relative './base'
|
6
|
-
require_relative '../configuration/var_captor'
|
7
6
|
|
8
7
|
module RSpec
|
9
8
|
module Terraform
|
10
9
|
module Helpers
|
11
10
|
class Apply < Base
|
12
11
|
def execute(overrides = {}, &block)
|
13
|
-
parameters =
|
14
|
-
parameters = with_resolved_vars(parameters, &block)
|
15
|
-
parameters = with_mandatory_parameters(parameters)
|
12
|
+
parameters = resolve_parameters(overrides, &block)
|
16
13
|
|
17
14
|
execute_if_required(parameters) do
|
18
15
|
validate(parameters)
|
@@ -24,14 +21,6 @@ module RSpec
|
|
24
21
|
|
25
22
|
private
|
26
23
|
|
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
|
31
|
-
|
32
|
-
block.call if should_execute
|
33
|
-
end
|
34
|
-
|
35
24
|
def mandatory_parameters
|
36
25
|
{
|
37
26
|
input: false,
|
@@ -45,60 +34,6 @@ module RSpec
|
|
45
34
|
isolated: %i[source_directory configuration_directory]
|
46
35
|
}[execution_mode] || []
|
47
36
|
end
|
48
|
-
|
49
|
-
def clean(parameters)
|
50
|
-
return unless execution_mode == :isolated
|
51
|
-
|
52
|
-
FileUtils.rm_rf(parameters[:configuration_directory])
|
53
|
-
FileUtils.mkdir_p(parameters[:configuration_directory])
|
54
|
-
end
|
55
|
-
|
56
|
-
def init(parameters)
|
57
|
-
init_command.execute(init_parameters(parameters))
|
58
|
-
end
|
59
|
-
|
60
|
-
def apply(parameters)
|
61
|
-
apply_command.execute(apply_parameters(parameters))
|
62
|
-
end
|
63
|
-
|
64
|
-
def init_command
|
65
|
-
RubyTerraform::Commands::Init.new(command_options)
|
66
|
-
end
|
67
|
-
|
68
|
-
def apply_command
|
69
|
-
RubyTerraform::Commands::Apply.new(command_options)
|
70
|
-
end
|
71
|
-
|
72
|
-
def init_parameters(parameters)
|
73
|
-
init_parameters = parameters.merge(
|
74
|
-
chdir: parameters[:configuration_directory],
|
75
|
-
input: false
|
76
|
-
)
|
77
|
-
if execution_mode == :isolated
|
78
|
-
init_parameters =
|
79
|
-
init_parameters.merge(from_module: parameters[:source_directory])
|
80
|
-
end
|
81
|
-
|
82
|
-
init_parameters
|
83
|
-
end
|
84
|
-
|
85
|
-
# rubocop:disable Metrics/MethodLength
|
86
|
-
def apply_parameters(parameters)
|
87
|
-
apply_parameters =
|
88
|
-
parameters.merge(
|
89
|
-
chdir: parameters[:configuration_directory],
|
90
|
-
input: false,
|
91
|
-
auto_approve: true
|
92
|
-
)
|
93
|
-
|
94
|
-
if parameters[:state_file]
|
95
|
-
apply_parameters =
|
96
|
-
apply_parameters.merge(state: parameters[:state_file])
|
97
|
-
end
|
98
|
-
|
99
|
-
apply_parameters
|
100
|
-
end
|
101
|
-
# rubocop:enable Metrics/MethodLength
|
102
37
|
end
|
103
38
|
end
|
104
39
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative './actions'
|
4
|
+
require_relative './parameters'
|
4
5
|
|
5
6
|
module RSpec
|
6
7
|
module Terraform
|
7
8
|
module Helpers
|
8
9
|
class Base
|
10
|
+
include Parameters
|
11
|
+
include Actions
|
12
|
+
|
9
13
|
attr_reader(
|
10
14
|
:configuration_provider,
|
11
15
|
:binary,
|
@@ -29,44 +33,6 @@ module RSpec
|
|
29
33
|
|
30
34
|
private
|
31
35
|
|
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
36
|
def mandatory_parameters
|
71
37
|
{}
|
72
38
|
end
|
@@ -9,8 +9,7 @@ module RSpec
|
|
9
9
|
module Helpers
|
10
10
|
class Destroy < Base
|
11
11
|
def execute(overrides = {}, &block)
|
12
|
-
parameters =
|
13
|
-
parameters = with_resolved_vars(parameters, &block)
|
12
|
+
parameters = resolve_parameters(overrides, &block)
|
14
13
|
|
15
14
|
execute_if_required(parameters) do
|
16
15
|
validate(parameters)
|
@@ -22,74 +21,12 @@ module RSpec
|
|
22
21
|
|
23
22
|
private
|
24
23
|
|
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
|
29
|
-
|
30
|
-
block.call if should_execute
|
31
|
-
end
|
32
|
-
|
33
24
|
def required_parameters(execution_mode)
|
34
25
|
{
|
35
26
|
in_place: [:configuration_directory],
|
36
27
|
isolated: %i[source_directory configuration_directory]
|
37
28
|
}[execution_mode] || []
|
38
29
|
end
|
39
|
-
|
40
|
-
def clean(parameters)
|
41
|
-
return unless execution_mode == :isolated
|
42
|
-
|
43
|
-
FileUtils.rm_rf(parameters[:configuration_directory])
|
44
|
-
FileUtils.mkdir_p(parameters[:configuration_directory])
|
45
|
-
end
|
46
|
-
|
47
|
-
def init(parameters)
|
48
|
-
init_command.execute(init_parameters(parameters))
|
49
|
-
end
|
50
|
-
|
51
|
-
def destroy(parameters)
|
52
|
-
destroy_command.execute(destroy_parameters(parameters))
|
53
|
-
end
|
54
|
-
|
55
|
-
def init_command
|
56
|
-
RubyTerraform::Commands::Init.new(command_options)
|
57
|
-
end
|
58
|
-
|
59
|
-
def destroy_command
|
60
|
-
RubyTerraform::Commands::Destroy.new(command_options)
|
61
|
-
end
|
62
|
-
|
63
|
-
def init_parameters(parameters)
|
64
|
-
init_parameters = parameters.merge(
|
65
|
-
chdir: parameters[:configuration_directory],
|
66
|
-
input: false
|
67
|
-
)
|
68
|
-
if execution_mode == :isolated
|
69
|
-
init_parameters =
|
70
|
-
init_parameters.merge(from_module: parameters[:source_directory])
|
71
|
-
end
|
72
|
-
|
73
|
-
init_parameters
|
74
|
-
end
|
75
|
-
|
76
|
-
# rubocop:disable Metrics/MethodLength
|
77
|
-
def destroy_parameters(parameters)
|
78
|
-
destroy_parameters =
|
79
|
-
parameters.merge(
|
80
|
-
chdir: parameters[:configuration_directory],
|
81
|
-
input: false,
|
82
|
-
auto_approve: true
|
83
|
-
)
|
84
|
-
|
85
|
-
if parameters[:state_file]
|
86
|
-
destroy_parameters =
|
87
|
-
destroy_parameters.merge(state: parameters[:state_file])
|
88
|
-
end
|
89
|
-
|
90
|
-
destroy_parameters
|
91
|
-
end
|
92
|
-
# rubocop:enable Metrics/MethodLength
|
93
30
|
end
|
94
31
|
end
|
95
32
|
end
|
@@ -9,23 +9,18 @@ module RSpec
|
|
9
9
|
module Helpers
|
10
10
|
class Output < Base
|
11
11
|
def execute(overrides = {})
|
12
|
-
parameters =
|
13
|
-
parameters = with_mandatory_parameters(parameters)
|
12
|
+
parameters = resolve_parameters(overrides)
|
14
13
|
|
15
14
|
validate(parameters)
|
16
15
|
clean(parameters)
|
17
16
|
init(parameters)
|
18
17
|
output_value = output(parameters)
|
19
18
|
|
20
|
-
|
19
|
+
parse(output_value)
|
21
20
|
end
|
22
21
|
|
23
22
|
private
|
24
23
|
|
25
|
-
def with_mandatory_parameters(parameters)
|
26
|
-
parameters.merge(mandatory_parameters)
|
27
|
-
end
|
28
|
-
|
29
24
|
def mandatory_parameters
|
30
25
|
{
|
31
26
|
json: true
|
@@ -39,57 +34,8 @@ module RSpec
|
|
39
34
|
}[execution_mode] || []
|
40
35
|
end
|
41
36
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
FileUtils.rm_rf(parameters[:configuration_directory])
|
46
|
-
FileUtils.mkdir_p(parameters[:configuration_directory])
|
47
|
-
end
|
48
|
-
|
49
|
-
def init(parameters)
|
50
|
-
init_command.execute(init_parameters(parameters))
|
51
|
-
end
|
52
|
-
|
53
|
-
def output(parameters)
|
54
|
-
stdout = StringIO.new
|
55
|
-
output_command(stdout: stdout)
|
56
|
-
.execute(output_parameters(parameters))
|
57
|
-
stdout.string
|
58
|
-
end
|
59
|
-
|
60
|
-
def init_command
|
61
|
-
RubyTerraform::Commands::Init.new(command_options)
|
62
|
-
end
|
63
|
-
|
64
|
-
def output_command(opts = {})
|
65
|
-
RubyTerraform::Commands::Output.new(command_options.merge(opts))
|
66
|
-
end
|
67
|
-
|
68
|
-
def init_parameters(parameters)
|
69
|
-
init_parameters = parameters.merge(
|
70
|
-
chdir: parameters[:configuration_directory],
|
71
|
-
input: false
|
72
|
-
)
|
73
|
-
if execution_mode == :isolated
|
74
|
-
init_parameters =
|
75
|
-
init_parameters.merge(from_module: parameters[:source_directory])
|
76
|
-
end
|
77
|
-
|
78
|
-
init_parameters
|
79
|
-
end
|
80
|
-
|
81
|
-
def output_parameters(parameters)
|
82
|
-
output_parameters =
|
83
|
-
parameters.merge(
|
84
|
-
chdir: parameters[:configuration_directory]
|
85
|
-
)
|
86
|
-
|
87
|
-
if parameters[:state_file]
|
88
|
-
output_parameters =
|
89
|
-
output_parameters.merge(state: parameters[:state_file])
|
90
|
-
end
|
91
|
-
|
92
|
-
output_parameters
|
37
|
+
def parse(output_value)
|
38
|
+
JSON.parse(output_value, symbolize_names: true)
|
93
39
|
end
|
94
40
|
end
|
95
41
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../configuration/var_captor'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Terraform
|
7
|
+
module Helpers
|
8
|
+
module Parameters
|
9
|
+
def resolve_parameters(overrides, &block)
|
10
|
+
parameters = with_configuration_provider_parameters(overrides)
|
11
|
+
parameters = with_resolved_vars(parameters, &block)
|
12
|
+
with_mandatory_parameters(parameters)
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_configuration_provider_parameters(parameters)
|
16
|
+
configuration_provider.resolve(parameters)
|
17
|
+
end
|
18
|
+
|
19
|
+
def with_resolved_vars(parameters, &block)
|
20
|
+
return parameters unless block_given?
|
21
|
+
|
22
|
+
var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
|
23
|
+
block.call(var_captor)
|
24
|
+
parameters.merge(vars: var_captor.to_h)
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_mandatory_parameters(parameters)
|
28
|
+
parameters.merge(mandatory_parameters)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -11,8 +11,7 @@ module RSpec
|
|
11
11
|
module Helpers
|
12
12
|
class Plan < Base
|
13
13
|
def execute(overrides = {}, &block)
|
14
|
-
parameters =
|
15
|
-
parameters = with_resolved_vars(parameters, &block)
|
14
|
+
parameters = resolve_parameters(overrides, &block)
|
16
15
|
|
17
16
|
validate(parameters)
|
18
17
|
clean(parameters)
|
@@ -32,94 +31,11 @@ module RSpec
|
|
32
31
|
}[execution_mode] || []
|
33
32
|
end
|
34
33
|
|
35
|
-
def clean(parameters)
|
36
|
-
return unless execution_mode == :isolated
|
37
|
-
|
38
|
-
FileUtils.rm_rf(parameters[:configuration_directory])
|
39
|
-
FileUtils.mkdir_p(parameters[:configuration_directory])
|
40
|
-
end
|
41
|
-
|
42
|
-
def init(parameters)
|
43
|
-
init_command.execute(init_parameters(parameters))
|
44
|
-
end
|
45
|
-
|
46
|
-
def plan(parameters)
|
47
|
-
plan_parameters = plan_parameters(parameters)
|
48
|
-
plan_command.execute(plan_parameters)
|
49
|
-
plan_parameters[:out]
|
50
|
-
end
|
51
|
-
|
52
|
-
def show(parameters, plan_file)
|
53
|
-
stdout = StringIO.new
|
54
|
-
show_command(stdout: stdout)
|
55
|
-
.execute(show_parameters(parameters, plan_file))
|
56
|
-
stdout.string
|
57
|
-
end
|
58
|
-
|
59
34
|
def parse(plan_contents)
|
60
35
|
RubyTerraform::Models::Plan.new(
|
61
36
|
JSON.parse(plan_contents, symbolize_names: true)
|
62
37
|
)
|
63
38
|
end
|
64
|
-
|
65
|
-
def remove(parameters, plan_file)
|
66
|
-
FileUtils.rm_f(
|
67
|
-
File.join(parameters[:configuration_directory], plan_file)
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
def init_command
|
72
|
-
RubyTerraform::Commands::Init.new(command_options)
|
73
|
-
end
|
74
|
-
|
75
|
-
def plan_command
|
76
|
-
RubyTerraform::Commands::Plan.new(command_options)
|
77
|
-
end
|
78
|
-
|
79
|
-
def show_command(opts = {})
|
80
|
-
RubyTerraform::Commands::Show.new(command_options.merge(opts))
|
81
|
-
end
|
82
|
-
|
83
|
-
def init_parameters(parameters)
|
84
|
-
init_parameters = parameters.merge(
|
85
|
-
chdir: parameters[:configuration_directory],
|
86
|
-
input: false
|
87
|
-
)
|
88
|
-
if execution_mode == :isolated
|
89
|
-
init_parameters =
|
90
|
-
init_parameters.merge(from_module: parameters[:source_directory])
|
91
|
-
end
|
92
|
-
|
93
|
-
init_parameters
|
94
|
-
end
|
95
|
-
|
96
|
-
# rubocop:disable Metrics/MethodLength
|
97
|
-
def plan_parameters(parameters)
|
98
|
-
plan_parameters =
|
99
|
-
parameters.merge(
|
100
|
-
chdir: parameters[:configuration_directory],
|
101
|
-
out: parameters[:plan_file_name] ||
|
102
|
-
"#{SecureRandom.hex[0, 10]}.tfplan",
|
103
|
-
input: false
|
104
|
-
)
|
105
|
-
|
106
|
-
if parameters[:state_file]
|
107
|
-
plan_parameters =
|
108
|
-
plan_parameters.merge(state: parameters[:state_file])
|
109
|
-
end
|
110
|
-
|
111
|
-
plan_parameters
|
112
|
-
end
|
113
|
-
# rubocop:enable Metrics/MethodLength
|
114
|
-
|
115
|
-
def show_parameters(parameters, plan_file)
|
116
|
-
parameters.merge(
|
117
|
-
chdir: parameters[:configuration_directory],
|
118
|
-
path: plan_file,
|
119
|
-
no_color: true,
|
120
|
-
json: true
|
121
|
-
)
|
122
|
-
end
|
123
39
|
end
|
124
40
|
end
|
125
41
|
end
|
@@ -8,8 +8,7 @@ module RSpec
|
|
8
8
|
module Helpers
|
9
9
|
class Var < Base
|
10
10
|
def execute(overrides = {}, &block)
|
11
|
-
parameters =
|
12
|
-
parameters = with_resolved_vars(parameters, &block)
|
11
|
+
parameters = resolve_parameters(overrides, &block)
|
13
12
|
|
14
13
|
parameters[:vars][parameters[:name].to_sym]
|
15
14
|
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.46
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: confidante
|
@@ -304,10 +304,12 @@ files:
|
|
304
304
|
- lib/rspec/terraform/configuration/providers/seed.rb
|
305
305
|
- lib/rspec/terraform/configuration/var_captor.rb
|
306
306
|
- lib/rspec/terraform/helpers.rb
|
307
|
+
- lib/rspec/terraform/helpers/actions.rb
|
307
308
|
- lib/rspec/terraform/helpers/apply.rb
|
308
309
|
- lib/rspec/terraform/helpers/base.rb
|
309
310
|
- lib/rspec/terraform/helpers/destroy.rb
|
310
311
|
- lib/rspec/terraform/helpers/output.rb
|
312
|
+
- lib/rspec/terraform/helpers/parameters.rb
|
311
313
|
- lib/rspec/terraform/helpers/plan.rb
|
312
314
|
- lib/rspec/terraform/helpers/var.rb
|
313
315
|
- lib/rspec/terraform/logging.rb
|