-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmodule.rb
executable file
·60 lines (50 loc) · 1.5 KB
/
module.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
require "net/http"
require 'digest'
module ModuleUtils
def parse_link(name, source)
source_raw = source.match(/"(.*)"/).captures()[0]
if source_raw.start_with?"./"
link = source_raw
else
modules = JSON.parse(File.read("./.terraform/modules/modules.json"))
modules["Modules"].each do |m|
if m["Source"] == source_raw
link = "#{m["Dir"]}/#{m["Root"]}"
end
end
end
return link
end
def load_arg_module(name, source, path)
link = parse_link(name, source)
variables = ''
result = []
['main.tf', 'config.tf', 'inputs.tf', 'variables.tf', 'vars.tf'].each do |i|
if File.exist? "#{path}/#{link}/#{i}"
puts "#{path}/#{link}/#{i}"
variables = open("#{path}/#{link}/#{i}").read.split("\n").select { |x| x[/^variable/]}
variables.each do |x|
result.push({ "word": x.match(/variable\s*"?([A-Za-z0-9_-]*)"?\s*{/).captures()[0] })
end
end
end
return JSON.generate(result)
end
def load_attr_module(name,source, path)
link = parse_link(name, source)
variables = ''
result = []
['main.tf', 'outputs.tf'].each do |i|
if File.exist?"#{path}/#{link}/#{i}"
variables = open("#{path}/#{link}/#{i}").read.split("\n").select { |x| x[/^output/]}
variables.each do |x|
result.push({ "word": x.match(/output\s*"?([A-Za-z0-9_-]*)"?\s*{/).captures()[0] })
end
end
end
return JSON.generate(result)
end
end