-
Notifications
You must be signed in to change notification settings - Fork 8
/
getvariables.rb
28 lines (23 loc) · 1003 Bytes
/
getvariables.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
#!/usr/bin/ruby
require 'net/https'
require 'json'
uri = URI.parse("https://raw.githubusercontent.com/powdahound/ec2instances.info/master/www/instances.json")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
res = http.request(request)
ami_types = Hash[JSON.parse(res.body).map { |tuple| [tuple['instance_type'], tuple['linux_virtualization_types']] }]
output = {
"variable" => {
"prefer_pv" => {
"description" => "If an instance type supports PV, should return 'pv', else 'hvm'",
"default" => Hash[ami_types.map { |k, v| [k, v.include?('PV') ? 'pv' : 'hvm'] }]
},
"prefer_hvm" => {
"description" => "If an instance type supports HVM, should return 'hvm', else 'pv'",
"default" => Hash[ami_types.map { |k, v| [k, v.include?('HVM') ? 'hvm' : 'pv'] }]
}
}
}
File.open('variables.tf.json.new', 'w') { |f| f.puts JSON.pretty_generate(output) }
File.rename 'variables.tf.json.new', 'variables.tf.json'