Skip to content

test(network): add tftest.hcl coverage for network/aws and network/azure#34

Closed
dmchaledev wants to merge 2 commits into
mainfrom
claude/blissful-pascal-ssmosd
Closed

test(network): add tftest.hcl coverage for network/aws and network/azure#34
dmchaledev wants to merge 2 commits into
mainfrom
claude/blissful-pascal-ssmosd

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

Problem

The two network/ modules had zero terraform test coverage despite being the foundational landing zone consumed by every tier (single-vm, ha-hot-hot, unlimited-scale). A misconfigured subnet CIDR, a missing Postgres delegation block, or a broken NAT flag would only surface at customer terraform apply time — not in CI.

The six tier modules all have .tftest.hcl suites; this PR closes the remaining gap.

Changes

modules/network/aws/tests/basic.tftest.hcl

Mock-provider apply test with only the required name_prefix variable. Asserts all eight outputs are populated: vpc_id, vpc_cidr, public_subnet_ids (×2), private_subnet_ids (×2), db_subnet_ids (×2), internet_gateway_id, nat_gateway_ids (×2), nat_gateway_public_ips (×2).

modules/network/aws/tests/feature_flags.tftest.hcl

Plan-only checks for the three boolean/numeric flags:

Run Flag Asserts
nat_disabled_creates_no_gateways enable_nat_gateway = false 0 aws_nat_gateway, 0 aws_eip
flow_logs_disabled_creates_no_resources enable_flow_logs = false 0 aws_flow_log, 0 log group, 0 IAM role
flow_logs_enabled_creates_one_set enable_flow_logs = true (default) 1 flow log, 1 log group
three_az_span_creates_three_subnets_each az_count = 3 3 public, 3 private, 3 db subnets

All plan runs set enable_nat_gateway = false to avoid the private route-table for_each referencing mock NAT gateway IDs that are unknown at plan time (same constraint as the create_backup_bucket note in single-vm/aws).

modules/network/azure/tests/basic.tftest.hcl

Mock-provider apply test with the three required variables. Asserts all six outputs: vnet_id, vnet_name, workload_subnet_id, lb_subnet_id, db_delegated_subnet_id, private_dns_zone_id, and that private_dns_zone_name == "privatelink.postgres.database.azure.com". The Azure module has no conditional resources so a single run gives full coverage.

.github/workflows/ci.yml

Adds network/aws and network/azure to the terraform-test job matrix so both modules are tested on every PR.

Test plan

  • terraform init -backend=false in modules/network/aws succeeds
  • terraform test -no-color in modules/network/aws — all 5 runs pass
  • terraform init -backend=false in modules/network/azure succeeds
  • terraform test -no-color in modules/network/azure — 1 run passes
  • CI terraform-test matrix shows 8 jobs (was 6): new network/aws and network/azure jobs green

🤖 Generated with Claude Code

https://claude.ai/code/session_0162Qhh6oX8BeGu9kM3LGhRv


Generated by Claude Code

claude and others added 2 commits June 25, 2026 14:50
The network modules were the only modules without terraform test coverage.
They underpin every tier (single-vm, ha-hot-hot, unlimited-scale), so a
misconfigured subnet CIDR or missing Postgres delegation would cascade to
all consumers.

network/aws:
- basic.tftest.hcl  — apply with mocked AWS provider; checks all eight
  outputs (vpc_id, vpc_cidr, subnet lists, igw, NAT gateway IDs/IPs)
- feature_flags.tftest.hcl — plan-only checks that enable_nat_gateway,
  enable_flow_logs, and az_count conditionals create/omit the right
  resource counts; all plan runs set enable_nat_gateway=false to avoid
  evaluating the private-route-table for_each from unknown mock IDs

network/azure:
- basic.tftest.hcl  — apply with mocked azurerm provider; checks all
  six outputs (vnet_id, vnet_name, workload/lb/db subnet IDs, private
  DNS zone id/name)

ci.yml: add network/aws and network/azure to the terraform-test matrix

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0162Qhh6oX8BeGu9kM3LGhRv
dmchaledev pushed a commit that referenced this pull request Jun 26, 2026
…erage

Folds two open PRs that could not be merged from their own branches (their
mock-based tests broke once rebased and the branches are not pushable here);
re-implemented with the test gaps fixed.

#9 — VPC Flow Logs for single-vm/aws (closes #9):
  Adds opt-in VPC Flow Logs (enable_flow_logs, default true) sending ALL traffic
  to a CloudWatch log group, with a least-privilege flow-log IAM role. Closes the
  gap vs SECURITY-DEFAULTS.md. Forwarded through asm-aws-single / sat-aws-single
  with a flow_log_group_name output. The existing single-vm/aws basic test now
  mocks aws_cloudwatch_log_group with a valid ARN so aws_flow_log's
  log_destination passes provider-side ARN validation.

#34 — terraform test coverage for the network modules (closes #34):
  Adds .tftest.hcl suites for network/aws (basic apply + feature-flag plans) and
  network/azure (basic apply), and adds both to the terraform-test CI matrix —
  the only modules previously lacking native tests. The azure test mocks
  azurerm_network_security_group, and both network/aws tests mock
  aws_cloudwatch_log_group, with well-formed ARNs so the subnet-NSG association
  and flow-log destination validate under the mock provider.

Verified locally: terraform validate, tflint, terraform test (single-vm/aws 5/5,
network/aws 5/5, network/azure 1/1), checkov (1078 passed, 0 failed), trivy
(0 findings), and the wrapper drift check (0 warnings) all pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFfgnPaoyGhp52vQL2PVU3

Copy link
Copy Markdown
Contributor Author

Superseded by #41 (merged), which adds the network/aws + network/azure tftest.hcl coverage and wires both into the terraform-test CI matrix. Additions vs this PR (needed after the NSG associations landed in #35): the azure test mocks azurerm_network_security_group, and both network/aws tests mock aws_cloudwatch_log_group, with well-formed ARNs so the subnet→NSG association and flow-log destination validate under the mock provider. The coverage is now in main. Closing.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants