Skip to main content

The Foundation Stones

Beginner
OpenTofu

An incomplete OpenTofu configuration is blocking the Merchant's Quarter from going live. Fix the broken backend, wire up dynamic resource provisioning with for_each, and use the new enabled meta-argument to conditionally deploy the audit database.

Mission Objective

  • Provision storage vaults and ledger databases for each district dynamically
  • Deploy the audit database only when there is more than one district
  • Store state remotely in a GCS backend following best practices so the Guild can collaborate
  • Resolve all TODOs in the code and successfully run tofu apply

Key Learnings

  • Infrastructure as Code with OpenTofu
  • Remote state management with GCS backend
  • Dynamic resource provisioning with for_each
  • Conditional resources with the enabled meta-argument, new in OpenTofu
The Story

The Merchant's Quarter needs essential services, but the previous Guild engineer left the OpenTofu configuration incomplete and misconfigured. The state is stored locally, making collaboration impossible, and some services remain half-configured or missing.

Your mission: fix the issues, complete the setup, and establish proper infrastructure management for the Guild.

Ready to start?

Launch in a preconfigured devcontainer

Open in Codespaces (opens in new tab)

Free GitHub account required

Walkthrough
  1. 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.

  2. Wait ~2 minutes for the environment to initialize.

  3. Open the Ports tab and navigate to each service:

    • Port 30104: GCP API Mock. Explore the mock cloud resources created by your configuration (Cloud Storage and Cloud SQL).
  4. All OpenTofu files are in adventures/02-building-cloudhaven/beginner/. Run:

    grep -r "TODO" .
    

    Files to review: main.tf, state.tf, variables.tf, merchants.tf, audit.tf, outputs.tf.

  5. After fixing the TODOs, run:

    tofu apply
    

    If you changed the backend configuration, run tofu init -migrate-state first.

  6. Run 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:
    ./smoke-test.sh
    If it passes, it generates a Certificate of Completion you can paste into the discussion.
  • 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

Know someone who'd enjoy this?