The Modular Metropolis
A senior engineer wrote the tests first and then left. The module code is buggy and the integration test is incomplete. Fix the implementation to match the test expectations, complete the end-to-end test, and use moved blocks to refactor without destroying state.
Mission Objective
- All tests of the districts module pass
- A completed integration test that applies infrastructure against the mock GCP API to verify end-to-end functionality
- Three districts deployed with correctly configured infrastructure (vaults and ledgers)
Key Learnings
- OpenTofu module testing with tofu test
- Test-Driven Development (TDD) workflow
- Input validation with custom rules
- Refactoring infrastructure safely with moved blocks
The Story
After fixing the Foundation Stones, CloudHaven is thriving. The city has grown to three districts, and the Guild decided to refactor the infrastructure into reusable modules.
A senior engineer started the work using Test-Driven Development, writing tests first then implementing. But they were called away before finishing, leaving behind working tests and buggy code that doesn't match them.
Your mission: fix the bugs, complete the integration test, and deploy the infrastructure.
Ready to start?
Launch in a preconfigured devcontainer
Free GitHub account required
Walkthrough
Open in GitHub Codespaces. The devcontainer is pre-configured and starts automatically. When you push from Codespaces, GitHub forks the repository to your account automatically.
Prefer working locally? Clone the repo and open it in any editor that supports the Dev Containers specification (VS Code, JetBrains IDEs, and others). The devcontainer config will be detected automatically.
Wait ~2 minutes for the environment to initialize.
Open the Ports tab and navigate to each service:
- Port 30104: GCP API Mock. Explore mock cloud resources to verify your module configuration.
All files are in
adventures/02-building-cloudhaven/intermediate/. The tests define the expected behaviour: your job is to fix the implementation to match what the tests expect. Don't modify existing tests unless a comment tells you to.adventures/02-building-cloudhaven/intermediate/ ├── main.tf # Provider and backend configuration ├── variables.tf # Input variables ├── districts.tf # Module calls for each district ├── outputs.tf # Infrastructure outputs ├── moved.tf # Resource migration blocks ├── modules/district/ # The district module (fix bugs here) │ ├── main.tf # Locals and tier configuration │ ├── variables.tf # Input validation │ ├── vault.tf # Storage bucket resource │ ├── ledger.tf # Cloud SQL resource │ ├── outputs.tf # Module outputs │ └── tests/ # Module tests (read these!) └── tests/ └── integration.tftest.hcl # Complete this testRun tests to see what fails:
make testOnce all tests pass, apply the infrastructure:
make test make applyRun the smoke test to verify your solution:
./smoke-test.sh
Complete Your Challenge
- When you push from Codespaces, GitHub forks the repository to your account automatically. If you are working locally, fork the repository on GitHub before pushing.
- Verify your solution:
If it passes, it generates a Certificate of Completion you can paste into the discussion../smoke-test.sh - Share your solutions in the challenge thread (opens in new tab) on community.offon.dev.
Completed the challenge? Share your achievement on LinkedIn (opens in new tab)
Toolbox
- tofu (opens in new tab) - OpenTofu CLI for infrastructure provisioning
- gcp-api-mock (opens in new tab) - mock GCP API running locally to simulate cloud resources without real cloud costs (Cloud Storage and Cloud SQL only)