Skip to content

Commit

Permalink
Find ASGs by DescribeTags first since DescribeAutoScalingGroups is pa…
Browse files Browse the repository at this point in the history
…ginated
  • Loading branch information
jwineinger committed Nov 18, 2016
1 parent f652c5e commit ff08b8a
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/autoscaling"
)

// data structure that stores information about a region
Expand Down Expand Up @@ -66,6 +67,8 @@ func (r *region) processRegion(cfg Config) {

logger.Println("Processing enabled AutoScaling groups in", r.name)
r.processEnabledAutoScalingGroups()
} else {
logger.Println(r.name, "has no enabled AutoScaling groups")
}
}

Expand Down Expand Up @@ -166,11 +169,45 @@ func (r *region) requestSpotPrices() error {
return nil
}

func (r *region) scanForEnabledAutoScalingGroupsByTag(asgs *[]*string) {
svc := r.services.autoScaling

input := autoscaling.DescribeTagsInput{
Filters: []*autoscaling.Filter{
{Name: aws.String("key"), Values: []*string{aws.String("spot-enabled")}},
{Name: aws.String("value"), Values: []*string{aws.String("true")}},
},
}
resp, err := svc.DescribeTags(&input)

if err != nil {
logger.Println("Failed to describe AutoScaling tags in",
r.name,
err.Error())
return
}

for _, tag := range resp.Tags {
logger.Println("Found enabled ASG:", *tag.ResourceId)
*asgs = append(*asgs, tag.ResourceId)
}
}

func (r *region) scanForEnabledAutoScalingGroups() {
filterTagName, filterValue := "spot-enabled", "true"
asgs := []*string{}

r.scanForEnabledAutoScalingGroupsByTag(&asgs)

if len(asgs) == 0 {
return
}

svc := r.services.autoScaling
resp, err := svc.DescribeAutoScalingGroups(nil)

input := autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: asgs,
}
resp, err := svc.DescribeAutoScalingGroups(&input)

if err != nil {
logger.Println("Failed to describe AutoScaling groups in",
Expand All @@ -180,16 +217,12 @@ func (r *region) scanForEnabledAutoScalingGroups() {
}

for _, asg := range resp.AutoScalingGroups {
for _, tag := range asg.Tags {
if *tag.Key == filterTagName && *tag.Value == filterValue {
group := autoScalingGroup{
name: *asg.AutoScalingGroupName,
region: r,
asgRawData: asg,
}
r.enabledASGs = append(r.enabledASGs, group)
}
group := autoScalingGroup{
name: *asg.AutoScalingGroupName,
region: r,
asgRawData: asg,
}
r.enabledASGs = append(r.enabledASGs, group)
}
}

Expand Down

0 comments on commit ff08b8a

Please sign in to comment.