Skip to content

Commit de7d818

Browse files
committed
add full module configuration
1 parent 8e7b568 commit de7d818

File tree

9 files changed

+285
-0
lines changed

9 files changed

+285
-0
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: check-added-large-files
6+
args: ['--maxkb=500']
7+
- id: check-executables-have-shebangs
8+
- id: pretty-format-json
9+
args: ['--autofix', '--no-sort-keys', '--indent=2']
10+
- id: check-byte-order-marker
11+
- id: check-case-conflict
12+
- id: check-executables-have-shebangs
13+
- id: check-merge-conflict
14+
- id: check-symlinks
15+
- id: detect-private-key
16+
- id: check-merge-conflict
17+
- id: detect-aws-credentials
18+
args: ['--allow-missing-credentials']
19+
- id: trailing-whitespace
20+
- repo: git://github.com/antonbabenko/pre-commit-terraform
21+
rev: v1.62.3
22+
hooks:
23+
- id: terraform_fmt
24+
- id: terraform_docs
25+
- id: terraform_tflint

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: hooks validate changelog
6+
7+
help:
8+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
9+
10+
hooks: ## Commit hooks setup
11+
@pre-commit install
12+
@pre-commit gc
13+
@pre-commit autoupdate
14+
15+
validate: ## Validate files with pre-commit hooks
16+
@pre-commit run --all-files
17+
18+
changelog:
19+
git-chglog -o CHANGELOG.md

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,96 @@
1+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/native-cube/terraform-aws-vpc-flow-logs)](https://github.com/native-cube/terraform-aws-vpc-flow-logs/releases/latest)
2+
13
# terraform-aws-vpc-flow-logs
24
Terraform module for enabling AWS VPC flow logs.
5+
6+
## Usage
7+
8+
```hcl
9+
module "vpc-flow-logs" {
10+
source = "native-cube/vpc-flow-logs/aws"
11+
version = "~> 1.0.0"
12+
13+
name_prefix = "native-cube-example"
14+
vpc_id = "vpc-123456789"
15+
16+
traffic_type = "ALL"
17+
18+
tags = {
19+
Project = "native-cube"
20+
}
21+
}
22+
```
23+
24+
## Examples
25+
26+
* [VPC flow logs](https://github.com/native-cube/terraform-aws-vpc-flow-logs/tree/master/examples/core)
27+
28+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
29+
## Requirements
30+
31+
| Name | Version |
32+
|------|---------|
33+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
34+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
35+
36+
## Providers
37+
38+
| Name | Version |
39+
|------|---------|
40+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0 |
41+
42+
## Modules
43+
44+
No modules.
45+
46+
## Resources
47+
48+
| Name | Type |
49+
|------|------|
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 |
53+
| [aws_iam_policy_document.cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
54+
55+
## Inputs
56+
57+
| Name | Description | Type | Default | Required |
58+
|------|-------------|------|---------|:--------:|
59+
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data. Please note, after the AWS KMS CMK is disassociated from the log group, AWS CloudWatch Logs stops encrypting newly ingested data for the log group. All previously ingested data remains encrypted, and AWS CloudWatch Logs requires permissions for the CMK whenever the encrypted data is requested. | `string` | `null` | no |
60+
| <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 |
61+
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | A prefix used for naming resources. | `string` | n/a | yes |
62+
| <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_tags"></a> [tags](#input\_tags) | Default tags attached to all resources. | `map(string)` | `{}` | no |
64+
| <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+
67+
## Outputs
68+
69+
| Name | Description |
70+
|------|-------------|
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. |
75+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
76+
77+
## License
78+
79+
See LICENSE file for full details.
80+
81+
## Pre-commit hooks
82+
83+
### Install dependencies
84+
85+
* [`pre-commit`](https://pre-commit.com/#install)
86+
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
87+
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
88+
89+
#### MacOS
90+
91+
```bash
92+
brew install pre-commit terraform-docs tflint
93+
94+
brew tap git-chglog/git-chglog
95+
brew install git-chglog
96+
```

data.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
data "aws_iam_policy_document" "cloudwatch" {
2+
statement {
3+
actions = [
4+
"logs:CreateLogGroup",
5+
"logs:CreateLogStream",
6+
"logs:PutLogEvents",
7+
"logs:DescribeLogGroups",
8+
"logs:DescribeLogStreams"
9+
]
10+
11+
resources = ["*"]
12+
}
13+
}

examples/core/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
module "flow-logs" {
6+
source = "../../"
7+
8+
name_prefix = "native-cube-example"
9+
vpc_id = "vpc-123456789"
10+
11+
traffic_type = "ALL"
12+
# retention_in_days = 30
13+
# max_aggregation_interval = 60
14+
15+
tags = {
16+
Environment = "test"
17+
Project = "native-cube"
18+
}
19+
}

main.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
resource "aws_cloudwatch_log_group" "vpc" {
2+
name = "${var.name_prefix}-vpc-flow-logs"
3+
4+
retention_in_days = var.retention_in_days
5+
kms_key_id = var.kms_key_id
6+
7+
tags = var.tags
8+
}
9+
10+
resource "aws_iam_role" "vpc" {
11+
name = "${var.name_prefix}-vpc-flow-logs"
12+
13+
assume_role_policy = jsonencode(
14+
{
15+
"Version" : "2012-10-17",
16+
"Statement" : [
17+
{
18+
"Effect" : "Allow",
19+
"Principal" : {
20+
"Service" : "vpc-flow-logs.amazonaws.com"
21+
},
22+
"Action" : "sts:AssumeRole"
23+
}
24+
]
25+
}
26+
)
27+
28+
inline_policy {
29+
name = "cloudwatch-policy"
30+
policy = data.aws_iam_policy_document.cloudwatch.json
31+
}
32+
33+
tags = var.tags
34+
}
35+
36+
resource "aws_flow_log" "vpc" {
37+
log_destination_type = "cloud-watch-logs"
38+
log_destination = aws_cloudwatch_log_group.vpc.arn
39+
40+
iam_role_arn = aws_iam_role.vpc.arn
41+
vpc_id = var.vpc_id
42+
traffic_type = var.traffic_type
43+
44+
max_aggregation_interval = var.max_aggregation_interval
45+
46+
tags = var.tags
47+
}

outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "vpc_flow_logs_id" {
2+
value = aws_flow_log.vpc.id
3+
description = "The Flow Log ID."
4+
}
5+
6+
output "vpc_flow_logs_role_arn" {
7+
value = aws_iam_role.vpc.arn
8+
description = "The ARN specifying the role used by Flow Logs."
9+
}
10+
11+
output "vpc_flow_logs_role_id" {
12+
value = aws_iam_role.vpc.id
13+
description = "The ID specifying the role used by Flow Logs."
14+
}
15+
16+
output "vpc_flow_logs_cloudwatch_group_arn" {
17+
value = aws_cloudwatch_log_group.vpc.arn
18+
description = "The ARN specifying the log group used by Flow Logs."
19+
}

variables.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "name_prefix" {
2+
description = "A prefix used for naming resources."
3+
type = string
4+
}
5+
6+
variable "vpc_id" {
7+
type = string
8+
description = "VPC ID where resources will be created and flow logs enabled."
9+
}
10+
11+
variable "tags" {
12+
type = map(string)
13+
description = "Default tags attached to all resources."
14+
default = {}
15+
}
16+
17+
variable "retention_in_days" {
18+
type = string
19+
description = "Specifies the number of days you want to retain log events in the specified log group."
20+
default = null
21+
}
22+
23+
variable "kms_key_id" {
24+
type = string
25+
description = "The ARN of the KMS Key to use when encrypting log data. Please note, after the AWS KMS CMK is disassociated from the log group, AWS CloudWatch Logs stops encrypting newly ingested data for the log group. All previously ingested data remains encrypted, and AWS CloudWatch Logs requires permissions for the CMK whenever the encrypted data is requested."
26+
default = null
27+
}
28+
29+
variable "traffic_type" {
30+
type = string
31+
description = "The type of traffic to capture. Valid values: ACCEPT, REJECT, ALL."
32+
default = "ALL"
33+
}
34+
35+
variable "max_aggregation_interval" {
36+
type = string
37+
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)"
38+
default = "600"
39+
}

versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 3.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)