/
dms_replicationsubnetgroup.go
executable file
·51 lines (44 loc) · 1.49 KB
/
dms_replicationsubnetgroup.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
39
40
41
42
43
44
45
46
47
48
49
50
51
package lister
import (
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/trek10inc/awsets/context"
"github.com/trek10inc/awsets/resource"
)
type AWSDMSReplicationSubnetGroup struct {
}
func init() {
i := AWSDMSReplicationSubnetGroup{}
listers = append(listers, i)
}
func (l AWSDMSReplicationSubnetGroup) Types() []resource.ResourceType {
return []resource.ResourceType{resource.DMSReplicationSubnetGroup}
}
func (l AWSDMSReplicationSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) {
svc := databasemigrationservice.NewFromConfig(ctx.AWSCfg)
rg := resource.NewGroup()
err := Paginator(func(nt *string) (*string, error) {
res, err := svc.DescribeReplicationSubnetGroups(ctx.Context, &databasemigrationservice.DescribeReplicationSubnetGroupsInput{
MaxRecords: aws.Int32(100),
Marker: nt,
})
if err != nil {
if strings.Contains(err.Error(), "exceeded maximum number of attempts") {
// If DMS is not supported in a region, it triggers this error
return nil, nil
}
return nil, err
}
for _, v := range res.ReplicationSubnetGroups {
r := resource.New(ctx, resource.DMSReplicationSubnetGroup, v.ReplicationSubnetGroupIdentifier, v.ReplicationSubnetGroupIdentifier, v)
r.AddRelation(resource.Ec2Vpc, v.VpcId, "")
for _, sn := range v.Subnets {
r.AddRelation(resource.Ec2Subnet, sn.SubnetIdentifier, "")
}
rg.AddResource(r)
}
return res.Marker, nil
})
return rg, err
}