Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
get instance IPs also from terraform output
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Jul 8, 2020
1 parent 2a87f47 commit fe96082
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/bitte/cluster.cr
Expand Up @@ -21,15 +21,17 @@ module Bitte
).reservations.map(&.instances).flatten

asg.instances.map do |asgi|
i = instances.find{|instance| instance.instance_id == asgi.instance_id }
i = instances.find { |instance| instance.instance_id == asgi.instance_id }
next unless i

tags = i.tags_hash
if i && i["Cluster"]? == self.name
if i && tags["Cluster"]? == self.name
Node.new(
cluster: self,
name: asgi.instance_id,
private_ip: i.private_ip_address.not_nil!,
public_ip: i.public_ip_address,
).tap{|node| node.tags = tags }
).tap { |node| node.tags = tags }
else
raise "Can't find #{asgi.instance_id}"
end
Expand All @@ -52,6 +54,13 @@ module Bitte
def hydrate
return if hydrated

mem = IO::Memory.new
sh!("terraform", args: ["output", "-json", "instances"], output: mem)
ips = Hash(String, String).from_json(mem.to_s)
ips.each do |node_name, ip|
@nodes[node_name].public_ip = ip
end

aws_instances.each do |instance|
tags = instance.tags_hash

Expand Down

0 comments on commit fe96082

Please sign in to comment.