Skip to content

Commit

Permalink
Allow custom tags for instance lane and name
Browse files Browse the repository at this point in the history
  • Loading branch information
codekoala committed Aug 3, 2017
1 parent 940e646 commit 7fb8ad8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ behavior:
``$LANES_CONFIG_DIR/lanes.yml``
* ``LANES_REGION``: the AWS region to use when listing EC2 instances. Default:
``us-west-2``
* ``LANES_LANE_TAG``: the EC2 instance tag to use for determining which lane an
instance belongs to. Default: ``Lane``
* ``LANES_NAME_TAG``: the EC2 instance tag to use for determining an instance's
name. Default: ``Name``
## Usage
Expand Down
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ var (

// REGION is the default region to use for any profile that doesn't have a region explicitly set.
REGION = EnvDefault("LANES_REGION", "us-west-2")

// LANE_TAG is the name of the EC2 tag to use when determining which lane a server belongs in.
LANE_TAG = EnvDefault("LANES_LANE_TAG", "Lane")

// NAME_TAG is the name of the EC2 tag to use when determining a server's name.
NAME_TAG = EnvDefault("LANES_NAME_TAG", "Name")
)

type Config struct {
Expand Down
9 changes: 4 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/exec"
"sort"
"strings"
"time"

"github.com/apcera/termtables"
Expand Down Expand Up @@ -92,7 +91,7 @@ func FetchServersInLane(svc *ec2.EC2, lane string) ([]*Server, error) {
input = &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{{
Name: aws.String("tag-key"),
Values: []*string{aws.String("Lane")},
Values: []*string{aws.String(LANE_TAG)},
}, {
Name: aws.String("tag-value"),
Values: []*string{aws.String(lane)},
Expand Down Expand Up @@ -132,10 +131,10 @@ func FetchServersBy(svc *ec2.EC2, input *ec2.DescribeInstancesInput) (servers []
continue
}

switch strings.ToLower(*tag.Key) {
case "name":
switch *tag.Key {
case NAME_TAG:
svr.Name = *tag.Value
case "lane":
case LANE_TAG:
svr.Lane = *tag.Value
}
}
Expand Down

0 comments on commit 7fb8ad8

Please sign in to comment.