Skip to content

[#316] Add VPC flow log module as an optional module#317

Open
tung-nimblehq wants to merge 3 commits intodevelopfrom
feature/316-add-vpc-flows-log-module
Open

[#316] Add VPC flow log module as an optional module#317
tung-nimblehq wants to merge 3 commits intodevelopfrom
feature/316-add-vpc-flows-log-module

Conversation

@tung-nimblehq
Copy link
Copy Markdown
Contributor

@tung-nimblehq tung-nimblehq commented Oct 5, 2025

What happened 👀

  • Add vpc-flow-log module
  • Upgrade Terraform to the latest version.
  • Add enabledSecurityFeatures flag to make vpc-flow-log module an optional module.
  • Add some unit tests.

Insight 📝

Add a Glue table for Athena to query flow logs. Since Athena charges based on queries: https://www.amazonaws.cn/en/athena/pricing/

Proof Of Work 📹

Apply on AWS correctly

Logs

Screenshot 2025-10-05 at 14 06 56

S3 bucket

Screenshot 2025-10-05 at 14 06 56

Athena Query

Screenshot 2025-10-05 at 14 19 37

Example query:
99825aeb-13ee-4801-87c3-5c512f619a50.csv

Create VPC flow log in the Advanced template with flag set true.

Screen.Recording.2025-10-05.at.12.41.38.mov

Does not create VPC flow log in Blank template.

Screen.Recording.2025-10-05.at.12.38.54.mov

Does not create VPC flow log in the Advanced template with the flag not set.

Screen.Recording.2025-10-05.at.12.40.24.mov

@tung-nimblehq tung-nimblehq self-assigned this Oct 5, 2025
@tung-nimblehq tung-nimblehq added the type : feature New feature or request label Oct 5, 2025
@tung-nimblehq tung-nimblehq added this to the 2.4.0 milestone Oct 5, 2025
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch 2 times, most recently from debef21 to b55003b Compare October 5, 2025 07:24
@tung-nimblehq tung-nimblehq marked this pull request as ready for review October 5, 2025 07:26
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from b55003b to 73b05d7 Compare October 12, 2025 02:09
@tung-nimblehq tung-nimblehq requested a review from suho as a code owner October 12, 2025 02:09
@tung-nimblehq
Copy link
Copy Markdown
Contributor Author

@hoangmirs Can you recheck it? 🙏

@hoangmirs
Copy link
Copy Markdown
Collaborator

Could you help rebase against the develop branch again?

@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 2625247 to 220e3c5 Compare October 17, 2025 03:46
@tung-nimblehq
Copy link
Copy Markdown
Contributor Author

Could you help rebase against the develop branch again?

Rebased 🙏

@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 220e3c5 to c222713 Compare January 10, 2026 04:38
@tung-nimblehq tung-nimblehq changed the base branch from develop to feature/316-separate-s3-and-alb-module January 10, 2026 04:39
@tung-nimblehq tung-nimblehq force-pushed the feature/316-separate-s3-and-alb-module branch from 5fc06d7 to 0aa0817 Compare January 15, 2026 15:26
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from c222713 to 8f894f4 Compare January 15, 2026 15:55
@tung-nimblehq tung-nimblehq force-pushed the feature/316-separate-s3-and-alb-module branch 3 times, most recently from a7c33ad to b619cf2 Compare January 16, 2026 11:23
Base automatically changed from feature/316-separate-s3-and-alb-module to develop January 16, 2026 11:27
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 8f894f4 to 84a9710 Compare January 16, 2026 14:57
Copy link
Copy Markdown

@toby-thanathip toby-thanathip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tung-nimblehq Just wondering if VPC Flow Log is something we've used in other projects?

If not, do you think it's essential for the B2B project? 🙏

Just a concern if we plan to add VPC Flow Log, it would be an additional cost for the project. 💭

1. Run the infrastructure generator
2. Select "Complete infrastructure (VPC + ECR + RDS + S3 + FARGATE + Cloudwatch + Security groups + ALB)" when prompted for infrastructure type
3. Choose "Yes" when asked "Do you want to create (VPC Flow Logs + CloudTrail) to enhance security posture and compliance?"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant line.

expect(applyAwsEcs).toHaveBeenCalledWith(options);
});

