-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparse-state.rb
45 lines (36 loc) · 1.07 KB
/
parse-state.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
require 'json'
def format_hostname(hostname)
return hostname unless hostname.include?('compliance-workstation')
hostname = hostname.split('-')
hostname.delete('compliance')
hostname.delete('workstation')
hostname.delete('of')
suit = hostname.pop
suit_char = case suit
when "hearts"
"♥︎"
when "spades"
"♠︎"
when "diamonds"
"⬥"
when "clubs"
"♣︎"
else
suit
end
hostname << suit_char
hostname.join(' ')
end
file = ARGV[0];
raise "no file given -- Usage: #{__FILE__} tfstate_file" if file.nil?
raise "File not readable" unless File.readable?(file)
data = JSON.parse(File.read(file))
puts "| Workstation | IP Address |"
puts "| ----------- | ---------- |"
data['modules'].each do |m|
m['resources'].each do |res_name, res_data|
attrs = res_data['primary']['attributes']
next if attrs['public_ip'].nil?
puts "| #{format_hostname(attrs['tags.Name'])} | #{attrs['public_ip']} |"
end
end