/
table_aws_codedeploy_deployment_group.go
389 lines (350 loc) · 13.1 KB
/
table_aws_codedeploy_deployment_group.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package aws
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codedeploy"
"github.com/aws/aws-sdk-go-v2/service/codedeploy/types"
codedeployv1 "github.com/aws/aws-sdk-go/service/codedeploy"
"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 tableAwsCodeDeployDeploymentGroup(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_codedeploy_deployment_group",
Description: "AWS CodeDeploy Deployment Group",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"deployment_group_name", "application_name"}),
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ApplicationDoesNotExistException", "DeploymentGroupDoesNotExistException"}),
},
Hydrate: getCodeDeployDeploymentGroup,
Tags: map[string]string{"service": "codedeploy", "action": "GetDeploymentGroup"},
},
List: &plugin.ListConfig{
KeyColumns: plugin.OptionalColumns([]string{"application_name"}),
ParentHydrate: listCodeDeployApplications,
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ApplicationDoesNotExistException"}),
},
Hydrate: listCodeDeployDeploymentGroups,
Tags: map[string]string{"service": "codedeploy", "action": "ListDeploymentGroups"},
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: getCodeDeployDeploymentGroupTags,
Tags: map[string]string{"service": "codedeploy", "action": "ListTagsForResource"},
},
{
Func: getCodeDeployDeploymentGroup,
Tags: map[string]string{"service": "codedeploy", "action": "GetDeploymentGroup"},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(codedeployv1.EndpointsID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) specifying the application.",
Type: proto.ColumnType_STRING,
Hydrate: getCodeDeployDeploymentGroupArn,
Transform: transform.FromValue(),
},
{
Name: "application_name",
Description: "The application name.",
Type: proto.ColumnType_STRING,
},
{
Name: "deployment_config_name",
Description: "The deployment configuration name.",
Type: proto.ColumnType_STRING,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "deployment_group_id",
Description: "The deployment group ID.",
Type: proto.ColumnType_STRING,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "deployment_group_name",
Description: "The deployment group name.",
Type: proto.ColumnType_STRING,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "service_role_arn",
Description: "A service role Amazon Resource Name (ARN) that grants CodeDeploy permission to make calls to Amazon Web Services services on your behalf.",
Type: proto.ColumnType_STRING,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "alarm_configuration",
Description: "A list of alarms associated with the deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "auto_rollback_configuration",
Description: "Information about the automatic rollback configuration associated with the deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "auto_scaling_groups",
Description: "A list of associated Auto Scaling groups.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "blue_green_deployment_configuration",
Description: "Information about blue/green deployment options for a deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "compute_platform",
Description: "The destination platform type for the deployment (Lambda, Server, or ECS).",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "deployment_style",
Description: "Information about the type of deployment, either in-place or blue/green, you want to run and whether to route deployment traffic behind a load balancer.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "ec2_tag_filters",
Description: "The Amazon EC2 tags on which to filter. The deployment group includes EC2 instances with any of the specified tags.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "ec2_tag_set",
Description: "Information about groups of tags applied to an Amazon EC2 instance.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "ecs_services",
Description: "The target Amazon ECS services in the deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "last_attempted_deployment",
Description: "Information about the most recent attempted deployment to the deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "last_successful_deployment",
Description: "Information about the most recent successful deployment to the deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "load_balancer_info",
Description: "Information about the load balancer to use in a deployment.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "on_premises_instance_tag_filters",
Description: "The on-premises instance tags on which to filter.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "on_premises_tag_set",
Description: "Information about groups of tags applied to an on-premises instance.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "outdated_instances_strategy",
Description: "Indicates what happens when new Amazon EC2 instances are launched mid-deployment and do not receive the deployed application revision.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "tags_src",
Description: "A list of tags associated with deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroupTags,
Transform: transform.FromField("Tags"),
},
{
Name: "target_revision",
Description: "Information about the deployment group's target revision, including type and location.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
{
Name: "trigger_configurations",
Description: "Information about triggers associated with the deployment group.",
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroup,
},
// Steampipe standard columns
{
Name: "title",
Description: resourceInterfaceDescription("title"),
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeploymentGroupName"),
},
{
Name: "tags",
Description: resourceInterfaceDescription("tags"),
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroupTags,
Transform: transform.From(codeDeployDeploymentGroupTurbotTags),
},
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Hydrate: getCodeDeployDeploymentGroupArn,
Transform: transform.FromValue().Transform(transform.EnsureStringArray),
},
}),
}
}
//// LIST FUNCTION
func listCodeDeployDeploymentGroups(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
application := h.Item.(*types.ApplicationInfo)
// Create session
svc, err := CodeDeployClient(ctx, d)
if err != nil {
logger.Error("aws_codedeploy_deployment_group.listCodeDeployDeploymentGroups", "client_error", err)
return nil, err
}
if svc == nil {
// Unsupported region, return no data
return nil, nil
}
applicationName := d.EqualsQuals["application_name"].GetStringValue()
input := codedeploy.ListDeploymentGroupsInput{
ApplicationName: aws.String(*application.ApplicationName),
}
// Check if the application name is nil or if it doesn't match the parent hydrate
if applicationName != "" && applicationName != *application.ApplicationName {
return nil, nil
}
paginator := codedeploy.NewListDeploymentGroupsPaginator(svc, &input, func(o *codedeploy.ListDeploymentGroupsPaginatorOptions) {
o.StopOnDuplicateToken = true
})
for paginator.HasMorePages() {
// apply rate limiting
d.WaitForListRateLimit(ctx)
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_codedeploy_deployment_group.listCodeDeployDeploymentGroups", "api_error", err)
return nil, err
}
for _, deploymentgroup := range output.DeploymentGroups {
item := &types.DeploymentGroupInfo{
DeploymentGroupName: aws.String(deploymentgroup),
ApplicationName: output.ApplicationName,
}
d.StreamListItem(ctx, item)
// Context may get cancelled due to manual cancellation or if the limit has been reached
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
return nil, nil
}
//// HYDRATE FUNCTIONS
func getCodeDeployDeploymentGroup(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
var name string
var appname string
if h.Item != nil {
name = *h.Item.(*types.DeploymentGroupInfo).DeploymentGroupName
appname = *h.Item.(*types.DeploymentGroupInfo).ApplicationName
} else {
name = d.EqualsQuals["deployment_group_name"].GetStringValue()
appname = d.EqualsQuals["application_name"].GetStringValue()
}
// Check if the required quals are empty
if name == "" || appname == "" {
return nil, nil
}
// Build the params
params := &codedeploy.GetDeploymentGroupInput{
DeploymentGroupName: aws.String(name),
ApplicationName: aws.String(appname),
}
// Create session
svc, err := CodeDeployClient(ctx, d)
if err != nil {
logger.Error("aws_codedeploy_deployment_group.getCodeDeployDeploymentGroup", "client_error", err)
return nil, err
}
if svc == nil {
// Unsupported region, return no data
return nil, nil
}
// Get call
data, err := svc.GetDeploymentGroup(ctx, params)
if err != nil {
logger.Error("aws_codedeploy_deployment_group.getCodeDeployDeploymentGroup", "api_error", err)
return nil, err
}
return data.DeploymentGroupInfo, nil
}
func getCodeDeployDeploymentGroupTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
// Build the params
params := &codedeploy.ListTagsForResourceInput{
ResourceArn: aws.String(CodeDeployDeploymentGroupArn(ctx, d, h)),
}
// Create session
svc, err := CodeDeployClient(ctx, d)
if err != nil {
logger.Error("aws_codedeploy_deployment_group.getCodeDeployDeploymentGroupTags", "client_error", err)
return nil, err
}
// Get call
data, err := svc.ListTagsForResource(ctx, params)
if err != nil {
logger.Error("aws_codedeploy_deployment_group.getCodeDeployDeploymentGroupTags", "api_error", err)
return nil, err
}
return data, nil
}
func getCodeDeployDeploymentGroupArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
return CodeDeployDeploymentGroupArn(ctx, d, h), nil
}
func CodeDeployDeploymentGroupArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) string {
name := *h.Item.(*types.DeploymentGroupInfo).DeploymentGroupName
appname := *h.Item.(*types.DeploymentGroupInfo).ApplicationName
region := d.EqualsQualString(matrixKeyRegion)
logger := plugin.Logger(ctx)
commonData, err := getCommonColumns(ctx, d, h)
if err != nil {
logger.Error("aws_codedeploy_deployment_group.CodeDeployDeploymentGroupArn", "caching_error", err)
return ""
}
commonColumnData := commonData.(*awsCommonColumnData)
//arn:aws:codedeploy:region:account-id:deploymentgroup:application-name/deployment-group-name
tableArn := "arn:" + commonColumnData.Partition + ":codedeploy:" + region + ":" + commonColumnData.AccountId + ":deploymentgroup:" + appname + "/" + name
return tableArn
}
func codeDeployDeploymentGroupTurbotTags(ctx context.Context, d *transform.TransformData) (interface{}, error) {
tags := d.HydrateItem.(*codedeploy.ListTagsForResourceOutput)
// Mapping the resource tags inside turbotTags
var turbotTagsMap map[string]string
if tags.Tags != nil {
turbotTagsMap = map[string]string{}
for _, i := range tags.Tags {
turbotTagsMap[*i.Key] = *i.Value
}
}
return turbotTagsMap, nil
}