rspec-terraform 0.1.0.pre.47 → 0.1.0.pre.49
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/README.md +163 -10
- 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: 71e9d6c1dcc91011ceaaf7e50cb2f449453ed10157afa51675e644404df114cb
|
4
|
+
data.tar.gz: c7efffc268030aedb282fb8e72dfb2d7d1ee9ae97c8fe0896f08e3817aeb8a42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57bb3067903397d0378278b20a4e1f91ff1e5fde1576a8e156221279d33d64a316d3704b6f5cbad2317e000e80a12ec4c152f7b7fcda731f1956516c7363f62
|
7
|
+
data.tar.gz: '094cc08b00bf0209439809d707636a1a4bcf112865bc6f6ce9a90b0d558719e11fcb18ad318bf4f81a08fed2938ce71057463cdf44a4f5abfc645c6ebbd7bd9a'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# RSpec::Terraform
|
2
2
|
|
3
|
-
RSpec
|
3
|
+
An RSpec extension for verifying Terraform configurations, with support for:
|
4
|
+
|
5
|
+
* unit testing;
|
6
|
+
* integration testing;
|
7
|
+
* end-to-end testing; and
|
8
|
+
* change auditing.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -20,19 +25,167 @@ Or install it yourself as:
|
|
20
25
|
|
21
26
|
## Usage
|
22
27
|
|
23
|
-
|
28
|
+
To use RSpec::Terraform, require it in your `spec_helper.rb` file:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'rspec/terraform'
|
32
|
+
```
|
33
|
+
|
34
|
+
When required, RSpec::Terraform automatically configures itself against
|
35
|
+
RSpec by:
|
36
|
+
|
37
|
+
* adding helper methods to interact with Terraform;
|
38
|
+
* adding matchers to verify Terraform plans; and
|
39
|
+
* adding settings to control RSpec::Terraform's behaviour.
|
40
|
+
|
41
|
+
The sections below provide further details on each of these additions.
|
42
|
+
|
43
|
+
### Helper methods
|
44
|
+
|
45
|
+
RSpec::Terraform adds helper methods to the RSpec DSL for planning, applying,
|
46
|
+
and destroying Terraform configurations, as well as accessing variables to and
|
47
|
+
outputs from Terraform configurations.
|
48
|
+
|
49
|
+
Each helper method takes a hash of parameters used to identify the configuration
|
50
|
+
against which to act and to provide as options to the Terraform command being
|
51
|
+
executed. Additionally, RSpec::Terraform includes a flexible approach to
|
52
|
+
resolving these parameters allowing them to be sourced from a variety of
|
53
|
+
locations. See the [Configuration Providers](#configuration-providers) section
|
54
|
+
for more details.
|
55
|
+
|
56
|
+
When executing helper methods, RSpec::Terraform provides two execution modes,
|
57
|
+
`:in_place` and `:isolated`. By default, RSpec::Terraform works against a
|
58
|
+
Terraform configuration _in place_, i.e., it executes commands against the
|
59
|
+
Terraform configuration directly, in the location specified. RSpec::Terraform
|
60
|
+
can also operate in an _isolated_ manner, wherein it initialises the
|
61
|
+
configuration into an isolated directory before executing commands. See the
|
62
|
+
[Execution Mode](#execution-mode) section for more details.
|
63
|
+
|
64
|
+
#### `plan`
|
65
|
+
|
66
|
+
The `plan` helper produces a Terraform plan for a configuration, reads it
|
67
|
+
into a Ruby representation and returns it.
|
68
|
+
|
69
|
+
`plan` requires a `:configuration_directory` parameter, representing the path
|
70
|
+
to the configuration to plan and is typically invoked in a `before(:context)`
|
71
|
+
hook, with the resulting plan stored for use in expectations:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
before(:context) do
|
75
|
+
@plan = plan(
|
76
|
+
configuration_directory: 'path/to/configuration/directory'
|
77
|
+
)
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
If the configuration has input variables, a `:vars` parameter can be provided
|
82
|
+
as a hash:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
before(:context) do
|
86
|
+
@plan = plan(
|
87
|
+
configuration_directory: 'path/to/configuration/directory',
|
88
|
+
vars: {
|
89
|
+
region: 'uk',
|
90
|
+
zones: ['uk-a', 'uk-b'],
|
91
|
+
tags: {
|
92
|
+
name: 'important-thing',
|
93
|
+
role: 'persistence'
|
94
|
+
}
|
95
|
+
}
|
96
|
+
)
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
or within a block:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
before(:context) do
|
104
|
+
@plan = plan(
|
105
|
+
configuration_directory: 'path/to/configuration/directory'
|
106
|
+
) do |vars|
|
107
|
+
vars.region = 'uk'
|
108
|
+
vars.zones = ['uk-a', 'uk-b']
|
109
|
+
vars.tags = {
|
110
|
+
name: 'important-thing',
|
111
|
+
role: 'persistence'
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
`plan` accepts an optional `:state_file` parameter with the path to where the
|
118
|
+
current state file for the configuration is located, useful when checking the
|
119
|
+
incremental change that applying the configuration would have after a previous
|
120
|
+
apply.
|
121
|
+
|
122
|
+
Internally, `plan`:
|
123
|
+
* calls `terraform init` to initialise the configuration directory;
|
124
|
+
* calls `terraform plan` to produce a plan file;
|
125
|
+
* calls `terraform show` to read the contents of the plan file into a Ruby
|
126
|
+
representation; and
|
127
|
+
* deletes the plan file.
|
128
|
+
|
129
|
+
Any additional parameters passed to `plan` are passed on to the underlying
|
130
|
+
Terraform invocations.
|
131
|
+
|
132
|
+
#### `apply`
|
133
|
+
|
134
|
+
#### `destroy`
|
135
|
+
|
136
|
+
#### `output`
|
137
|
+
|
138
|
+
#### `var`
|
139
|
+
|
140
|
+
### Plan Matchers
|
141
|
+
|
142
|
+
### Settings
|
143
|
+
|
144
|
+
#### Binary Location
|
145
|
+
|
146
|
+
#### Logging and Standard Streams
|
147
|
+
|
148
|
+
#### Execution Mode
|
149
|
+
|
150
|
+
The benefit of isolated execution is that nothing is carried over between test
|
151
|
+
runs and providers and modules are fetched into a clean configuration directory
|
152
|
+
every time. The downside is additional test run time.
|
153
|
+
|
154
|
+
#### Configuration Providers
|
155
|
+
|
156
|
+
### Frequently Asked Questions
|
24
157
|
|
25
158
|
## Development
|
26
159
|
|
27
|
-
|
28
|
-
|
29
|
-
|
160
|
+
To install dependencies and run the build, run the pre-commit build:
|
161
|
+
|
162
|
+
```shell
|
163
|
+
./go
|
164
|
+
```
|
165
|
+
|
166
|
+
This runs all unit tests and other checks including coverage and code linting /
|
167
|
+
formatting.
|
168
|
+
|
169
|
+
To run only the unit tests, including coverage:
|
170
|
+
|
171
|
+
```shell
|
172
|
+
./go test:unit
|
173
|
+
```
|
174
|
+
|
175
|
+
To attempt to fix any code linting / formatting issues:
|
176
|
+
|
177
|
+
```shell
|
178
|
+
./go library:fix
|
179
|
+
```
|
180
|
+
|
181
|
+
To check for code linting / formatting issues without fixing:
|
182
|
+
|
183
|
+
```shell
|
184
|
+
./go library:check
|
185
|
+
```
|
30
186
|
|
31
|
-
|
32
|
-
|
33
|
-
`bundle exec rake release`, which will create a git tag for the version, push
|
34
|
-
git commits and tags, and push the `.gem` file to
|
35
|
-
[rubygems.org](https://rubygems.org).
|
187
|
+
You can also run `bin/console` for an interactive prompt that will allow you to
|
188
|
+
experiment.
|
36
189
|
|
37
190
|
### Managing CircleCI keys
|
38
191
|
|
@@ -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.49
|
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-
|
11
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: confidante
|