/
table_aws_rds_db_engine_version.go
362 lines (333 loc) · 12.3 KB
/
table_aws_rds_db_engine_version.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package aws
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/types"
rdsv1 "github.com/aws/aws-sdk-go/service/rds"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
//// TABLE DEFINITION
func tableAwsRDSDBEngineVersion(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_rds_db_engine_version",
Description: "AWS RDS DB Engine Version",
List: &plugin.ListConfig{
Hydrate: listRDSDBEngineVersions,
Tags: map[string]string{"service": "rds", "action": "DescribeDBEngineVersions"},
KeyColumns: plugin.KeyColumnSlice{
{Name: "engine", Require: plugin.Optional},
{Name: "engine_version", Require: plugin.Optional},
{Name: "db_parameter_group_family", Require: plugin.Optional},
{Name: "list_supported_character_sets", Require: plugin.Optional},
{Name: "list_supported_timezones", Require: plugin.Optional},
{Name: "default_only", Require: plugin.Optional},
{Name: "engine_mode", Require: plugin.Optional},
{Name: "status", Require: plugin.Optional},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(rdsv1.EndpointsID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "engine",
Description: "The name of the database engine.",
Type: proto.ColumnType_STRING,
},
{
Name: "engine_version",
Description: "The version number of the database engine.",
Type: proto.ColumnType_STRING,
},
{
Name: "arn",
Description: "The ARN of the custom engine version.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DBEngineVersionArn"),
},
{
Name: "status",
Description: "The status of the DB engine version, either available or deprecated.",
Type: proto.ColumnType_STRING,
},
{
Name: "create_time",
Description: "The creation time of the DB engine version.",
Type: proto.ColumnType_TIMESTAMP,
},
{
Name: "custom_db_engine_version_manifest",
Description: "JSON string that lists the installation files and parameters that RDS Custom uses to create a custom engine version (CEV).",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("CustomDBEngineVersionManifest"),
},
{
Name: "list_supported_character_sets",
Description: "A value that indicates whether to list the supported character sets for each engine version.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromQual("list_supported_character_sets"),
Default: false,
},
{
Name: "engine_mode",
Description: "Accepts DB engine modes.",
Type: proto.ColumnType_STRING,
Transform: transform.FromQual("engine_mode"),
},
{
Name: "list_supported_timezones",
Description: "A value that indicates whether to list the supported time zones for each engine version.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromQual("list_supported_timezones"),
Default: false,
},
{
Name: "default_only",
Description: "A value that indicates whether only the default version of the specified engine or engine and major version combination is returned.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromQual("list_supported_timezones"),
Default: false,
},
{
Name: "db_engine_description",
Description: "The description of the database engine.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DBEngineDescription"),
},
{
Name: "db_engine_media_type",
Description: "A value that indicates the source media provider of the AMI based on the usage operation. Applicable for RDS Custom for SQL Server.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DBEngineMediaType"),
},
{
Name: "db_engine_version_description",
Description: "The description of the database engine version.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DBEngineVersionDescription"),
},
{
Name: "db_parameter_group_family",
Description: "The name of the DB parameter group family for the database engine.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DBParameterGroupFamily"),
},
{
Name: "database_installation_files_s3_bucket_name",
Description: "The name of the Amazon S3 bucket that contains your database installation files.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DatabaseInstallationFilesS3BucketName"),
},
{
Name: "database_installation_files_s3_prefix",
Description: "The Amazon S3 directory that contains the database installation files. If not specified, then no prefix is assumed.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DatabaseInstallationFilesS3Prefix"),
},
{
Name: "kms_key_id",
Description: "The Amazon Web Services KMS key identifier for an encrypted CEV. This parameter is required for RDS Custom, but optional for Amazon RDS.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("KMSKeyId"),
},
{
Name: "major_engine_version",
Description: "The major engine version of the CEV.",
Type: proto.ColumnType_STRING,
},
{
Name: "supports_babelfish",
Description: "A value that indicates whether the engine version supports Babelfish for Aurora PostgreSQL.",
Type: proto.ColumnType_BOOL,
},
{
Name: "supports_certificate_rotation_without_restart",
Description: "A value that indicates whether the engine version supports rotating the server certificate without rebooting the DB instance.",
Type: proto.ColumnType_BOOL,
},
{
Name: "supports_global_databases",
Description: "A value that indicates whether you can use Aurora global databases with a specific DB engine version.",
Type: proto.ColumnType_BOOL,
},
{
Name: "supports_log_exports_to_cloudwatch_logs",
Description: "A value that indicates whether the engine version supports exporting the log types specified by ExportableLogTypes to CloudWatch Logs.",
Type: proto.ColumnType_BOOL,
},
{
Name: "supports_parallel_query",
Description: "A value that indicates whether you can use Aurora parallel query with a specific DB engine version.",
Type: proto.ColumnType_BOOL,
},
{
Name: "supports_read_replica",
Description: "Indicates whether the database engine version supports read replicas.",
Type: proto.ColumnType_BOOL,
},
{
Name: "exportable_log_types",
Description: "The types of logs that the database engine has available for export to CloudWatch Logs.",
Type: proto.ColumnType_JSON,
},
{
Name: "image",
Description: "The EC2 image.",
Type: proto.ColumnType_JSON,
},
{
Name: "supported_feature_names",
Description: "A list of features supported by the DB engine.",
Type: proto.ColumnType_JSON,
},
{
Name: "supported_nchar_character_sets",
Description: "A list of the character sets supported by the Oracle DB engine for the NcharCharacterSetName parameter of the CreateDBInstance operation.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SupportedNcharCharacterSets"),
},
{
Name: "supported_timezones",
Description: "A list of the time zones supported by this engine for the Timezone parameter of the CreateDBInstance action.",
Type: proto.ColumnType_JSON,
},
{
Name: "valid_upgrade_target",
Description: "A list of engine versions that this database engine version can be upgraded to.",
Type: proto.ColumnType_JSON,
},
{
Name: "tag_list",
Description: "A list of tags.",
Type: proto.ColumnType_JSON,
},
// Steampipe standard columns
{
Name: "title",
Description: resourceInterfaceDescription("title"),
Type: proto.ColumnType_STRING,
Transform: transform.FromField("EngineVersion"),
},
{
Name: "tags",
Description: resourceInterfaceDescription("tags"),
Type: proto.ColumnType_JSON,
Transform: transform.FromField("TagList").Transform(getRDSDBEngineVersionTurbotTags),
},
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Transform: transform.FromField("DBEngineVersionArn").Transform(getRDSDBEngineVersionAka),
},
}),
}
}
//// LIST FUNCTION
func listRDSDBEngineVersions(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
// Create Session
svc, err := RDSClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_rds_db_engine_version.listRDSDBEngineVersions", "connection_error", err)
return nil, err
}
// Limiting the results
maxLimit := int32(100)
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxLimit {
if limit < 20 {
maxLimit = 20
} else {
maxLimit = limit
}
}
}
input := &rds.DescribeDBEngineVersionsInput{
MaxRecords: aws.Int32(maxLimit),
}
if d.EqualsQualString("db_parameter_group_family") != "" {
input.DBParameterGroupFamily = aws.String(d.EqualsQualString("db_parameter_group_family"))
}
if d.EqualsQualString("engine") != "" {
input.Engine = aws.String(d.EqualsQualString("engine"))
}
if d.EqualsQualString("engine_version") != "" {
input.EngineVersion = aws.String(d.EqualsQualString("engine_version"))
}
if d.EqualsQuals["list_supported_character_sets"] != nil {
input.ListSupportedCharacterSets = aws.Bool(d.EqualsQuals["list_supported_character_sets"].GetBoolValue())
}
if d.EqualsQuals["list_supported_timezones"] != nil {
input.ListSupportedTimezones = aws.Bool(d.EqualsQuals["list_supported_timezones"].GetBoolValue())
}
if d.EqualsQuals["default_only"] != nil {
input.DefaultOnly = aws.Bool(d.EqualsQuals["default_only"].GetBoolValue())
}
// Additional input filter
filters := buildEngineVersionInputFilter(d.EqualsQuals)
if len(filters) > 0 {
input.Filters = filters
}
paginator := rds.NewDescribeDBEngineVersionsPaginator(svc, input, func(o *rds.DescribeDBEngineVersionsPaginatorOptions) {
o.Limit = maxLimit
o.StopOnDuplicateToken = true
})
// List call
for paginator.HasMorePages() {
// apply rate limiting
d.WaitForListRateLimit(ctx)
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_rds_db_engine_version.listRDSDBEngineVersions", "api_error", err)
return nil, err
}
for _, item := range output.DBEngineVersions {
d.StreamListItem(ctx, item)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
return nil, err
}
//// TRANSFORM FUNCTIONS
func getRDSDBEngineVersionTurbotTags(_ context.Context, d *transform.TransformData) (interface{}, error) {
engineVersion := d.HydrateItem.(types.DBEngineVersion)
if engineVersion.TagList != nil {
turbotTagsMap := map[string]string{}
for _, i := range engineVersion.TagList {
turbotTagsMap[*i.Key] = *i.Value
}
return turbotTagsMap, nil
}
return nil, nil
}
func getRDSDBEngineVersionAka(ctx context.Context, d *transform.TransformData) (interface{}, error) {
engineVersion := d.HydrateItem.(types.DBEngineVersion)
if engineVersion.DBEngineVersionArn == nil {
return []string{}, nil
} else {
return transform.EnsureStringArray(ctx, d)
}
}
//// UTILITY FUNCTION
func buildEngineVersionInputFilter(equalQuals plugin.KeyColumnEqualsQualMap) []types.Filter {
filters := []types.Filter{}
filterQuals := map[string]string{
"status": "status",
"engine_mode": "engine-mode",
}
for qual, filterKey := range filterQuals {
if equalQuals[qual] != nil {
filter := types.Filter{}
filter.Name = aws.String(filterKey)
value := equalQuals[qual].GetStringValue()
filter.Values = []string{value}
filters = append(filters, filter)
}
}
return filters
}