-
Notifications
You must be signed in to change notification settings - Fork 151
/
flowLog.go
485 lines (425 loc) · 16.8 KB
/
flowLog.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package ec2
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Provides a VPC/Subnet/ENI Flow Log to capture IP traffic for a specific network
// interface, subnet, or VPC. Logs are sent to a CloudWatch Log Group or a S3 Bucket.
//
// ## Example Usage
// ### CloudWatch Logging
//
// ```go
// package main
//
// import (
// "fmt"
//
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cloudwatch"
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/iam"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// exampleLogGroup, err := cloudwatch.NewLogGroup(ctx, "exampleLogGroup", nil)
// if err != nil {
// return err
// }
// exampleRole, err := iam.NewRole(ctx, "exampleRole", &iam.RoleArgs{
// AssumeRolePolicy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Sid\": \"\",\n", " \"Effect\": \"Allow\",\n", " \"Principal\": {\n", " \"Service\": \"vpc-flow-logs.amazonaws.com\"\n", " },\n", " \"Action\": \"sts:AssumeRole\"\n", " }\n", " ]\n", "}\n")),
// })
// if err != nil {
// return err
// }
// _, err = ec2.NewFlowLog(ctx, "exampleFlowLog", &ec2.FlowLogArgs{
// IamRoleArn: exampleRole.Arn,
// LogDestination: exampleLogGroup.Arn,
// TrafficType: pulumi.String("ALL"),
// VpcId: pulumi.Any(aws_vpc.Example.Id),
// })
// if err != nil {
// return err
// }
// _, err = iam.NewRolePolicy(ctx, "exampleRolePolicy", &iam.RolePolicyArgs{
// Role: exampleRole.ID(),
// Policy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Action\": [\n", " \"logs:CreateLogGroup\",\n", " \"logs:CreateLogStream\",\n", " \"logs:PutLogEvents\",\n", " \"logs:DescribeLogGroups\",\n", " \"logs:DescribeLogStreams\"\n", " ],\n", " \"Effect\": \"Allow\",\n", " \"Resource\": \"*\"\n", " }\n", " ]\n", "}\n")),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
// ### S3 Logging
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/s3"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// exampleBucket, err := s3.NewBucket(ctx, "exampleBucket", nil)
// if err != nil {
// return err
// }
// _, err = ec2.NewFlowLog(ctx, "exampleFlowLog", &ec2.FlowLogArgs{
// LogDestination: exampleBucket.Arn,
// LogDestinationType: pulumi.String("s3"),
// TrafficType: pulumi.String("ALL"),
// VpcId: pulumi.Any(aws_vpc.Example.Id),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// Flow Logs can be imported using the `id`, e.g.
//
// ```sh
// $ pulumi import aws:ec2/flowLog:FlowLog test_flow_log fl-1a2b3c4d
// ```
type FlowLog struct {
pulumi.CustomResourceState
// The ARN of the Flow Log.
Arn pulumi.StringOutput `pulumi:"arn"`
// Elastic Network Interface ID to attach to
EniId pulumi.StringPtrOutput `pulumi:"eniId"`
// The ARN for the IAM role that's used to post flow logs to a CloudWatch Logs log group
IamRoleArn pulumi.StringPtrOutput `pulumi:"iamRoleArn"`
// The ARN of the logging destination.
LogDestination pulumi.StringOutput `pulumi:"logDestination"`
// The type of the logging destination. Valid values: `cloud-watch-logs`, `s3`. Default: `cloud-watch-logs`.
LogDestinationType pulumi.StringPtrOutput `pulumi:"logDestinationType"`
// The fields to include in the flow log record, in the order in which they should appear.
LogFormat pulumi.StringOutput `pulumi:"logFormat"`
// *Deprecated:* Use `logDestination` instead. The name of the CloudWatch log group.
//
// Deprecated: use 'log_destination' argument instead
LogGroupName pulumi.StringOutput `pulumi:"logGroupName"`
// The maximum interval of time
// during which a flow of packets is captured and aggregated into a flow
// log record. Valid Values: `60` seconds (1 minute) or `600` seconds (10
// minutes). Default: `600`.
MaxAggregationInterval pulumi.IntPtrOutput `pulumi:"maxAggregationInterval"`
// Subnet ID to attach to
SubnetId pulumi.StringPtrOutput `pulumi:"subnetId"`
// Key-value map of resource tags
Tags pulumi.StringMapOutput `pulumi:"tags"`
// The type of traffic to capture. Valid values: `ACCEPT`,`REJECT`, `ALL`.
TrafficType pulumi.StringOutput `pulumi:"trafficType"`
// VPC ID to attach to
VpcId pulumi.StringPtrOutput `pulumi:"vpcId"`
}
// NewFlowLog registers a new resource with the given unique name, arguments, and options.
func NewFlowLog(ctx *pulumi.Context,
name string, args *FlowLogArgs, opts ...pulumi.ResourceOption) (*FlowLog, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.TrafficType == nil {
return nil, errors.New("invalid value for required argument 'TrafficType'")
}
var resource FlowLog
err := ctx.RegisterResource("aws:ec2/flowLog:FlowLog", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetFlowLog gets an existing FlowLog resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetFlowLog(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *FlowLogState, opts ...pulumi.ResourceOption) (*FlowLog, error) {
var resource FlowLog
err := ctx.ReadResource("aws:ec2/flowLog:FlowLog", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering FlowLog resources.
type flowLogState struct {
// The ARN of the Flow Log.
Arn *string `pulumi:"arn"`
// Elastic Network Interface ID to attach to
EniId *string `pulumi:"eniId"`
// The ARN for the IAM role that's used to post flow logs to a CloudWatch Logs log group
IamRoleArn *string `pulumi:"iamRoleArn"`
// The ARN of the logging destination.
LogDestination *string `pulumi:"logDestination"`
// The type of the logging destination. Valid values: `cloud-watch-logs`, `s3`. Default: `cloud-watch-logs`.
LogDestinationType *string `pulumi:"logDestinationType"`
// The fields to include in the flow log record, in the order in which they should appear.
LogFormat *string `pulumi:"logFormat"`
// *Deprecated:* Use `logDestination` instead. The name of the CloudWatch log group.
//
// Deprecated: use 'log_destination' argument instead
LogGroupName *string `pulumi:"logGroupName"`
// The maximum interval of time
// during which a flow of packets is captured and aggregated into a flow
// log record. Valid Values: `60` seconds (1 minute) or `600` seconds (10
// minutes). Default: `600`.
MaxAggregationInterval *int `pulumi:"maxAggregationInterval"`
// Subnet ID to attach to
SubnetId *string `pulumi:"subnetId"`
// Key-value map of resource tags
Tags map[string]string `pulumi:"tags"`
// The type of traffic to capture. Valid values: `ACCEPT`,`REJECT`, `ALL`.
TrafficType *string `pulumi:"trafficType"`
// VPC ID to attach to
VpcId *string `pulumi:"vpcId"`
}
type FlowLogState struct {
// The ARN of the Flow Log.
Arn pulumi.StringPtrInput
// Elastic Network Interface ID to attach to
EniId pulumi.StringPtrInput
// The ARN for the IAM role that's used to post flow logs to a CloudWatch Logs log group
IamRoleArn pulumi.StringPtrInput
// The ARN of the logging destination.
LogDestination pulumi.StringPtrInput
// The type of the logging destination. Valid values: `cloud-watch-logs`, `s3`. Default: `cloud-watch-logs`.
LogDestinationType pulumi.StringPtrInput
// The fields to include in the flow log record, in the order in which they should appear.
LogFormat pulumi.StringPtrInput
// *Deprecated:* Use `logDestination` instead. The name of the CloudWatch log group.
//
// Deprecated: use 'log_destination' argument instead
LogGroupName pulumi.StringPtrInput
// The maximum interval of time
// during which a flow of packets is captured and aggregated into a flow
// log record. Valid Values: `60` seconds (1 minute) or `600` seconds (10
// minutes). Default: `600`.
MaxAggregationInterval pulumi.IntPtrInput
// Subnet ID to attach to
SubnetId pulumi.StringPtrInput
// Key-value map of resource tags
Tags pulumi.StringMapInput
// The type of traffic to capture. Valid values: `ACCEPT`,`REJECT`, `ALL`.
TrafficType pulumi.StringPtrInput
// VPC ID to attach to
VpcId pulumi.StringPtrInput
}
func (FlowLogState) ElementType() reflect.Type {
return reflect.TypeOf((*flowLogState)(nil)).Elem()
}
type flowLogArgs struct {
// Elastic Network Interface ID to attach to
EniId *string `pulumi:"eniId"`
// The ARN for the IAM role that's used to post flow logs to a CloudWatch Logs log group
IamRoleArn *string `pulumi:"iamRoleArn"`
// The ARN of the logging destination.
LogDestination *string `pulumi:"logDestination"`
// The type of the logging destination. Valid values: `cloud-watch-logs`, `s3`. Default: `cloud-watch-logs`.
LogDestinationType *string `pulumi:"logDestinationType"`
// The fields to include in the flow log record, in the order in which they should appear.
LogFormat *string `pulumi:"logFormat"`
// *Deprecated:* Use `logDestination` instead. The name of the CloudWatch log group.
//
// Deprecated: use 'log_destination' argument instead
LogGroupName *string `pulumi:"logGroupName"`
// The maximum interval of time
// during which a flow of packets is captured and aggregated into a flow
// log record. Valid Values: `60` seconds (1 minute) or `600` seconds (10
// minutes). Default: `600`.
MaxAggregationInterval *int `pulumi:"maxAggregationInterval"`
// Subnet ID to attach to
SubnetId *string `pulumi:"subnetId"`
// Key-value map of resource tags
Tags map[string]string `pulumi:"tags"`
// The type of traffic to capture. Valid values: `ACCEPT`,`REJECT`, `ALL`.
TrafficType string `pulumi:"trafficType"`
// VPC ID to attach to
VpcId *string `pulumi:"vpcId"`
}
// The set of arguments for constructing a FlowLog resource.
type FlowLogArgs struct {
// Elastic Network Interface ID to attach to
EniId pulumi.StringPtrInput
// The ARN for the IAM role that's used to post flow logs to a CloudWatch Logs log group
IamRoleArn pulumi.StringPtrInput
// The ARN of the logging destination.
LogDestination pulumi.StringPtrInput
// The type of the logging destination. Valid values: `cloud-watch-logs`, `s3`. Default: `cloud-watch-logs`.
LogDestinationType pulumi.StringPtrInput
// The fields to include in the flow log record, in the order in which they should appear.
LogFormat pulumi.StringPtrInput
// *Deprecated:* Use `logDestination` instead. The name of the CloudWatch log group.
//
// Deprecated: use 'log_destination' argument instead
LogGroupName pulumi.StringPtrInput
// The maximum interval of time
// during which a flow of packets is captured and aggregated into a flow
// log record. Valid Values: `60` seconds (1 minute) or `600` seconds (10
// minutes). Default: `600`.
MaxAggregationInterval pulumi.IntPtrInput
// Subnet ID to attach to
SubnetId pulumi.StringPtrInput
// Key-value map of resource tags
Tags pulumi.StringMapInput
// The type of traffic to capture. Valid values: `ACCEPT`,`REJECT`, `ALL`.
TrafficType pulumi.StringInput
// VPC ID to attach to
VpcId pulumi.StringPtrInput
}
func (FlowLogArgs) ElementType() reflect.Type {
return reflect.TypeOf((*flowLogArgs)(nil)).Elem()
}
type FlowLogInput interface {
pulumi.Input
ToFlowLogOutput() FlowLogOutput
ToFlowLogOutputWithContext(ctx context.Context) FlowLogOutput
}
func (*FlowLog) ElementType() reflect.Type {
return reflect.TypeOf((*FlowLog)(nil))
}
func (i *FlowLog) ToFlowLogOutput() FlowLogOutput {
return i.ToFlowLogOutputWithContext(context.Background())
}
func (i *FlowLog) ToFlowLogOutputWithContext(ctx context.Context) FlowLogOutput {
return pulumi.ToOutputWithContext(ctx, i).(FlowLogOutput)
}
func (i *FlowLog) ToFlowLogPtrOutput() FlowLogPtrOutput {
return i.ToFlowLogPtrOutputWithContext(context.Background())
}
func (i *FlowLog) ToFlowLogPtrOutputWithContext(ctx context.Context) FlowLogPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(FlowLogPtrOutput)
}
type FlowLogPtrInput interface {
pulumi.Input
ToFlowLogPtrOutput() FlowLogPtrOutput
ToFlowLogPtrOutputWithContext(ctx context.Context) FlowLogPtrOutput
}
type flowLogPtrType FlowLogArgs
func (*flowLogPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**FlowLog)(nil))
}
func (i *flowLogPtrType) ToFlowLogPtrOutput() FlowLogPtrOutput {
return i.ToFlowLogPtrOutputWithContext(context.Background())
}
func (i *flowLogPtrType) ToFlowLogPtrOutputWithContext(ctx context.Context) FlowLogPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(FlowLogPtrOutput)
}
// FlowLogArrayInput is an input type that accepts FlowLogArray and FlowLogArrayOutput values.
// You can construct a concrete instance of `FlowLogArrayInput` via:
//
// FlowLogArray{ FlowLogArgs{...} }
type FlowLogArrayInput interface {
pulumi.Input
ToFlowLogArrayOutput() FlowLogArrayOutput
ToFlowLogArrayOutputWithContext(context.Context) FlowLogArrayOutput
}
type FlowLogArray []FlowLogInput
func (FlowLogArray) ElementType() reflect.Type {
return reflect.TypeOf(([]*FlowLog)(nil))
}
func (i FlowLogArray) ToFlowLogArrayOutput() FlowLogArrayOutput {
return i.ToFlowLogArrayOutputWithContext(context.Background())
}
func (i FlowLogArray) ToFlowLogArrayOutputWithContext(ctx context.Context) FlowLogArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(FlowLogArrayOutput)
}
// FlowLogMapInput is an input type that accepts FlowLogMap and FlowLogMapOutput values.
// You can construct a concrete instance of `FlowLogMapInput` via:
//
// FlowLogMap{ "key": FlowLogArgs{...} }
type FlowLogMapInput interface {
pulumi.Input
ToFlowLogMapOutput() FlowLogMapOutput
ToFlowLogMapOutputWithContext(context.Context) FlowLogMapOutput
}
type FlowLogMap map[string]FlowLogInput
func (FlowLogMap) ElementType() reflect.Type {
return reflect.TypeOf((map[string]*FlowLog)(nil))
}
func (i FlowLogMap) ToFlowLogMapOutput() FlowLogMapOutput {
return i.ToFlowLogMapOutputWithContext(context.Background())
}
func (i FlowLogMap) ToFlowLogMapOutputWithContext(ctx context.Context) FlowLogMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(FlowLogMapOutput)
}
type FlowLogOutput struct {
*pulumi.OutputState
}
func (FlowLogOutput) ElementType() reflect.Type {
return reflect.TypeOf((*FlowLog)(nil))
}
func (o FlowLogOutput) ToFlowLogOutput() FlowLogOutput {
return o
}
func (o FlowLogOutput) ToFlowLogOutputWithContext(ctx context.Context) FlowLogOutput {
return o
}
func (o FlowLogOutput) ToFlowLogPtrOutput() FlowLogPtrOutput {
return o.ToFlowLogPtrOutputWithContext(context.Background())
}
func (o FlowLogOutput) ToFlowLogPtrOutputWithContext(ctx context.Context) FlowLogPtrOutput {
return o.ApplyT(func(v FlowLog) *FlowLog {
return &v
}).(FlowLogPtrOutput)
}
type FlowLogPtrOutput struct {
*pulumi.OutputState
}
func (FlowLogPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**FlowLog)(nil))
}
func (o FlowLogPtrOutput) ToFlowLogPtrOutput() FlowLogPtrOutput {
return o
}
func (o FlowLogPtrOutput) ToFlowLogPtrOutputWithContext(ctx context.Context) FlowLogPtrOutput {
return o
}
type FlowLogArrayOutput struct{ *pulumi.OutputState }
func (FlowLogArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]FlowLog)(nil))
}
func (o FlowLogArrayOutput) ToFlowLogArrayOutput() FlowLogArrayOutput {
return o
}
func (o FlowLogArrayOutput) ToFlowLogArrayOutputWithContext(ctx context.Context) FlowLogArrayOutput {
return o
}
func (o FlowLogArrayOutput) Index(i pulumi.IntInput) FlowLogOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) FlowLog {
return vs[0].([]FlowLog)[vs[1].(int)]
}).(FlowLogOutput)
}
type FlowLogMapOutput struct{ *pulumi.OutputState }
func (FlowLogMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]FlowLog)(nil))
}
func (o FlowLogMapOutput) ToFlowLogMapOutput() FlowLogMapOutput {
return o
}
func (o FlowLogMapOutput) ToFlowLogMapOutputWithContext(ctx context.Context) FlowLogMapOutput {
return o
}
func (o FlowLogMapOutput) MapIndex(k pulumi.StringInput) FlowLogOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) FlowLog {
return vs[0].(map[string]FlowLog)[vs[1].(string)]
}).(FlowLogOutput)
}
func init() {
pulumi.RegisterOutputType(FlowLogOutput{})
pulumi.RegisterOutputType(FlowLogPtrOutput{})
pulumi.RegisterOutputType(FlowLogArrayOutput{})
pulumi.RegisterOutputType(FlowLogMapOutput{})
}