# tnx-journey-to-cloud/terraform-aws-networkfirewall architecture

> Architecture diagram of the GitHub repository tnx-journey-to-cloud/terraform-aws-networkfirewall, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tnx-journey-to-cloud/terraform-aws-networkfirewall
- Repository: https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall

## Overview

##### Project type and purpose
- This repository is an Infrastructure‑as‑Code (IaC) Terraform module designed to provision and configure AWS Network Firewall resources (firewall, rule groups, logging, endpoints) within a VPC.
- It includes:
- Core module code: main.tf, variables.tf, outputs.tf, providers.tf, data.tf, locals.tf
- End‑to‑end (e2e) test configurations in the `e2e/` folder
- Unit tests in the `unittest/` folder
- CI/CD pipeline definitions in `.github/workflows/`

##### File structure
- Top‑level IaC files (main.tf, variables.tf, outputs.tf, providers.tf) define the module’s input/outputs and AWS provider config.
- `data.tf` fetches external AWS data (e.g., AMIs, VPC info).
- `locals.tf` computes derived values (e.g., `app_env_prefix`).
- `e2e/` folder: Terraform configs and rule files used to validate the module end‑to‑end.
- `unittest/` folder: Go‑based Terraform unit tests.
- `.github/workflows/`: CI/CD jobs for static analysis (Checkov), documentation generation, notifications, releases.

##### README for additional insights
- The README outlines required inputs (VPC id, subnets, rule group definitions) and outputs (firewall ARN, endpoint ID).
- It lists AWS resources created: AWS Network Firewall, rule groups (stateless, stateful domain, Suricata, 5‑tuple), CloudWatch Log Group.

##### Elements
- Clear labels:
- “Developer / CI Pipeline”
- “Terraform Module: AWS Network Firewall”
- “AWS API (Provider)”
- “AWS VPC” + “Subnets”
- “Network Firewall Policy” & sub‑components (Rule Groups)
- “CloudWatch Log Group”
- “E2E Test Harness”
- “Unit Test Harness”
- From Developer/CI → Terraform Module (init/plan/apply)
- From Terraform Module → AWS API → respective AWS resources
- From Module → CloudWatch for logging
- From Test Harness → Terraform Module

##### Detailed component breakdown
- Local dev machine or GitHub Actions
- Steps: checkout code → `terraform init` → `terraform plan` → `terraform apply`
- CI jobs: checkov scan, docs-gen, release
- Files: main.tf (resources), variables.tf (inputs), outputs.tf (outputs), data.tf, locals.tf
- Provides abstraction over AWS Network Firewall resources
- VPC → Subnet A & Subnet B
- Network Firewall: Firewall resource with endpoint in each subnet
- Firewall Policy → Rule Groups (stateless, stateful domain, Suricata, 5‑tuple)
- CloudWatch Log Group receiving logs from the firewall
- E2E: Terraform configs under e2e/ executing a full apply
- Unit: Go test running `terraform plan` logic assertions

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Developer / CI Pipeline"
    direction TB
    Dev["Developer"]:::ci
    CI["GitHub Actions"]:::ci
    Dev -->|"init/plan/apply"| TFModule
    CI --> CI_Checkov
    CI --> CI_Docs
    CI --> CI_Notify
    CI --> CI_Release

    CI_Checkov["checkov.yaml"]:::ci
    CI_Docs["gen-docs.yaml"]:::ci
    CI_Notify["notify.yaml"]:::ci
    CI_Release["release.yaml"]:::ci
  end

  subgraph "Terraform Module: AWS Network Firewall"
    direction TB
    TFModule["Terraform Module"]:::terraform
    main["main.tf"]:::terraform
    vars["variables.tf"]:::terraform
    outs["outputs.tf"]:::terraform
    prov["providers.tf"]:::terraform
    data["data.tf"]:::terraform
    loc["locals.tf"]:::terraform

    TFModule --> main
    TFModule --> vars
    TFModule --> outs
    TFModule --> prov
    TFModule --> data
    TFModule --> loc
  end

  subgraph "Test Harness"
    direction TB
    subgraph "E2E Test Harness"
      direction TB
      E2E["E2E Terraform Tests"]:::test
      e2e_main["main.tf"]:::test
      e2e_prov["providers.tf"]:::test
      e2e_vars["variables.tf"]:::test
      e2e_outs["outputs.tf"]:::test
      rg_stateless["rule_group_stateless.tf"]:::test
      rg_domain["rule_group_domain_stateful.tf"]:::test
      rg_fivetuple["rule_group_fivetuple_stateful.tf"]:::test
      rg_suricata["rule_group_suricata_stateful.tf"]:::test
      alert["alert.rules"]:::test
      drop["drop.rules"]:::test

      E2E --> e2e_main
      E2E --> e2e_prov
      E2E --> e2e_vars
      E2E --> e2e_outs
      E2E --> rg_stateless
      E2E --> rg_domain
      E2E --> rg_fivetuple
      E2E --> rg_suricata
      E2E --> alert
      E2E --> drop
    end

    subgraph "Unit Test Harness"
      direction TB
      Unit["Unit Tests (Go)"]:::test
      ut_main["main.tf"]:::test
      ut_test["terraform_hello_world_example_test.go"]:::test

      Unit --> ut_main
      Unit --> ut_test
    end

    E2E -->|validate| TFModule
    Unit -->|plan validations| TFModule
  end

  subgraph "AWS Account"
    direction TB
    AWSAPI["AWS Provider API"]:::aws
    VPC["VPC & Subnets"]:::aws
    FW["Network Firewall"]:::aws
    Policy["Firewall Policy"]:::aws
    RG["Rule Groups"]:::aws
    CW["CloudWatch Log Group"]:::logs

    TFModule -->|"calls"| AWSAPI
    AWSAPI --> VPC
    AWSAPI --> FW
    FW --> Policy
    Policy --> RG
    FW --> CW
  end

  click main "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/main.tf"
  click vars "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/variables.tf"
  click outs "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/outputs.tf"
  click prov "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/providers.tf"
  click data "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/data.tf"
  click loc "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/locals.tf"

  click e2e_main "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/main.tf"
  click e2e_prov "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/providers.tf"
  click e2e_vars "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/variables.tf"
  click e2e_outs "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/outputs.tf"
  click rg_stateless "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/rule_group_stateless.tf"
  click rg_domain "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/rule_group_domain_stateful.tf"
  click rg_fivetuple "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/rule_group_fivetuple_stateful.tf"
  click rg_suricata "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/rule_group_suricata_stateful.tf"
  click alert "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/alert.rules"
  click drop "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/e2e/drop.rules"

  click ut_main "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/unittest/main.tf"
  click ut_test "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/unittest/terraform_hello_world_example_test.go"

  click CI_Checkov "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/.github/workflows/checkov.yaml"
  click CI_Docs "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/.github/workflows/gen-docs.yaml"
  click CI_Notify "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/.github/workflows/notify.yaml"
  click CI_Release "https://github.com/tnx-journey-to-cloud/terraform-aws-networkfirewall/blob/master/.github/workflows/release.yaml"

  classDef terraform fill:#cfe2f3,stroke:#0b5394,color:#073763
  classDef aws fill:#fce5cd,stroke:#b45f06,color:#783f04
  classDef ci fill:#d9ead3,stroke:#6aa84f,color:#38761d
  classDef test fill:#ead1dc,stroke:#a64d79,color:#741b47
  classDef logs fill:#d9ead3,stroke:#82b366,color:#38761d
```
