terraform-synthesizer 0.0.14 → 0.0.16
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/lib/terraform-synthesizer/version.rb +1 -1
- data/lib/terraform-synthesizer.rb +42 -30
- data/spec/terraform_spec.rb +19 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e742e74bfa241477d03973992c8791cf8ffe68930b58b4eed82598c084a4e57
|
4
|
+
data.tar.gz: d26630d09fc22a704a3935403c83f71e7e420921a329bcd8a623e599ffc8c57b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6cf1088cada6405cc839674f0e0a29e6d917359a3e022a79ca65f049e47633d843d3dba6e297b3e66864bdd2827fec3a5a8d1756cb7c906ff629f97bdf0900f
|
7
|
+
data.tar.gz: 58c0632dbce69a7cd498b6fc49ab305997bf750ab02defe56aee9fd65d690da81ee441025251591cc0fa09a364507959bfdcaff108e083becd682578689f87b7
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require %(abstract-synthesizer)
|
2
2
|
|
3
3
|
class TerraformSynthesizer < AbstractSynthesizer
|
4
|
-
|
4
|
+
RESOURCE_KEYS = %i[
|
5
5
|
terraform
|
6
6
|
resource
|
7
7
|
variable
|
@@ -9,38 +9,50 @@ class TerraformSynthesizer < AbstractSynthesizer
|
|
9
9
|
data
|
10
10
|
].freeze
|
11
11
|
|
12
|
+
# if there are additional block keys
|
13
|
+
# add them here and they should be processed
|
14
|
+
# accordingly
|
15
|
+
BLOCK_KEYS = %i[locals].freeze
|
16
|
+
|
17
|
+
##############################################################################
|
18
|
+
# notes:
|
19
|
+
#
|
20
|
+
# locals are processed as a direct block like
|
21
|
+
# locals do
|
22
|
+
# key value
|
23
|
+
# end
|
24
|
+
# while resources are processed as resource like blocks
|
25
|
+
# resource :aws_vpc, :virtual_name do
|
26
|
+
# key value
|
27
|
+
# end
|
28
|
+
##############################################################################
|
12
29
|
def method_missing(method_name, *args, &)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
30
|
+
BLOCK_KEYS.each do |block_key|
|
31
|
+
if @in_block_key
|
32
|
+
raise ArgumentError, %(not assigning anything to this #{block_key}) if args[0].nil?
|
33
|
+
|
34
|
+
@in_block_key = false
|
35
|
+
@translation[:template][block_key.to_sym][method_name.to_sym] = args[0]
|
20
36
|
|
21
|
-
|
22
|
-
@translation[:template][:locals].merge!(
|
23
|
-
{ method_name.to_sym => args[0] }
|
24
|
-
)
|
25
|
-
elsif method_name.to_s.eql?(%(locals))
|
26
|
-
puts %(caught local execution start)
|
37
|
+
elsif method_name.to_s.eql?(block_key.to_s)
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
@translation = {} if @translation.nil?
|
40
|
+
@translation[:template] = {} if @translation[:template].nil?
|
41
|
+
if @translation[:template][block_key.to_sym].nil?
|
42
|
+
@translation[:template][block_key.to_sym] =
|
43
|
+
{}
|
44
|
+
end
|
45
|
+
@in_block_key = true
|
46
|
+
|
47
|
+
yield
|
48
|
+
else
|
49
|
+
abstract_method_missing(
|
50
|
+
method_name.to_sym,
|
51
|
+
RESOURCE_KEYS,
|
52
|
+
*args,
|
53
|
+
&
|
54
|
+
)
|
55
|
+
end
|
44
56
|
end
|
45
57
|
end
|
46
58
|
end
|
data/spec/terraform_spec.rb
CHANGED
@@ -36,10 +36,13 @@ describe TerraformSynthesizer do
|
|
36
36
|
expect(synth.synthesis[:locals][:special_var]).to be_kind_of(String)
|
37
37
|
end
|
38
38
|
|
39
|
-
it %(should contain
|
39
|
+
it %(should contain resource thing) do
|
40
40
|
synth.synthesize do
|
41
41
|
resource :aws_vpc, :thing do
|
42
42
|
cidr_block %(10.0.0.0/16)
|
43
|
+
stuff do
|
44
|
+
other_stuff %(whoa)
|
45
|
+
end
|
43
46
|
end
|
44
47
|
locals do
|
45
48
|
special_var %(special_value)
|
@@ -50,5 +53,20 @@ describe TerraformSynthesizer do
|
|
50
53
|
end
|
51
54
|
expect(synth.synthesis[:resource][:aws_vpc][:thing]).to be_kind_of(Hash)
|
52
55
|
end
|
56
|
+
|
57
|
+
it %(should contain resource thang) do
|
58
|
+
synth.synthesize do
|
59
|
+
resource :aws_vpc, :thing do
|
60
|
+
cidr_block %(10.0.0.0/16)
|
61
|
+
end
|
62
|
+
locals do
|
63
|
+
special_var %(special_value)
|
64
|
+
end
|
65
|
+
resource :aws_vpc, :thang do
|
66
|
+
cidr_block %(10.0.0.0/16)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
expect(synth.synthesis[:resource][:aws_vpc][:thang]).to be_kind_of(Hash)
|
70
|
+
end
|
53
71
|
end
|
54
72
|
end
|