Module: AwsPublicIps::Checks::Elasticsearch

Defined in:
lib/aws_public_ips/checks/elasticsearch.rb

Class Method Summary collapse

Class Method Details

.runObject



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
# File 'lib/aws_public_ips/checks/elasticsearch.rb', line 9

def self.run
  client = ::Aws::ElasticsearchService::Client.new
  return [] unless ::AwsPublicIps::Utils.has_service?(client)

  # ElasticSearch instances can be launched into classic into VPCs. Classic instances are public and have a
  # `domain_status.endpoint` hostname, and VPC instances have a `domain_status.endpoints['vpc']` hostname.
  # However VPC ElasticSearch instances create their own Network Interface and AWS will not allow you
  # to associate an Elastic IP to it. As a result VPC ElasticSearch instances are always private, even with an
  # internet gateway.

  client.list_domain_names.flat_map do |response|
    response.domain_names.flat_map do |domain_name|
      client.describe_elasticsearch_domain(domain_name: domain_name.domain_name).map do |domain|
        hostname = domain.domain_status.endpoint
        next unless hostname

        {
          id: domain.domain_status.domain_id,
          hostname: hostname,
          ip_addresses: ::AwsPublicIps::Utils.resolve_hostname(hostname)
        }
      end.compact
    end
  end
end