rspec-terraform 0.1.0.pre.47 → 0.1.0.pre.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rspec/terraform/helpers/actions/apply.rb +37 -8
- data/lib/rspec/terraform/helpers/actions/clean.rb +21 -2
- data/lib/rspec/terraform/helpers/actions/destroy.rb +37 -8
- data/lib/rspec/terraform/helpers/actions/execute_if_required.rb +26 -3
- data/lib/rspec/terraform/helpers/actions/init.rb +35 -8
- data/lib/rspec/terraform/helpers/actions/output.rb +36 -6
- data/lib/rspec/terraform/helpers/actions/plan.rb +48 -11
- data/lib/rspec/terraform/helpers/actions/remove.rb +20 -1
- data/lib/rspec/terraform/helpers/actions/show.rb +33 -6
- data/lib/rspec/terraform/helpers/actions/validate.rb +37 -5
- data/lib/rspec/terraform/helpers/apply.rb +1 -1
- data/lib/rspec/terraform/helpers/destroy.rb +1 -1
- data/lib/rspec/terraform/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c565d7154d7321b3b6b9452592201b5230bbba63e30a3603e233f9ebd8f5bc9d
|
4
|
+
data.tar.gz: d9a59fe476ba65bd885da0386e3696e9e41daaf71b98d48f4c89a6dbcc7d56ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d52e392f0a08c5d4e1cd1eefccba1d11782f628c88426815e1ae5665e1aaf024f8119d2be4de264487670471bdb52bc8636e52be9c61249491180b433ad8ca
|
7
|
+
data.tar.gz: 7d5f89bd7ca96606e89104b4541f9ccde0b89619b0bbcedad2c95b63e5b82ac87ae31a05eaf2dafaf758131970d34be8576123a0f791bd3aff8921b0e13d5338
|
data/Gemfile.lock
CHANGED
@@ -12,11 +12,33 @@ module RSpec
|
|
12
12
|
include CommandInstantiation
|
13
13
|
|
14
14
|
def apply(parameters)
|
15
|
-
|
15
|
+
parameters = apply_parameters(parameters)
|
16
|
+
|
17
|
+
log_apply_starting(parameters)
|
18
|
+
log_apply_using_parameters(parameters)
|
19
|
+
|
20
|
+
apply_command.execute(parameters)
|
21
|
+
|
22
|
+
log_apply_complete
|
16
23
|
end
|
17
24
|
|
18
25
|
private
|
19
26
|
|
27
|
+
def log_apply_starting(parameters)
|
28
|
+
logger&.info(
|
29
|
+
'Applying for configuration in directory: ' \
|
30
|
+
"'#{parameters[:chdir]}'..."
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_apply_using_parameters(parameters)
|
35
|
+
logger&.debug("Applying using parameters: #{parameters}...")
|
36
|
+
end
|
37
|
+
|
38
|
+
def log_apply_complete
|
39
|
+
logger&.info('Apply complete.')
|
40
|
+
end
|
41
|
+
|
20
42
|
def apply_command
|
21
43
|
instantiate_command(RubyTerraform::Commands::Apply)
|
22
44
|
end
|
@@ -28,16 +50,23 @@ module RSpec
|
|
28
50
|
end
|
29
51
|
|
30
52
|
def with_apply_standard_parameters(parameters)
|
31
|
-
parameters
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
53
|
+
configuration_directory = parameters[:configuration_directory]
|
54
|
+
|
55
|
+
parameters
|
56
|
+
.except(:configuration_directory)
|
57
|
+
.merge(
|
58
|
+
chdir: configuration_directory,
|
59
|
+
input: false,
|
60
|
+
auto_approve: true
|
61
|
+
)
|
36
62
|
end
|
37
63
|
|
38
64
|
def with_apply_state_file_parameters(parameters)
|
39
|
-
|
40
|
-
|
65
|
+
state_file = parameters[:state_file]
|
66
|
+
if state_file
|
67
|
+
return parameters
|
68
|
+
.except(:state_file)
|
69
|
+
.merge(state: state_file)
|
41
70
|
end
|
42
71
|
|
43
72
|
parameters
|
@@ -8,8 +8,27 @@ module RSpec
|
|
8
8
|
def clean(parameters)
|
9
9
|
return unless execution_mode == :isolated
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
configuration_directory = parameters[:configuration_directory]
|
12
|
+
|
13
|
+
log_clean_starting(configuration_directory)
|
14
|
+
|
15
|
+
FileUtils.rm_rf(configuration_directory)
|
16
|
+
FileUtils.mkdir_p(configuration_directory)
|
17
|
+
|
18
|
+
log_clean_complete
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def log_clean_starting(configuration_directory)
|
24
|
+
logger&.info(
|
25
|
+
'Cleaning configuration directory: ' \
|
26
|
+
"'#{configuration_directory}'..."
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def log_clean_complete
|
31
|
+
logger&.info('Clean complete.')
|
13
32
|
end
|
14
33
|
end
|
15
34
|
end
|
@@ -12,11 +12,33 @@ module RSpec
|
|
12
12
|
include CommandInstantiation
|
13
13
|
|
14
14
|
def destroy(parameters)
|
15
|
-
|
15
|
+
parameters = destroy_parameters(parameters)
|
16
|
+
|
17
|
+
log_destroy_starting(parameters)
|
18
|
+
log_destroy_using_parameters(parameters)
|
19
|
+
|
20
|
+
destroy_command.execute(parameters)
|
21
|
+
|
22
|
+
log_destroy_complete
|
16
23
|
end
|
17
24
|
|
18
25
|
private
|
19
26
|
|
27
|
+
def log_destroy_starting(parameters)
|
28
|
+
logger&.info(
|
29
|
+
'Destroying for configuration in directory: ' \
|
30
|
+
"'#{parameters[:chdir]}'..."
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_destroy_using_parameters(parameters)
|
35
|
+
logger&.debug("Destroying using parameters: #{parameters}...")
|
36
|
+
end
|
37
|
+
|
38
|
+
def log_destroy_complete
|
39
|
+
logger&.info('Destroy complete.')
|
40
|
+
end
|
41
|
+
|
20
42
|
def destroy_command
|
21
43
|
instantiate_command(RubyTerraform::Commands::Destroy)
|
22
44
|
end
|
@@ -28,16 +50,23 @@ module RSpec
|
|
28
50
|
end
|
29
51
|
|
30
52
|
def with_destroy_standard_parameters(parameters)
|
31
|
-
parameters
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
53
|
+
configuration_directory = parameters[:configuration_directory]
|
54
|
+
|
55
|
+
parameters
|
56
|
+
.except(:configuration_directory)
|
57
|
+
.merge(
|
58
|
+
chdir: configuration_directory,
|
59
|
+
input: false,
|
60
|
+
auto_approve: true
|
61
|
+
)
|
36
62
|
end
|
37
63
|
|
38
64
|
def with_destroy_state_file_parameters(parameters)
|
39
|
-
|
40
|
-
|
65
|
+
state_file = parameters[:state_file]
|
66
|
+
if state_file
|
67
|
+
return parameters
|
68
|
+
.except(:state_file)
|
69
|
+
.merge(state: state_file)
|
41
70
|
end
|
42
71
|
|
43
72
|
parameters
|
@@ -5,12 +5,35 @@ module RSpec
|
|
5
5
|
module Helpers
|
6
6
|
module Actions
|
7
7
|
module ExecuteIfRequired
|
8
|
-
def execute_if_required(parameters, &block)
|
8
|
+
def execute_if_required(name, parameters, &block)
|
9
|
+
log_execute_if_required_starting(name)
|
10
|
+
|
11
|
+
if should_execute(parameters)
|
12
|
+
log_execute_if_required_continuing
|
13
|
+
block.call
|
14
|
+
else
|
15
|
+
log_execute_if_required_skipping
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def should_execute(parameters)
|
9
22
|
only_if = parameters[:only_if]
|
10
23
|
only_if_args = only_if ? [parameters].slice(0, only_if.arity) : []
|
11
|
-
|
24
|
+
only_if ? only_if.call(*only_if_args) : true
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_execute_if_required_starting(name)
|
28
|
+
logger&.info("Checking if execution of #{name} required...")
|
29
|
+
end
|
30
|
+
|
31
|
+
def log_execute_if_required_continuing
|
32
|
+
logger&.info('Execution required. Continuing...')
|
33
|
+
end
|
12
34
|
|
13
|
-
|
35
|
+
def log_execute_if_required_skipping
|
36
|
+
logger&.info('Execution not required. Skipping...')
|
14
37
|
end
|
15
38
|
end
|
16
39
|
end
|
@@ -12,11 +12,33 @@ module RSpec
|
|
12
12
|
include CommandInstantiation
|
13
13
|
|
14
14
|
def init(parameters)
|
15
|
-
|
15
|
+
parameters = init_parameters(parameters)
|
16
|
+
|
17
|
+
log_init_starting(parameters)
|
18
|
+
log_init_using_parameters(parameters)
|
19
|
+
|
20
|
+
init_command.execute(parameters)
|
21
|
+
|
22
|
+
log_init_complete
|
16
23
|
end
|
17
24
|
|
18
25
|
private
|
19
26
|
|
27
|
+
def log_init_starting(parameters)
|
28
|
+
logger&.info(
|
29
|
+
'Initing for configuration in directory: ' \
|
30
|
+
"'#{parameters[:chdir]}'..."
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_init_using_parameters(parameters)
|
35
|
+
logger&.debug("Initing using parameters: #{parameters}...")
|
36
|
+
end
|
37
|
+
|
38
|
+
def log_init_complete
|
39
|
+
logger&.info('Init complete.')
|
40
|
+
end
|
41
|
+
|
20
42
|
def init_command
|
21
43
|
instantiate_command(RubyTerraform::Commands::Init)
|
22
44
|
end
|
@@ -28,17 +50,22 @@ module RSpec
|
|
28
50
|
end
|
29
51
|
|
30
52
|
def with_init_standard_parameters(parameters)
|
31
|
-
parameters
|
32
|
-
|
33
|
-
|
34
|
-
|
53
|
+
configuration_directory = parameters[:configuration_directory]
|
54
|
+
|
55
|
+
parameters
|
56
|
+
.except(:configuration_directory)
|
57
|
+
.merge(
|
58
|
+
chdir: configuration_directory,
|
59
|
+
input: false
|
60
|
+
)
|
35
61
|
end
|
36
62
|
|
37
63
|
def with_init_execution_mode_parameters(parameters)
|
64
|
+
source_directory = parameters[:source_directory]
|
65
|
+
parameters = parameters.except(:source_directory)
|
66
|
+
|
38
67
|
if execution_mode == :isolated
|
39
|
-
return parameters.merge(
|
40
|
-
from_module: parameters[:source_directory]
|
41
|
-
)
|
68
|
+
return parameters.merge(from_module: source_directory)
|
42
69
|
end
|
43
70
|
|
44
71
|
parameters
|
@@ -14,13 +14,36 @@ module RSpec
|
|
14
14
|
|
15
15
|
def output(parameters)
|
16
16
|
stdout = StringIO.new
|
17
|
+
parameters = output_parameters(parameters)
|
18
|
+
|
19
|
+
log_output_starting(parameters)
|
20
|
+
log_output_using_parameters(parameters)
|
21
|
+
|
17
22
|
output_command(stdout: stdout)
|
18
|
-
.execute(
|
23
|
+
.execute(parameters)
|
24
|
+
|
25
|
+
log_output_complete
|
26
|
+
|
19
27
|
stdout.string
|
20
28
|
end
|
21
29
|
|
22
30
|
private
|
23
31
|
|
32
|
+
def log_output_starting(parameters)
|
33
|
+
logger&.info(
|
34
|
+
'Outputting for configuration in directory: ' \
|
35
|
+
"'#{parameters[:chdir]}'..."
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def log_output_using_parameters(parameters)
|
40
|
+
logger&.debug("Outputting using parameters: #{parameters}...")
|
41
|
+
end
|
42
|
+
|
43
|
+
def log_output_complete
|
44
|
+
logger&.info('Output complete.')
|
45
|
+
end
|
46
|
+
|
24
47
|
def output_command(opts = {})
|
25
48
|
instantiate_command(RubyTerraform::Commands::Output, opts)
|
26
49
|
end
|
@@ -32,14 +55,21 @@ module RSpec
|
|
32
55
|
end
|
33
56
|
|
34
57
|
def with_output_standard_parameters(parameters)
|
35
|
-
parameters
|
36
|
-
|
37
|
-
|
58
|
+
configuration_directory = parameters[:configuration_directory]
|
59
|
+
|
60
|
+
parameters
|
61
|
+
.except(:configuration_directory)
|
62
|
+
.merge(
|
63
|
+
chdir: configuration_directory
|
64
|
+
)
|
38
65
|
end
|
39
66
|
|
40
67
|
def with_output_state_file_parameters(parameters)
|
41
|
-
|
42
|
-
|
68
|
+
state_file = parameters[:state_file]
|
69
|
+
if state_file
|
70
|
+
return parameters
|
71
|
+
.except(:state_file)
|
72
|
+
.merge(state: state_file)
|
43
73
|
end
|
44
74
|
|
45
75
|
parameters
|
@@ -13,13 +13,35 @@ module RSpec
|
|
13
13
|
include CommandInstantiation
|
14
14
|
|
15
15
|
def plan(parameters)
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
parameters = plan_parameters(parameters)
|
17
|
+
|
18
|
+
log_plan_starting(parameters)
|
19
|
+
log_plan_using_parameters(parameters)
|
20
|
+
|
21
|
+
plan_command.execute(parameters)
|
22
|
+
|
23
|
+
log_plan_complete
|
24
|
+
|
25
|
+
parameters[:out]
|
19
26
|
end
|
20
27
|
|
21
28
|
private
|
22
29
|
|
30
|
+
def log_plan_starting(parameters)
|
31
|
+
logger&.info(
|
32
|
+
'Planning for configuration in directory: ' \
|
33
|
+
"'#{parameters[:chdir]}'..."
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def log_plan_using_parameters(parameters)
|
38
|
+
logger&.debug("Planning using parameters: #{parameters}...")
|
39
|
+
end
|
40
|
+
|
41
|
+
def log_plan_complete
|
42
|
+
logger&.info('Plan complete.')
|
43
|
+
end
|
44
|
+
|
23
45
|
def plan_command
|
24
46
|
instantiate_command(RubyTerraform::Commands::Plan)
|
25
47
|
end
|
@@ -31,17 +53,32 @@ module RSpec
|
|
31
53
|
end
|
32
54
|
|
33
55
|
def with_plan_standard_parameters(parameters)
|
34
|
-
parameters
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
56
|
+
configuration_directory = parameters[:configuration_directory]
|
57
|
+
plan_file_name = resolve_plan_file_name(parameters)
|
58
|
+
|
59
|
+
parameters
|
60
|
+
.except(:configuration_directory, :plan_file_name)
|
61
|
+
.merge(
|
62
|
+
chdir: configuration_directory,
|
63
|
+
out: plan_file_name,
|
64
|
+
input: false
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def resolve_plan_file_name(parameters)
|
69
|
+
parameters[:plan_file_name] || random_plan_file_name
|
70
|
+
end
|
71
|
+
|
72
|
+
def random_plan_file_name
|
73
|
+
"#{SecureRandom.hex[0, 10]}.tfplan"
|
40
74
|
end
|
41
75
|
|
42
76
|
def with_plan_state_file_parameters(parameters)
|
43
|
-
|
44
|
-
|
77
|
+
state_file = parameters[:state_file]
|
78
|
+
if state_file
|
79
|
+
return parameters
|
80
|
+
.except(:state_file)
|
81
|
+
.merge(state: state_file)
|
45
82
|
end
|
46
83
|
|
47
84
|
parameters
|
@@ -8,9 +8,28 @@ module RSpec
|
|
8
8
|
module Actions
|
9
9
|
module Remove
|
10
10
|
def remove(parameters, file)
|
11
|
+
configuration_directory = parameters[:configuration_directory]
|
12
|
+
|
13
|
+
log_remove_starting(configuration_directory, file)
|
14
|
+
|
11
15
|
FileUtils.rm_f(
|
12
|
-
File.join(
|
16
|
+
File.join(configuration_directory, file)
|
13
17
|
)
|
18
|
+
|
19
|
+
log_remove_complete
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def log_remove_starting(configuration_directory, file)
|
25
|
+
logger&.info(
|
26
|
+
"Removing file: '#{file}' in configuration directory: " \
|
27
|
+
"'#{configuration_directory}'..."
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def log_remove_complete
|
32
|
+
logger&.info('Remove complete.')
|
14
33
|
end
|
15
34
|
end
|
16
35
|
end
|
@@ -13,14 +13,37 @@ module RSpec
|
|
13
13
|
include CommandInstantiation
|
14
14
|
|
15
15
|
def show(parameters, plan_file)
|
16
|
+
parameters = show_parameters(parameters, plan_file)
|
17
|
+
|
18
|
+
log_show_starting(parameters, plan_file)
|
19
|
+
log_show_using_parameters(parameters)
|
20
|
+
|
16
21
|
stdout = StringIO.new
|
17
22
|
show_command(stdout: stdout)
|
18
|
-
.execute(
|
23
|
+
.execute(parameters)
|
24
|
+
|
25
|
+
log_show_complete
|
26
|
+
|
19
27
|
stdout.string
|
20
28
|
end
|
21
29
|
|
22
30
|
private
|
23
31
|
|
32
|
+
def log_show_starting(parameters, plan_file)
|
33
|
+
logger&.info(
|
34
|
+
"Showing file: '#{plan_file}' in configuration directory: " \
|
35
|
+
"'#{parameters[:chdir]}'..."
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def log_show_using_parameters(parameters)
|
40
|
+
logger&.debug("Showing using parameters: #{parameters}...")
|
41
|
+
end
|
42
|
+
|
43
|
+
def log_show_complete
|
44
|
+
logger&.info('Show complete.')
|
45
|
+
end
|
46
|
+
|
24
47
|
def show_command(opts = {})
|
25
48
|
instantiate_command(RubyTerraform::Commands::Show, opts)
|
26
49
|
end
|
@@ -33,11 +56,15 @@ module RSpec
|
|
33
56
|
end
|
34
57
|
|
35
58
|
def with_show_standard_parameters(parameters)
|
36
|
-
parameters
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
59
|
+
configuration_directory = parameters[:configuration_directory]
|
60
|
+
|
61
|
+
parameters
|
62
|
+
.except(:configuration_directory)
|
63
|
+
.merge(
|
64
|
+
chdir: configuration_directory,
|
65
|
+
no_color: true,
|
66
|
+
json: true
|
67
|
+
)
|
41
68
|
end
|
42
69
|
|
43
70
|
def with_show_plan_file_parameters(parameters, plan_file)
|
@@ -6,17 +6,49 @@ module RSpec
|
|
6
6
|
module Actions
|
7
7
|
module Validate
|
8
8
|
def validate(parameters)
|
9
|
-
|
10
|
-
required_parameters(execution_mode)
|
11
|
-
.filter { |parameter| parameters[parameter].nil? }
|
9
|
+
required = required_parameters(execution_mode)
|
12
10
|
|
13
|
-
|
11
|
+
log_validate_starting(required)
|
12
|
+
log_validate_using_parameters(parameters)
|
14
13
|
|
15
|
-
|
14
|
+
missing = determine_missing(parameters, required)
|
15
|
+
|
16
|
+
handle_result(missing)
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
21
|
+
def determine_missing(parameters, required)
|
22
|
+
required.filter { |parameter| parameters[parameter].nil? }
|
23
|
+
end
|
24
|
+
|
25
|
+
def handle_result(missing)
|
26
|
+
if missing.empty?
|
27
|
+
log_validate_successful
|
28
|
+
else
|
29
|
+
log_validate_failed(missing)
|
30
|
+
raise_missing_parameters(missing)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_validate_starting(required)
|
35
|
+
logger&.info(
|
36
|
+
"Validating required parameters: #{required} present..."
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_validate_using_parameters(parameters)
|
41
|
+
logger&.debug("Validating parameters: #{parameters}...")
|
42
|
+
end
|
43
|
+
|
44
|
+
def log_validate_successful
|
45
|
+
logger&.info('Validate successful.')
|
46
|
+
end
|
47
|
+
|
48
|
+
def log_validate_failed(missing)
|
49
|
+
logger&.error("Validate failed. Parameters: #{missing} missing.")
|
50
|
+
end
|
51
|
+
|
20
52
|
def raise_missing_parameters(parameters)
|
21
53
|
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
22
54
|
if parameters.count == 1
|
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.48
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: confidante
|