/
byoip_cidrs.go
89 lines (84 loc) · 2.75 KB
/
byoip_cidrs.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package ec2
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
func Ec2ByoipCidrs() *schema.Table {
return &schema.Table{
Name: "aws_ec2_byoip_cidrs",
Description: "Information about an address range that is provisioned for use with your AWS resources through bring your own IP addresses (BYOIP).",
Resolver: fetchEc2ByoipCidrs,
Multiplex: client.ServiceAccountRegionMultiplexer("ec2"),
IgnoreError: client.IgnoreWithInvalidAction,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "region", "cidr"}},
IgnoreInTests: true,
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "cidr",
Description: "The address range, in CIDR notation.",
Type: schema.TypeString,
},
{
Name: "description",
Description: "The description of the address range.",
Type: schema.TypeString,
},
{
Name: "state",
Description: "The state of the address pool.",
Type: schema.TypeString,
},
{
Name: "status_message",
Description: "Upon success, contains the ID of the address pool.",
Type: schema.TypeString,
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchEc2ByoipCidrs(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
config := ec2.DescribeByoipCidrsInput{
MaxResults: aws.Int32(100),
}
c := meta.(*client.Client)
// DescribeByoipCidrs does not work in next regions, so we ignore them.
if _, ok := map[string]struct{}{
"cn-north-1": {},
"cn-northwest-1": {},
}[c.Region]; ok {
return nil
}
svc := c.Services().EC2
for {
response, err := svc.DescribeByoipCidrs(ctx, &config)
if err != nil {
return diag.WrapError(err)
}
res <- response.ByoipCidrs
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}