rspec-terraform 0.1.0.pre.46 → 0.1.0.pre.48
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
- data/Gemfile.lock +1 -1
- data/lib/rspec/terraform/helpers/actions/apply.rb +78 -0
- data/lib/rspec/terraform/helpers/actions/clean.rb +37 -0
- data/lib/rspec/terraform/helpers/actions/command_instantiation.rb +15 -0
- data/lib/rspec/terraform/helpers/actions/destroy.rb +78 -0
- data/lib/rspec/terraform/helpers/actions/execute_if_required.rb +42 -0
- data/lib/rspec/terraform/helpers/actions/init.rb +77 -0
- data/lib/rspec/terraform/helpers/actions/output.rb +81 -0
- data/lib/rspec/terraform/helpers/actions/plan.rb +90 -0
- data/lib/rspec/terraform/helpers/actions/remove.rb +38 -0
- data/lib/rspec/terraform/helpers/actions/show.rb +79 -0
- data/lib/rspec/terraform/helpers/actions/validate.rb +68 -0
- data/lib/rspec/terraform/helpers/actions.rb +10 -207
- data/lib/rspec/terraform/helpers/apply.rb +8 -1
- data/lib/rspec/terraform/helpers/base.rb +0 -2
- data/lib/rspec/terraform/helpers/destroy.rb +8 -1
- data/lib/rspec/terraform/helpers/output.rb +6 -0
- data/lib/rspec/terraform/helpers/plan.rb +8 -4
- data/lib/rspec/terraform/version.rb +1 -1
- data/lib/rspec/terraform.rb +0 -1
- metadata +13 -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
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_terraform'
|
4
|
+
|
5
|
+
require_relative './command_instantiation'
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module Terraform
|
9
|
+
module Helpers
|
10
|
+
module Actions
|
11
|
+
module Apply
|
12
|
+
include CommandInstantiation
|
13
|
+
|
14
|
+
def apply(parameters)
|
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
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
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
|
+
|
42
|
+
def apply_command
|
43
|
+
instantiate_command(RubyTerraform::Commands::Apply)
|
44
|
+
end
|
45
|
+
|
46
|
+
def apply_parameters(parameters)
|
47
|
+
with_apply_state_file_parameters(
|
48
|
+
with_apply_standard_parameters(parameters)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_apply_standard_parameters(parameters)
|
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
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def with_apply_state_file_parameters(parameters)
|
65
|
+
state_file = parameters[:state_file]
|
66
|
+
if state_file
|
67
|
+
return parameters
|
68
|
+
.except(:state_file)
|
69
|
+
.merge(state: state_file)
|
70
|
+
end
|
71
|
+
|
72
|
+
parameters
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Terraform
|
5
|
+
module Helpers
|
6
|
+
module Actions
|
7
|
+
module Clean
|
8
|
+
def clean(parameters)
|
9
|
+
return unless execution_mode == :isolated
|
10
|
+
|
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.')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Terraform
|
5
|
+
module Helpers
|
6
|
+
module Actions
|
7
|
+
module CommandInstantiation
|
8
|
+
def instantiate_command(klass, opts = {})
|
9
|
+
klass.new(command_options.merge(opts))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_terraform'
|
4
|
+
|
5
|
+
require_relative './command_instantiation'
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module Terraform
|
9
|
+
module Helpers
|
10
|
+
module Actions
|
11
|
+
module Destroy
|
12
|
+
include CommandInstantiation
|
13
|
+
|
14
|
+
def destroy(parameters)
|
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
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
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
|
+
|
42
|
+
def destroy_command
|
43
|
+
instantiate_command(RubyTerraform::Commands::Destroy)
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy_parameters(parameters)
|
47
|
+
with_destroy_state_file_parameters(
|
48
|
+
with_destroy_standard_parameters(parameters)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_destroy_standard_parameters(parameters)
|
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
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def with_destroy_state_file_parameters(parameters)
|
65
|
+
state_file = parameters[:state_file]
|
66
|
+
if state_file
|
67
|
+
return parameters
|
68
|
+
.except(:state_file)
|
69
|
+
.merge(state: state_file)
|
70
|
+
end
|
71
|
+
|
72
|
+
parameters
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Terraform
|
5
|
+
module Helpers
|
6
|
+
module Actions
|
7
|
+
module ExecuteIfRequired
|
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)
|
22
|
+
only_if = parameters[:only_if]
|
23
|
+
only_if_args = only_if ? [parameters].slice(0, only_if.arity) : []
|
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
|
34
|
+
|
35
|
+
def log_execute_if_required_skipping
|
36
|
+
logger&.info('Execution not required. Skipping...')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_terraform'
|
4
|
+
|
5
|
+
require_relative './command_instantiation'
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module Terraform
|
9
|
+
module Helpers
|
10
|
+
module Actions
|
11
|
+
module Init
|
12
|
+
include CommandInstantiation
|
13
|
+
|
14
|
+
def init(parameters)
|
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
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
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
|
+
|
42
|
+
def init_command
|
43
|
+
instantiate_command(RubyTerraform::Commands::Init)
|
44
|
+
end
|
45
|
+
|
46
|
+
def init_parameters(parameters)
|
47
|
+
with_init_execution_mode_parameters(
|
48
|
+
with_init_standard_parameters(parameters)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_init_standard_parameters(parameters)
|
53
|
+
configuration_directory = parameters[:configuration_directory]
|
54
|
+
|
55
|
+
parameters
|
56
|
+
.except(:configuration_directory)
|
57
|
+
.merge(
|
58
|
+
chdir: configuration_directory,
|
59
|
+
input: false
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def with_init_execution_mode_parameters(parameters)
|
64
|
+
source_directory = parameters[:source_directory]
|
65
|
+
parameters = parameters.except(:source_directory)
|
66
|
+
|
67
|
+
if execution_mode == :isolated
|
68
|
+
return parameters.merge(from_module: source_directory)
|
69
|
+
end
|
70
|
+
|
71
|
+
parameters
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_terraform'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
require_relative './command_instantiation'
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
module Terraform
|
10
|
+
module Helpers
|
11
|
+
module Actions
|
12
|
+
module Output
|
13
|
+
include CommandInstantiation
|
14
|
+
|
15
|
+
def output(parameters)
|
16
|
+
stdout = StringIO.new
|
17
|
+
parameters = output_parameters(parameters)
|
18
|
+
|
19
|
+
log_output_starting(parameters)
|
20
|
+
log_output_using_parameters(parameters)
|
21
|
+
|
22
|
+
output_command(stdout: stdout)
|
23
|
+
.execute(parameters)
|
24
|
+
|
25
|
+
log_output_complete
|
26
|
+
|
27
|
+
stdout.string
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
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
|
+
|
47
|
+
def output_command(opts = {})
|
48
|
+
instantiate_command(RubyTerraform::Commands::Output, opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
def output_parameters(parameters)
|
52
|
+
with_output_state_file_parameters(
|
53
|
+
with_output_standard_parameters(parameters)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def with_output_standard_parameters(parameters)
|
58
|
+
configuration_directory = parameters[:configuration_directory]
|
59
|
+
|
60
|
+
parameters
|
61
|
+
.except(:configuration_directory)
|
62
|
+
.merge(
|
63
|
+
chdir: configuration_directory
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def with_output_state_file_parameters(parameters)
|
68
|
+
state_file = parameters[:state_file]
|
69
|
+
if state_file
|
70
|
+
return parameters
|
71
|
+
.except(:state_file)
|
72
|
+
.merge(state: state_file)
|
73
|
+
end
|
74
|
+
|
75
|
+
parameters
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_terraform'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
require_relative './command_instantiation'
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
module Terraform
|
10
|
+
module Helpers
|
11
|
+
module Actions
|
12
|
+
module Plan
|
13
|
+
include CommandInstantiation
|
14
|
+
|
15
|
+
def plan(parameters)
|
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]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
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
|
+
|
45
|
+
def plan_command
|
46
|
+
instantiate_command(RubyTerraform::Commands::Plan)
|
47
|
+
end
|
48
|
+
|
49
|
+
def plan_parameters(parameters)
|
50
|
+
with_plan_state_file_parameters(
|
51
|
+
with_plan_standard_parameters(parameters)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def with_plan_standard_parameters(parameters)
|
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"
|
74
|
+
end
|
75
|
+
|
76
|
+
def with_plan_state_file_parameters(parameters)
|
77
|
+
state_file = parameters[:state_file]
|
78
|
+
if state_file
|
79
|
+
return parameters
|
80
|
+
.except(:state_file)
|
81
|
+
.merge(state: state_file)
|
82
|
+
end
|
83
|
+
|
84
|
+
parameters
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Terraform
|
7
|
+
module Helpers
|
8
|
+
module Actions
|
9
|
+
module Remove
|
10
|
+
def remove(parameters, file)
|
11
|
+
configuration_directory = parameters[:configuration_directory]
|
12
|
+
|
13
|
+
log_remove_starting(configuration_directory, file)
|
14
|
+
|
15
|
+
FileUtils.rm_f(
|
16
|
+
File.join(configuration_directory, file)
|
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.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_terraform'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
require_relative './command_instantiation'
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
module Terraform
|
10
|
+
module Helpers
|
11
|
+
module Actions
|
12
|
+
module Show
|
13
|
+
include CommandInstantiation
|
14
|
+
|
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
|
+
|
21
|
+
stdout = StringIO.new
|
22
|
+
show_command(stdout: stdout)
|
23
|
+
.execute(parameters)
|
24
|
+
|
25
|
+
log_show_complete
|
26
|
+
|
27
|
+
stdout.string
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
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
|
+
|
47
|
+
def show_command(opts = {})
|
48
|
+
instantiate_command(RubyTerraform::Commands::Show, opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
def show_parameters(parameters, plan_file)
|
52
|
+
with_show_plan_file_parameters(
|
53
|
+
with_show_standard_parameters(parameters),
|
54
|
+
plan_file
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def with_show_standard_parameters(parameters)
|
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
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def with_show_plan_file_parameters(parameters, plan_file)
|
71
|
+
parameters.merge(
|
72
|
+
path: plan_file
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Terraform
|
5
|
+
module Helpers
|
6
|
+
module Actions
|
7
|
+
module Validate
|
8
|
+
def validate(parameters)
|
9
|
+
required = required_parameters(execution_mode)
|
10
|
+
|
11
|
+
log_validate_starting(required)
|
12
|
+
log_validate_using_parameters(parameters)
|
13
|
+
|
14
|
+
missing = determine_missing(parameters, required)
|
15
|
+
|
16
|
+
handle_result(missing)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
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
|
+
|
52
|
+
def raise_missing_parameters(parameters)
|
53
|
+
parameters = parameters.collect { |parameter| "`:#{parameter}`" }
|
54
|
+
if parameters.count == 1
|
55
|
+
raise StandardError,
|
56
|
+
"Required parameter: #{parameters[0]} missing."
|
57
|
+
else
|
58
|
+
parameters =
|
59
|
+
"#{parameters[..-2].join(', ')} and #{parameters[-1]}"
|
60
|
+
raise StandardError,
|
61
|
+
"Required parameters: #{parameters} missing."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,209 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
+
require_relative './actions/clean'
|
4
|
+
require_relative './actions/validate'
|
5
|
+
require_relative './actions/init'
|
6
|
+
require_relative './actions/apply'
|
7
|
+
require_relative './actions/destroy'
|
8
|
+
require_relative './actions/plan'
|
9
|
+
require_relative './actions/output'
|
10
|
+
require_relative './actions/show'
|
11
|
+
require_relative './actions/remove'
|
12
|
+
require_relative './actions/execute_if_required'
|
@@ -3,15 +3,22 @@
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
5
|
require_relative './base'
|
6
|
+
require_relative './actions'
|
6
7
|
|
7
8
|
module RSpec
|
8
9
|
module Terraform
|
9
10
|
module Helpers
|
10
11
|
class Apply < Base
|
12
|
+
include Actions::ExecuteIfRequired
|
13
|
+
include Actions::Validate
|
14
|
+
include Actions::Clean
|
15
|
+
include Actions::Init
|
16
|
+
include Actions::Apply
|
17
|
+
|
11
18
|
def execute(overrides = {}, &block)
|
12
19
|
parameters = resolve_parameters(overrides, &block)
|
13
20
|
|
14
|
-
execute_if_required(parameters) do
|
21
|
+
execute_if_required(:apply, parameters) do
|
15
22
|
validate(parameters)
|
16
23
|
clean(parameters)
|
17
24
|
init(parameters)
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './actions'
|
4
3
|
require_relative './parameters'
|
5
4
|
|
6
5
|
module RSpec
|
@@ -8,7 +7,6 @@ module RSpec
|
|
8
7
|
module Helpers
|
9
8
|
class Base
|
10
9
|
include Parameters
|
11
|
-
include Actions
|
12
10
|
|
13
11
|
attr_reader(
|
14
12
|
:configuration_provider,
|
@@ -3,15 +3,22 @@
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
5
|
require_relative './base'
|
6
|
+
require_relative './actions'
|
6
7
|
|
7
8
|
module RSpec
|
8
9
|
module Terraform
|
9
10
|
module Helpers
|
10
11
|
class Destroy < Base
|
12
|
+
include Actions::ExecuteIfRequired
|
13
|
+
include Actions::Validate
|
14
|
+
include Actions::Clean
|
15
|
+
include Actions::Init
|
16
|
+
include Actions::Destroy
|
17
|
+
|
11
18
|
def execute(overrides = {}, &block)
|
12
19
|
parameters = resolve_parameters(overrides, &block)
|
13
20
|
|
14
|
-
execute_if_required(parameters) do
|
21
|
+
execute_if_required(:destroy, parameters) do
|
15
22
|
validate(parameters)
|
16
23
|
clean(parameters)
|
17
24
|
init(parameters)
|
@@ -3,11 +3,17 @@
|
|
3
3
|
require 'ruby_terraform'
|
4
4
|
|
5
5
|
require_relative './base'
|
6
|
+
require_relative './actions'
|
6
7
|
|
7
8
|
module RSpec
|
8
9
|
module Terraform
|
9
10
|
module Helpers
|
10
11
|
class Output < Base
|
12
|
+
include Actions::Validate
|
13
|
+
include Actions::Clean
|
14
|
+
include Actions::Init
|
15
|
+
include Actions::Output
|
16
|
+
|
11
17
|
def execute(overrides = {})
|
12
18
|
parameters = resolve_parameters(overrides)
|
13
19
|
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ruby_terraform'
|
4
|
-
require 'securerandom'
|
5
|
-
require 'stringio'
|
6
|
-
|
7
3
|
require_relative './base'
|
4
|
+
require_relative './actions'
|
8
5
|
|
9
6
|
module RSpec
|
10
7
|
module Terraform
|
11
8
|
module Helpers
|
12
9
|
class Plan < Base
|
10
|
+
include Actions::Validate
|
11
|
+
include Actions::Clean
|
12
|
+
include Actions::Init
|
13
|
+
include Actions::Plan
|
14
|
+
include Actions::Show
|
15
|
+
include Actions::Remove
|
16
|
+
|
13
17
|
def execute(overrides = {}, &block)
|
14
18
|
parameters = resolve_parameters(overrides, &block)
|
15
19
|
|
data/lib/rspec/terraform.rb
CHANGED
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
|
@@ -305,6 +305,17 @@ files:
|
|
305
305
|
- lib/rspec/terraform/configuration/var_captor.rb
|
306
306
|
- lib/rspec/terraform/helpers.rb
|
307
307
|
- lib/rspec/terraform/helpers/actions.rb
|
308
|
+
- lib/rspec/terraform/helpers/actions/apply.rb
|
309
|
+
- lib/rspec/terraform/helpers/actions/clean.rb
|
310
|
+
- lib/rspec/terraform/helpers/actions/command_instantiation.rb
|
311
|
+
- lib/rspec/terraform/helpers/actions/destroy.rb
|
312
|
+
- lib/rspec/terraform/helpers/actions/execute_if_required.rb
|
313
|
+
- lib/rspec/terraform/helpers/actions/init.rb
|
314
|
+
- lib/rspec/terraform/helpers/actions/output.rb
|
315
|
+
- lib/rspec/terraform/helpers/actions/plan.rb
|
316
|
+
- lib/rspec/terraform/helpers/actions/remove.rb
|
317
|
+
- lib/rspec/terraform/helpers/actions/show.rb
|
318
|
+
- lib/rspec/terraform/helpers/actions/validate.rb
|
308
319
|
- lib/rspec/terraform/helpers/apply.rb
|
309
320
|
- lib/rspec/terraform/helpers/base.rb
|
310
321
|
- lib/rspec/terraform/helpers/destroy.rb
|