8000 Add offline infrastructure test with OpenTofu mocks by k2on · Pull Request #2 · k2on/os · GitHub
[go: up one dir, main page]

Skip to content

Add offline infrastructure test with OpenTofu mocks - #2

Open
k2on wants to merge 1 commit into
cosmicfrom
infra-tftest
Open

k2on wants to merge 1 commit into
cosmicfrom
infra-tftest

Conversation

@k2on
@k2on k2on commented Sep 22, 2026
Copy link
Copy Markdown
Owner

Summary

This PR adds an offline infrastructure test (infra-tftest) that validates the Terraform/OpenTofu configuration without making any API calls. The test uses OpenTofu's mock providers to catch broken references, duplicate resources, and misconfigured providers early in the development cycle.

Key Changes

  • New offline test module (modules/ark/lib/tftest.nix): Implements a comprehensive infrastructure validation check that:

    • Evaluates the same Terraform configuration as the real deployment
    • Replaces all providers with OpenTofu mocks (no API calls or credentials needed)
    • Mocks the nixos-anywhere module with its expected outputs
    • Asserts that critical resources resolve correctly (VPS IP/ID for each host, DNS record content)
    • Runs both plan and apply phases to catch configuration errors
  • Refactored terranix configuration (modules/ark/lib/terranix.nix):

    • Extracted infrastructure modules into a shared ark.infra.modules option
    • Allows both the real Terraform build and the offline test to use identical module definitions
    • Simplified the perSystem configuration by centralizing module definitions
  • Provider mock support:

    • Added mock option to VPS providers (modules/ark/lib/vps.nix)
    • Added mock option to DNS providers (modules/ark/lib/dns.nix)
    • Implemented mocks for Hetzner (hcloud_server with documentation IPs) and Cloudflare (cloudflare_zone with fixed ID)
  • nixos-anywhere integration:

    • Added nixos-anywhere as a flake input (non-flake, pinned)
    • Updated the nixos-anywhere module source to use a relative path (./nixos-anywhere/all-in-one)
    • Modified terranix wrapper to symlink nixos-anywhere's terraform modules into the workdir
  • Build configuration: Updated .gitignore to exclude the symlinked nixos-anywhere directory

Implementation Details

The test validates the provider-agnostic contract that every host relies on:

  • ark.vps.ip and ark.vps.id resolve to real resources for each host with a provider
  • Every DNS record has content

The mocks are provider-specific and defined alongside their real configurations, making them easy to maintain as the infrastructure evolves. The test is cheap enough to run on every push and complements the more expensive VM integration tests.

https://claude.ai/code/session_015WpX4JSgNq9jx8WBNNrpFt

Add checks.infra-tftest: `tofu test` over the same terranix output
`ark plan` uses, with every provider mocked (mock_provider), the
nixos-anywhere module replaced by its outputs, and a plan plus mocked
apply that must succeed. Asserts that ark.vps.ip / ark.vps.id resolve to
a resource for every host with a provider and that every DNS record has
content. No API calls, no tokens, runs under `nix flake check`.

To make the config loadable offline, nixos-anywhere becomes a flake
input (flake = false) and the deploy module is sourced from a
./nixos-anywhere symlink the terranix wrapper creates in the workdir;
its all-in-one module references siblings with ../, which OpenTofu
refuses from an absolute store path. This also pins the module through
flake.lock instead of tracking GitHub HEAD.

The terranix module list is shared through ark.infra.modules so the test
and the real configuration cannot drift. Providers gain a `mock` option
for their tofu test mocks (Hetzner servers get documentation addresses,
Cloudflare zones a fixed id).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015WpX4JSgNq9jx8WBNNrpFt
k2on pushed a commit that referenced this pull request Oct 18, 2026
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

0