rspec-terraform 0.1.0.pre.27 → 0.1.0.pre.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbe0f55f0b5903a638e780131a1a32b5e0859b0b92c36f431938ffb929568efc
4
- data.tar.gz: d052537b7512b50b1b94509b50cbb07b493f2efe18ec34a1326bf0555b7631ed
3
+ metadata.gz: 1c8f792e87abefbea94694f0fee81efbae81c54361681352b5f37860a8daad4e
4
+ data.tar.gz: c95be85f8b07bde0d80fb42c0324b17a0a3973cfd51b29ad025bd377cb0470fe
5
5
  SHA512:
6
- metadata.gz: 9cbe733d1fd152518c6d9df00f5c9137ed51f3e7d7e4121b13c5f4b090fce912a965f2de6417b687b77bc1b68c5c9058b3402e4d6b4434f07383d3511364562d
7
- data.tar.gz: 0ef10564041a355a71e1cf61bfe4eeaf9b1db740074c24916d3d995b5935a24286571cf2098bef841356beb98359acb5ea883ea40cf0b5524435022f2fd573c9
6
+ metadata.gz: d17f25036ba285de0d641952ad1ed0b04bf74cebb87d42125631a2eeb725f2a7da8606a156afe82aa695447c9ccb9ce1629cfde833a89cba8fb5c248690ab03b
7
+ data.tar.gz: 750c207d47f2066f53f76ddc03d072d391163f7312ca83859c3880d9e12e7c0f36f8b28ce941256d8cdc06f5486d4e4fc9b0d56e6274f31f0d3c1013218b5d90
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.27)
4
+ rspec-terraform (0.1.0.pre.28)
5
5
  rspec (>= 3.0)
6
6
  ruby-terraform (= 1.7.0.pre.15)
7
7
 
@@ -183,4 +183,4 @@ DEPENDENCIES
183
183
  terminal-notifier-guard
184
184
 
185
185
  BUNDLED WITH
186
- 2.3.20
186
+ 2.3.21
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_terraform'
4
+
5
+ module RSpec
6
+ module Terraform
7
+ module Helpers
8
+ class Output
9
+ attr_reader(
10
+ :overrides, :configuration_provider, :binary, :execution_mode
11
+ )
12
+
13
+ def initialize(overrides = {}, configuration_provider = nil)
14
+ @overrides = overrides
15
+ @configuration_provider =
16
+ configuration_provider || Configuration.identity_provider
17
+ @binary = RSpec.configuration.terraform_binary
18
+ @execution_mode = RSpec.configuration.terraform_execution_mode
19
+ end
20
+
21
+ def execute
22
+ parameters = with_configuration_provider_parameters(overrides)
23
+ parameters = with_mandatory_parameters(parameters)
24
+
25
+ ensure_required_parameters(parameters)
26
+
27
+ clean(parameters)
28
+ init(parameters)
29
+ output_value = output(parameters)
30
+
31
+ JSON.parse(output_value, symbolize_names: true)
32
+ end
33
+
34
+ private
35
+
36
+ def with_configuration_provider_parameters(parameters)
37
+ configuration_provider.resolve(parameters)
38
+ end
39
+
40
+ def with_mandatory_parameters(parameters)
41
+ parameters.merge(
42
+ json: true
43
+ )
44
+ end
45
+
46
+ def required_parameters(execution_mode)
47
+ {
48
+ in_place: %i[name configuration_directory],
49
+ isolated: %i[name source_directory configuration_directory]
50
+ }[execution_mode] || []
51
+ end
52
+
53
+ def ensure_required_parameters(parameters)
54
+ missing_parameters =
55
+ required_parameters(execution_mode)
56
+ .filter { |parameter| parameters[parameter].nil? }
57
+
58
+ return if missing_parameters.empty?
59
+
60
+ raise_missing_parameters(missing_parameters)
61
+ end
62
+
63
+ def raise_missing_parameters(parameters)
64
+ parameters = parameters.collect { |parameter| "`:#{parameter}`" }
65
+ if parameters.count == 1
66
+ raise StandardError,
67
+ "Required parameter: #{parameters[0]} missing."
68
+ else
69
+ parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
70
+ raise StandardError,
71
+ "Required parameters: #{parameters} missing."
72
+ end
73
+ end
74
+
75
+ def clean(parameters)
76
+ return unless execution_mode == :isolated
77
+
78
+ FileUtils.rm_rf(parameters[:configuration_directory])
79
+ FileUtils.mkdir_p(parameters[:configuration_directory])
80
+ end
81
+
82
+ def init(parameters)
83
+ init_command.execute(init_parameters(parameters))
84
+ end
85
+
86
+ def output(parameters)
87
+ stdout = StringIO.new
88
+ output_command(stdout: stdout)
89
+ .execute(output_parameters(parameters))
90
+ stdout.string
91
+ end
92
+
93
+ def init_command
94
+ RubyTerraform::Commands::Init.new(binary: binary)
95
+ end
96
+
97
+ def output_command(opts = {})
98
+ RubyTerraform::Commands::Output.new(opts.merge(binary: binary))
99
+ end
100
+
101
+ def init_parameters(parameters)
102
+ init_parameters = parameters.merge(
103
+ chdir: parameters[:configuration_directory],
104
+ input: false
105
+ )
106
+ if execution_mode == :isolated
107
+ init_parameters =
108
+ init_parameters.merge(from_module: parameters[:source_directory])
109
+ end
110
+
111
+ init_parameters
112
+ end
113
+
114
+ def output_parameters(parameters)
115
+ output_parameters =
116
+ parameters.merge(
117
+ chdir: parameters[:configuration_directory]
118
+ )
119
+
120
+ if parameters[:state_file]
121
+ output_parameters =
122
+ output_parameters.merge(state: parameters[:state_file])
123
+ end
124
+
125
+ output_parameters
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -3,6 +3,7 @@
3
3
  require_relative './helpers/apply'
4
4
  require_relative './helpers/destroy'
5
5
  require_relative './helpers/plan'
6
+ require_relative './helpers/output'
6
7
 
7
8
  module RSpec
8
9
  module Terraform
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.27'
5
+ VERSION = '0.1.0.pre.28'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.27
4
+ version: 0.1.0.pre.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
@@ -288,6 +288,7 @@ files:
288
288
  - lib/rspec/terraform/helpers.rb
289
289
  - lib/rspec/terraform/helpers/apply.rb
290
290
  - lib/rspec/terraform/helpers/destroy.rb
291
+ - lib/rspec/terraform/helpers/output.rb
291
292
  - lib/rspec/terraform/helpers/plan.rb
292
293
  - lib/rspec/terraform/matchers.rb
293
294
  - lib/rspec/terraform/matchers/include_output_change.rb