Skip to content

Commit

Permalink
config: set default region for EC2 SD
Browse files Browse the repository at this point in the history
  • Loading branch information
mtanda committed Jun 1, 2017
1 parent 287ec6e commit a1ddab4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"
"time"

"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -1126,7 +1128,13 @@ func (c *EC2SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}
if c.Region == "" {
return fmt.Errorf("EC2 SD configuration requires a region")
sess := session.Must(session.NewSession())
metadata := ec2metadata.New(sess)
region, err := metadata.Region()
if err != nil {
return fmt.Errorf("EC2 SD configuration requires a region")
}
c.Region = region
}
return nil
}
Expand Down

0 comments on commit a1ddab4

Please sign in to comment.