This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
/
nat_gateways.go
187 lines (183 loc) · 6.1 KB
/
nat_gateways.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package ec2
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
func Ec2NatGateways() *schema.Table {
return &schema.Table{
Name: "aws_ec2_nat_gateways",
Description: "Describes a NAT gateway.",
Resolver: fetchEc2NatGateways,
Multiplex: client.ServiceAccountRegionMultiplexer("ec2"),
IgnoreError: client.IgnoreCommonErrors,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "id"}},
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: "arn",
Description: "The Amazon Resource Name (ARN) for the resource.",
Type: schema.TypeString,
Resolver: client.ResolveARN(client.EC2Service, func(resource *schema.Resource) ([]string, error) {
return []string{"natgateway", *resource.Item.(types.NatGateway).NatGatewayId}, nil
}),
},
{
Name: "id",
Description: "The ID of the NAT gateway.",
Type: schema.TypeString,
Resolver: schema.PathResolver("NatGatewayId"),
},
{
Name: "create_time",
Description: "The date and time the NAT gateway was created.",
Type: schema.TypeTimestamp,
},
{
Name: "delete_time",
Description: "The date and time the NAT gateway was deleted, if applicable.",
Type: schema.TypeTimestamp,
IgnoreInTests: true,
},
{
Name: "failure_code",
Description: "If the NAT gateway could not be created, specifies the error code for the failure.",
Type: schema.TypeString,
IgnoreInTests: true,
},
{
Name: "failure_message",
Description: "If the NAT gateway could not be created, specifies the error message for the failure, that corresponds to the error code.",
Type: schema.TypeString,
IgnoreInTests: true,
},
{
Name: "provisioned_bandwidth_provision_time",
Description: "Reserved.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("ProvisionedBandwidth.ProvisionTime"),
IgnoreInTests: true,
},
{
Name: "provisioned_bandwidth_provisioned",
Description: "Reserved.",
Type: schema.TypeString,
Resolver: schema.PathResolver("ProvisionedBandwidth.Provisioned"),
IgnoreInTests: true,
},
{
Name: "provisioned_bandwidth_request_time",
Description: "Reserved.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("ProvisionedBandwidth.RequestTime"),
IgnoreInTests: true,
},
{
Name: "provisioned_bandwidth_requested",
Description: "Reserved.",
Type: schema.TypeString,
Resolver: schema.PathResolver("ProvisionedBandwidth.Requested"),
IgnoreInTests: true,
},
{
Name: "provisioned_bandwidth_status",
Description: "Reserved.",
Type: schema.TypeString,
Resolver: schema.PathResolver("ProvisionedBandwidth.Status"),
IgnoreInTests: true,
},
{
Name: "state",
Description: "The state of the NAT gateway.",
Type: schema.TypeString,
},
{
Name: "subnet_id",
Description: "The ID of the subnet in which the NAT gateway is located.",
Type: schema.TypeString,
},
{
Name: "tags",
Description: "The tags for the NAT gateway.",
Type: schema.TypeJSON,
Resolver: client.ResolveTags,
},
{
Name: "vpc_id",
Description: "The ID of the VPC in which the NAT gateway is located.",
Type: schema.TypeString,
},
},
Relations: []*schema.Table{
{
Name: "aws_ec2_nat_gateway_addresses",
Description: "Describes the IP addresses and network interface associated with a NAT gateway.",
Resolver: schema.PathTableResolver("NatGatewayAddresses"),
Columns: []schema.Column{
{
Name: "nat_gateway_cq_id",
Description: "Unique CloudQuery ID of aws_ec2_nat_gateways table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "allocation_id",
Description: "The allocation ID of the Elastic IP address that's associated with the NAT gateway.",
Type: schema.TypeString,
},
{
Name: "network_interface_id",
Description: "The ID of the network interface associated with the NAT gateway.",
Type: schema.TypeString,
},
{
Name: "private_ip",
Description: "The private IP address associated with the Elastic IP address.",
Type: schema.TypeString,
},
{
Name: "public_ip",
Description: "The Elastic IP address associated with the NAT gateway.",
Type: schema.TypeString,
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchEc2NatGateways(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
var config ec2.DescribeNatGatewaysInput
c := meta.(*client.Client)
svc := c.Services().EC2
for {
output, err := svc.DescribeNatGateways(ctx, &config)
if err != nil {
return diag.WrapError(err)
}
res <- output.NatGateways
if aws.ToString(output.NextToken) == "" {
break
}
config.NextToken = output.NextToken
}
return nil
}