rspec-terraform 0.1.0.pre.23 → 0.1.0.pre.24

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: 20b9a3c95d0e46b73b0da4b3900f76fc3df5d26a7e7ff2e0301acc6b25cc14f4
4
- data.tar.gz: 2de99c52157ff998a66f583100fab8237c60611093224e081a8b481b81361daf
3
+ metadata.gz: 0d7a8abc81671eea02a2fd4f6d3b4f8a3060eca51d50c70ebb76c3b0c064b027
4
+ data.tar.gz: c423cb560f674bc848cea3fcfdd57ef21e41742bc2a86e0db74755ec0c86c8d4
5
5
  SHA512:
6
- metadata.gz: 7c184db2e3ec377f97dc944b98332cdaf78f3f01140e01a06cb5af0ba151eb6a8913e734a971582af5ab01d6a55afec75ca186d69e7fea732b2c065a2d6367f3
7
- data.tar.gz: 6c46f3220718f37804eed3284eb80757ea0922a1048fc2d179e44efc003026bdd810188f5efcfad0e243b42a675c26399bfa4c065422268f4be0774664020668
6
+ metadata.gz: 9623a90a33ba6cd9f7948e3856c3954ef822a9eb94bdd48d44126b467985071e4a27654c1d8848168586a9ead4668d6e407e656163c5b1330500eb48e04c1eec
7
+ data.tar.gz: 0f4766cda2dd7a4fe0335094e155f5731d215b25dde91d135777546839859a82377833485ef0b8459dd32a77b9cf705d3934fa14bd3d2b330273d4895d944782
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.23)
4
+ rspec-terraform (0.1.0.pre.24)
5
5
  rspec (>= 3.0)
6
6
  ruby-terraform (= 1.7.0.pre.13)
7
7
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Terraform
5
+ module Configuration
6
+ class VarCaptor
7
+ def initialize(vars)
8
+ @vars = vars
9
+ end
10
+
11
+ def method_missing(method, *args, &_)
12
+ if method.to_s =~ /.*=$/
13
+ set_var(method.to_s.chop.to_sym, args[0])
14
+ else
15
+ read_var(method)
16
+ end
17
+ end
18
+
19
+ def respond_to_missing?
20
+ true
21
+ end
22
+
23
+ def to_h
24
+ @vars
25
+ end
26
+
27
+ private
28
+
29
+ def set_var(var, value)
30
+ @vars[var] = value
31
+ end
32
+
33
+ def read_var(var)
34
+ @vars[var]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'configuration/providers'
4
4
  require_relative 'configuration/merger'
5
+ require_relative 'configuration/var_captor'
5
6
 
6
7
  module RSpec
7
8
  module Terraform
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'ruby_terraform'
4
4
 
5
+ require_relative '../configuration/var_captor'
6
+
5
7
  module RSpec
6
8
  module Terraform
7
9
  module Helpers
@@ -14,20 +16,55 @@ module RSpec
14
16
  configuration_provider || Configuration.identity_provider
15
17
  end
16
18
 
17
- def execute
18
- parameters = configuration_provider.resolve(overrides)
19
- parameters = parameters.merge(
19
+ def execute(&block)
20
+ parameters = with_configuration_provider_parameters(overrides)
21
+ parameters = with_resolved_vars(parameters, &block)
22
+ parameters = with_mandatory_parameters(parameters)
23
+
24
+ ensure_required_parameters(parameters)
25
+
26
+ init(parameters)
27
+ apply(parameters)
28
+ end
29
+
30
+ private
31
+
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(
20
46
  input: false,
21
47
  auto_approve: true
22
48
  )
49
+ end
23
50
 
24
- do_apply(parameters)
51
+ def ensure_required_parameters(parameters)
52
+ return if parameters[:configuration_directory]
53
+
54
+ throw StandardError.new(
55
+ 'No Terraform configuration directory specified.'
56
+ )
25
57
  end
26
58
 
27
- private
59
+ def init(parameters)
60
+ init_command.execute(
61
+ chdir: parameters[:configuration_directory],
62
+ input: parameters[:input]
63
+ )
64
+ end
28
65
 
29
- def do_apply(parameters)
30
- RubyTerraform.apply(
66
+ def apply(parameters)
67
+ apply_command.execute(
31
68
  chdir: parameters[:configuration_directory],
32
69
  state: parameters[:state_file],
33
70
  vars: parameters[:vars],
@@ -35,6 +72,18 @@ module RSpec
35
72
  auto_approve: parameters[:auto_approve]
36
73
  )
37
74
  end
75
+
76
+ def init_command
77
+ RubyTerraform::Commands::Init.new(
78
+ binary: RSpec.configuration.terraform_binary
79
+ )
80
+ end
81
+
82
+ def apply_command
83
+ RubyTerraform::Commands::Apply.new(
84
+ binary: RSpec.configuration.terraform_binary
85
+ )
86
+ end
38
87
  end
39
88
  end
40
89
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.23'
5
+ VERSION = '0.1.0.pre.24'
6
6
  end
7
7
  end
@@ -10,4 +10,7 @@ require_relative 'terraform/helpers'
10
10
 
11
11
  RSpec.configure do |config|
12
12
  config.include(RSpec::Terraform::Matchers)
13
+
14
+ config.add_setting(:terraform_binary, default: 'terraform')
15
+ config.add_setting(:terraform_execution_mode, default: :in_place)
13
16
  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.23
4
+ version: 0.1.0.pre.24
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-08-19 00:00:00.000000000 Z
11
+ date: 2022-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -284,6 +284,7 @@ files:
284
284
  - lib/rspec/terraform/configuration/providers.rb
285
285
  - lib/rspec/terraform/configuration/providers/identity.rb
286
286
  - lib/rspec/terraform/configuration/providers/in_memory.rb
287
+ - lib/rspec/terraform/configuration/var_captor.rb
287
288
  - lib/rspec/terraform/helpers.rb
288
289
  - lib/rspec/terraform/helpers/apply.rb
289
290
  - lib/rspec/terraform/matchers.rb