Update the strategy to check cluster status
[vaultmon/.git] / aws.go
CommitLineData
9bce124f
SB
1package main
2
3import (
4 "github.com/aws/aws-sdk-go/aws"
5 "github.com/aws/aws-sdk-go/aws/endpoints"
6 "github.com/aws/aws-sdk-go/aws/session"
7 "github.com/aws/aws-sdk-go/service/ec2"
8
9 log "github.com/sirupsen/logrus"
10)
11
12func GetInstancesPrivateIps(filter map[string]string) ([]string, error) {
13
14 sess := session.Must(session.NewSession(&aws.Config{
15 Region: aws.String(endpoints.EuCentral1RegionID),
16 }))
17
18 service := ec2.New(sess)
19
20 input := &ec2.DescribeInstancesInput{
21 Filters: []*ec2.Filter{
22 {
23 Name: aws.String(filter["Name"]),
24 Values: []*string{aws.String(filter["Value"])},
25 },
26 },
27 }
28
29 result, err := service.DescribeInstances(input)
30 if err != nil {
31 log.Debugf("Unable to DescribeInstances using input: %+v", result)
32 return nil, err
33 }
34
35 nodeIps := make([]string, 0, len(result.Reservations))
36
37 for _, r := range result.Reservations {
38 if len(r.Instances) > 0 {
39 nodeIps = append(nodeIps, *r.Instances[0].PrivateIpAddress)
40 }
41 }
42
43 log.Debugf("Found %d private IPs: %v", len(nodeIps), nodeIps)
44
45 return nodeIps, nil
46}