terrascript 0.1.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/bin/terrascript +94 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3991ad65ff32b31e0139a62b895a5e97949c916
4
+ data.tar.gz: 6be3d8c282f6213e633759dd049cdaf1dc3cf9bd
5
+ SHA512:
6
+ metadata.gz: bea8b8f84eb6df29b9e37ac400384ea270eacab3ba2bb36422c65b3cd1a992e8c716e65023d0bcebc463694841956f15fa0a072cbd313ebeba44b28714f18e92
7
+ data.tar.gz: a41180e1c07afb611b70bb5e29329453d54352ec8f3ccbed8a33a248c76128f467c2bf4f83ec7d50da7265e0a4cfd8f42c8906f1a2e5032dd6d33bdf836b7da7
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *~
data/bin/terrascript ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'digest'
4
+ require 'fileutils'
5
+
6
+ class Transform
7
+ def transform
8
+ eval("lambda { |#{@argName}|\n#{@body}\n}").call(@arg)
9
+ end
10
+
11
+ def initialize(fname)
12
+ @fname = fname
13
+ @mode = :read
14
+ @argName = "block"
15
+ @arg = ""
16
+ @body = ""
17
+ end
18
+
19
+ def process
20
+ $stdout = File.new(@fname.gsub(".tfrb", ".tf"), "w")
21
+ File.open(@fname).each do |line|
22
+ processLine line
23
+ end
24
+ $stdout.close
25
+ $stdout = STDOUT
26
+ end
27
+
28
+ def processLine(line)
29
+ case @mode
30
+
31
+ when :read
32
+ if line.start_with?("@inline")
33
+ args = line.split(' ')
34
+ if !args[1].nil?
35
+ @argName = args[1]
36
+ end
37
+ @mode = :body
38
+ else
39
+ puts line
40
+ end
41
+
42
+ when :arg
43
+ if line.start_with?("@end")
44
+ @arg << "\n"
45
+ transform
46
+ @mode = :read
47
+ else
48
+ @arg << line
49
+ end
50
+
51
+ when :body
52
+ @body << line
53
+ if line.start_with?("return")
54
+ @mode = :arg
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ def processFile f
63
+ hash_dir = ".terraform/.tfrb"
64
+ FileUtils.mkdir_p(hash_dir)
65
+
66
+ fname_hash = Digest::SHA256.hexdigest f
67
+
68
+ hash_file = "#{hash_dir}/#{fname_hash}"
69
+
70
+ old_sha = ""
71
+ if File.file?(hash_file)
72
+ old_sha = File.read hash_file
73
+ end
74
+
75
+ sha = Digest::SHA256.hexdigest File.read f
76
+
77
+ if old_sha != sha
78
+ File.open(hash_file, "w") { |hash_fd| hash_fd.write sha}
79
+
80
+ File.open(f).each do |l|
81
+ Transform.new(f).process
82
+ end
83
+ puts "=> Done"
84
+ else
85
+ puts "=> Unchanged"
86
+ end
87
+ end
88
+
89
+ Dir.glob("**/*.tfrb").each do |f|
90
+ puts "Processing #{f}"
91
+ processFile(f)
92
+ end
93
+
94
+ exec("terraform", *ARGV)
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terrascript
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Chmiel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: marcin.k.chmiel@gmail.com
15
+ executables:
16
+ - terrascript
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - bin/terrascript
22
+ homepage: https://github.com/mewa/terrascript
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.6.12
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Terraform wrapper which adds Ruby scripting capabilities to your infrastructure
46
+ test_files: []