describe('given enabledSecurityFeatures is not set', () => {
Copy link
Copy Markdown

@toby-thanathip toby-thanathip Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, I'm not entirely convinced that VPC Flow and CloudTrail are security features.

→ Should we label them as Audit or Monitoring features instead?

If yes, we should rename Security.md accordingly and other variables too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VPC Flow Logs and AWS CloudTrail are foundational components that bridge Security, Audit, and Monitoring in AWS. @toby-thanathip I used security since it includes Audit, and Monitoring.

Comment on lines +11 to +14
variable "s3_bucket_name" {
description = "The name of the S3 bucket to store the flow logs."
type = string
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need s3_key_prefix here too? Similar what we did for CloudTrail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d16418

"projection.aws_region.type" = "enum"
"projection.aws_region.values" = "${data.aws_region.current.region}"
"projection.year.type" = "integer"
"projection.year.range" = "2025,2030" # Update the range as needed
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"projection.year.range" = "2025,2030" # Update the range as needed
"projection.year.range" = "2026,2030" # Update the range as needed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, should it be a variable? 💭

Copy link
Copy Markdown
Contributor Author

@tung-nimblehq tung-nimblehq Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d16418


env_namespace = local.env_namespace
bucket_name = "\${local.env_namespace}-flow-logs-\${data.aws_caller_identity.current.account_id}"
force_destroy = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds concerning, are we sure we want to have it as true? 🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d16418

const vpcFlowLogLocalesContent = dedent`
### Begin VPC Flow Log ###
locals {
vpc_flow_log_s3_bucket_policy = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm new to Terraform, forgive me; Why don't we add this to locals.tf?

→ Or should some parts be defined inside main.tf? 💭

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be created inside core/locals.tf after we generate for the project, @toby-thanathip. According to our convention, constants should be defined in locals.tf, not in main.tf. Also, we shouldn’t move everything directly into core/locals.tf at this stage for two reasons: It would separate these values from the main module logic, which could make the flow harder to follow. Some locals may require dynamic values passed from modules, so defining them too early or too centrally could limit flexibility.

Screenshot 2026-03-05 at 16 46 48


import { AWS_TEMPLATE_PATH } from '../constants';

const vpcFlowLogLocalesContent = dedent`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const vpcFlowLogLocalesContent = dedent`
const vpcFlowLogLocalsContent = dedent`

{ key = "flow_direction", value = "string" },
{ key = "traffic_path", value = "int" },
{ key = "ecs_task_id", value = "string" },
{ key = "reject_reason", value = "string" },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think all these columns are useful to us?

→ Just thinking if we reduce the amount of columns, it would reduce the cost for storage.

Fewer columns = smaller files = lower storage cost over time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, it provides us with some useful information like reject_reason, traffic_path... we can adjust these columns at the project level. I think these columns are fine at the template level

variable "log_retention_days" {
description = "The number of days to retain the flow logs in S3."
type = number
default = 90
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think 90 days is too long for troubleshooting cases? 💭

→ "The longer the retention, the more you accumulate, the more you pay."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to 30 days in 0d16418

type: 'confirm',
name: 'enabledSecurityFeatures',
message:
'Do you want to create (VPC Flow Logs + CloudTrail) to enhance security posture and compliance?',
Copy link
Copy Markdown

@toby-thanathip toby-thanathip Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking, if it's too strict too force them together.

→ Would there be any case where we only want one (instead of both), to reduce costs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. updated in 0d16418

};

export default applyAwsVpcFlowLog;
export { vpcFlowLogModuleContent, vpcFlowLogVariablesContent };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we don't export the outputs, same as we did for Cloudtrail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we won't need any output from these modules for now. That's why I don't expose it here.

@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 795a49a to 0d16418 Compare March 6, 2026 06:29
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 0d16418 to fe38800 Compare March 6, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type : feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance security posture and ensure compliance for infrastructure

3 participants