Skip to content

Commit c27daad

Browse files
authored
add support for additional flow log sources (#1)
1 parent 890722a commit c27daad

File tree

6 files changed

+70
-33
lines changed

6 files changed

+70
-33
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0
3+
rev: v4.4.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']
@@ -17,8 +17,8 @@ repos:
1717
- id: detect-aws-credentials
1818
args: ['--allow-missing-credentials']
1919
- id: trailing-whitespace
20-
- repo: git://github.com/antonbabenko/pre-commit-terraform
21-
rev: v1.62.3
20+
- repo: https://github.com/antonbabenko/pre-commit-terraform
21+
rev: v1.76.0
2222
hooks:
2323
- id: terraform_fmt
2424
- id: terraform_docs

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ No modules.
4747

4848
| Name | Type |
4949
|------|------|
50-
| [aws_cloudwatch_log_group.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
51-
| [aws_flow_log.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/flow_log) | resource |
52-
| [aws_iam_role.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
50+
| [aws_cloudwatch_log_group.flow_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
51+
| [aws_flow_log.flow_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/flow_log) | resource |
52+
| [aws_iam_role.flow_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
5353
| [aws_iam_policy_document.cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
5454

5555
## Inputs
@@ -60,18 +60,21 @@ No modules.
6060
| <a name="input_max_aggregation_interval"></a> [max\_aggregation\_interval](#input\_max\_aggregation\_interval) | 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) | `string` | `"600"` | no |
6161
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | A prefix used for naming resources. | `string` | n/a | yes |
6262
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. | `string` | `null` | no |
63+
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | Subnet ID to attach to. | `string` | `null` | no |
6364
| <a name="input_tags"></a> [tags](#input\_tags) | Default tags attached to all resources. | `map(string)` | `{}` | no |
6465
| <a name="input_traffic_type"></a> [traffic\_type](#input\_traffic\_type) | The type of traffic to capture. Valid values: ACCEPT, REJECT, ALL. | `string` | `"ALL"` | no |
65-
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID where resources will be created and flow logs enabled. | `string` | n/a | yes |
66+
| <a name="input_transit_gateway_attachment_id"></a> [transit\_gateway\_attachment\_id](#input\_transit\_gateway\_attachment\_id) | Transit Gateway Attachment ID to attach to. | `string` | `null` | no |
67+
| <a name="input_transit_gateway_id"></a> [transit\_gateway\_id](#input\_transit\_gateway\_id) | Transit Gateway ID to attach to. | `string` | `null` | no |
68+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID where resources will be created and flow logs enabled. | `string` | `null` | no |
6669

6770
## Outputs
6871

6972
| Name | Description |
7073
|------|-------------|
71-
| <a name="output_vpc_flow_logs_cloudwatch_group_arn"></a> [vpc\_flow\_logs\_cloudwatch\_group\_arn](#output\_vpc\_flow\_logs\_cloudwatch\_group\_arn) | The ARN specifying the log group used by Flow Logs. |
72-
| <a name="output_vpc_flow_logs_id"></a> [vpc\_flow\_logs\_id](#output\_vpc\_flow\_logs\_id) | The Flow Log ID. |
73-
| <a name="output_vpc_flow_logs_role_arn"></a> [vpc\_flow\_logs\_role\_arn](#output\_vpc\_flow\_logs\_role\_arn) | The ARN specifying the role used by Flow Logs. |
74-
| <a name="output_vpc_flow_logs_role_id"></a> [vpc\_flow\_logs\_role\_id](#output\_vpc\_flow\_logs\_role\_id) | The ID specifying the role used by Flow Logs. |
74+
| <a name="output_flow_logs_cloudwatch_group_arn"></a> [flow\_logs\_cloudwatch\_group\_arn](#output\_flow\_logs\_cloudwatch\_group\_arn) | The ARN specifying the log group used by Flow Logs. |
75+
| <a name="output_flow_logs_id"></a> [flow\_logs\_id](#output\_flow\_logs\_id) | The Flow Log ID. |
76+
| <a name="output_flow_logs_role_arn"></a> [flow\_logs\_role\_arn](#output\_flow\_logs\_role\_arn) | The ARN specifying the role used by Flow Logs. |
77+
| <a name="output_flow_logs_role_id"></a> [flow\_logs\_role\_id](#output\_flow\_logs\_role\_id) | The ID specifying the role used by Flow Logs. |
7578
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7679

7780
## License

examples/core/main.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
provider "aws" {
2-
region = "eu-west-1"
2+
region = "eu-west-2"
3+
}
4+
5+
terraform {
6+
required_version = ">= 1.3"
7+
8+
required_providers {
9+
aws = {
10+
source = "hashicorp/aws"
11+
version = ">= 4.41"
12+
}
13+
}
314
}
415

516
module "flow-logs" {

main.tf

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
resource "aws_cloudwatch_log_group" "vpc" {
2-
name = "${var.name_prefix}-vpc-flow-logs"
1+
resource "aws_cloudwatch_log_group" "flow_logs" {
2+
name = "${var.name_prefix}-flow-logs"
33

44
retention_in_days = var.retention_in_days
55
kms_key_id = var.kms_key_id
66

77
tags = var.tags
88
}
99

10-
resource "aws_iam_role" "vpc" {
11-
name = "${var.name_prefix}-vpc-flow-logs"
10+
resource "aws_iam_role" "flow_logs" {
11+
name = "${var.name_prefix}-flow-logs"
1212

1313
assume_role_policy = jsonencode(
1414
{
@@ -33,14 +33,18 @@ resource "aws_iam_role" "vpc" {
3333
tags = var.tags
3434
}
3535

36-
resource "aws_flow_log" "vpc" {
36+
resource "aws_flow_log" "flow_logs" {
3737
log_destination_type = "cloud-watch-logs"
38-
log_destination = aws_cloudwatch_log_group.vpc.arn
38+
log_destination = aws_cloudwatch_log_group.flow_logs.arn
3939

40-
iam_role_arn = aws_iam_role.vpc.arn
41-
vpc_id = var.vpc_id
40+
iam_role_arn = aws_iam_role.flow_logs.arn
4241
traffic_type = var.traffic_type
4342

43+
vpc_id = var.vpc_id
44+
subnet_id = var.subnet_id
45+
transit_gateway_id = var.transit_gateway_id
46+
transit_gateway_attachment_id = var.transit_gateway_attachment_id
47+
4448
max_aggregation_interval = var.max_aggregation_interval
4549

4650
tags = var.tags

outputs.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
output "vpc_flow_logs_id" {
2-
value = aws_flow_log.vpc.id
1+
output "flow_logs_id" {
2+
value = aws_flow_log.flow_logs.id
33
description = "The Flow Log ID."
44
}
55

6-
output "vpc_flow_logs_role_arn" {
7-
value = aws_iam_role.vpc.arn
6+
output "flow_logs_role_arn" {
7+
value = aws_iam_role.flow_logs.arn
88
description = "The ARN specifying the role used by Flow Logs."
99
}
1010

11-
output "vpc_flow_logs_role_id" {
12-
value = aws_iam_role.vpc.id
11+
output "flow_logs_role_id" {
12+
value = aws_iam_role.flow_logs.id
1313
description = "The ID specifying the role used by Flow Logs."
1414
}
1515

16-
output "vpc_flow_logs_cloudwatch_group_arn" {
17-
value = aws_cloudwatch_log_group.vpc.arn
16+
output "flow_logs_cloudwatch_group_arn" {
17+
value = aws_cloudwatch_log_group.flow_logs.arn
1818
description = "The ARN specifying the log group used by Flow Logs."
1919
}

variables.tf

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ variable "name_prefix" {
33
type = string
44
}
55

6-
variable "vpc_id" {
7-
type = string
8-
description = "VPC ID where resources will be created and flow logs enabled."
9-
}
10-
116
variable "tags" {
127
type = map(string)
138
description = "Default tags attached to all resources."
@@ -37,3 +32,27 @@ variable "max_aggregation_interval" {
3732
description = "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)"
3833
default = "600"
3934
}
35+
36+
variable "vpc_id" {
37+
type = string
38+
description = "VPC ID where resources will be created and flow logs enabled."
39+
default = null
40+
}
41+
42+
variable "subnet_id" {
43+
type = string
44+
description = "Subnet ID to attach to."
45+
default = null
46+
}
47+
48+
variable "transit_gateway_id" {
49+
type = string
50+
description = "Transit Gateway ID to attach to."
51+
default = null
52+
}
53+
54+
variable "transit_gateway_attachment_id" {
55+
type = string
56+
description = "Transit Gateway Attachment ID to attach to."
57+
default = null
58+
}

0 commit comments

Comments
 (0)