-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
38 lines (34 loc) · 851 Bytes
/
main.go
1
2
3
4
5
6
7
8
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
34
35
36
37
38
package subnets
import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/flippedbit/chaosity/pkg/aws/options"
"github.com/flippedbit/chaosity/pkg/aws/subnetfilter"
)
func GetSubnets(svc *ec2.EC2, o options.AwsOptions) ([]*ec2.Subnet, error) {
sf := &subnetfilter.SubnetFilter{}
if s := o.GetSubnets(); len(s) > 0 {
sf = sf.BySubnet(s)
}
if a := o.GetAvailabilityZones(); len(a) > 0 {
sf = sf.ByAvailabilityZone(a)
}
if t := o.GetTags(); len(t) > 0 {
sf = sf.ByTag(t)
}
input := &ec2.DescribeSubnetsInput{
Filters: sf.Build(),
}
result, err := svc.DescribeSubnets(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
default:
return []*ec2.Subnet{}, aerr
}
} else {
return []*ec2.Subnet{}, err
}
}
return result.Subnets, nil
}